add_library(pathplan
  cvt.c
  inpoly.c
  route.c
  shortest.c
  shortestpth.c
  solvers.c
  triang.c
  util.c
  visibility.c
)

target_compile_definitions(pathplan PRIVATE PATHPLAN_EXPORTS)

target_include_directories(pathplan
  PUBLIC
    $<INSTALL_INTERFACE:include>
    $<INSTALL_INTERFACE:include/graphviz>
  PRIVATE
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)

target_link_libraries(pathplan PRIVATE util)

# Installation location of library files
install(
  TARGETS pathplan
  EXPORT graphvizTargets
  RUNTIME DESTINATION ${BINARY_INSTALL_DIR}
  LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR}
  ARCHIVE DESTINATION ${LIBRARY_INSTALL_DIR}
)

# Specify headers to be installed
install(
  FILES pathgeom.h pathplan.h
  DESTINATION ${HEADER_INSTALL_DIR}
)

# Specify man pages to be installed
if(GZIP)
  add_custom_target(man-pathplan ALL DEPENDS pathplan.3.gz
                    COMMENT "pathplan man page")
  add_custom_command(
    OUTPUT pathplan.3.gz
    COMMAND ${GZIP} -9 --no-name --to-stdout pathplan.3
      >"${CMAKE_CURRENT_BINARY_DIR}/pathplan.3.gz"
    MAIN_DEPENDENCY pathplan.3
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    COMMENT "compress pathplan man page")
  install(
    FILES ${CMAKE_CURRENT_BINARY_DIR}/pathplan.3.gz
    DESTINATION ${MAN_INSTALL_DIR}/man3)
else()
  install(
    FILES pathplan.3
    DESTINATION ${MAN_INSTALL_DIR}/man3
  )
endif()

# Specify library version and soversion
set_target_properties(pathplan PROPERTIES
  VERSION 4.0.7
  SOVERSION 4
)
