cmake_minimum_required(VERSION 3.12)

project(mg_obstacles)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "CLANG")
    add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)

set(PACKAGE_DEPS
    rclcpp
    ament_index_cpp
    mg_msgs
    geometry_msgs
    std_msgs
    tf2
    tf2_ros
    tf2_geometry_msgs
    jsoncpp
)

foreach(PACKAGE ${PACKAGE_DEPS})
    find_package(${PACKAGE} REQUIRED)
endforeach(PACKAGE ${PACKAGE_DEPS})

include(FindPkgConfig)
pkg_check_modules(JSONCPP jsoncpp)
# pkg_search_module(LIBGLM REQUIRED glm)

set(SOURCES
    src/mg_obstacles.cpp
    src/sdf.cpp
    src/static_obstacle.cpp
    src/permanent_obstacle.cpp
)

add_library(
    mg_obstacles
    SHARED
    ${SOURCES}
)

target_include_directories(
    mg_obstacles
    PRIVATE
    ${LIBGLM_INCLUDE_DIRS}
    ${JSONCPP_INCLUDE_DIRS}
)

target_link_libraries(mg_obstacles ${JSONCPP_LINK_LIBRARIES})

target_include_directories(
    mg_obstacles
    PUBLIC 
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
    "$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
)

ament_target_dependencies(
    mg_obstacles
    ${PACKAGE_DEPS}
)


install(
    TARGETS mg_obstacles
    EXPORT export_${PROJECT_NAME}
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
    RUNTIME DESTINATION bin
)

install(DIRECTORY include/ DESTINATION include/${PROJECT_NAME})
install(DIRECTORY obstacles DESTINATION share/${PROJECT_NAME}/)

ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
ament_export_include_directories(include)

target_compile_features(mg_obstacles PUBLIC c_std_99 cxx_std_17)

ament_package()

