cmake_minimum_required(VERSION 3.10) project(voronoi_route VERSION 0.1.0 LANGUAGES CXX) # Standalone CMake, no catkin: the library runs inside RBApp (a plain CMake project), called once # per map right after the scanned map is copied into data/maps//. RBApp pulls it in either by # `find_package(voronoi_route)` after `cmake --install`, or by compiling src/*.cpp into robot_app # the way it does robot_time; the exported target is voronoi_route::voronoi_route. # # cmake -S . -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build -j # ./build/voronoi_route_compile --map set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() option(VORONOI_ROUTE_BUILD_TOOLS "Build voronoi_route_compile (needs OpenCV, yaml-cpp, nlohmann_json)" ON) option(VORONOI_ROUTE_BUILD_TESTS "Build GTest unit tests" ON) # ---- library ------------------------------------------------------------------------------------ add_library(voronoi_route src/dynamic_voronoi.cpp src/voronoi_field.cpp src/voronoi_graph.cpp src/attachment.cpp src/corridor_mask.cpp src/voronoi_route.cpp src/map_convert.cpp src/params.cpp) add_library(voronoi_route::voronoi_route ALIAS voronoi_route) target_include_directories(voronoi_route PUBLIC $ $) target_compile_features(voronoi_route PUBLIC cxx_std_17) target_compile_options(voronoi_route PRIVATE -Wall -Wextra) set_target_properties(voronoi_route PROPERTIES POSITION_INDEPENDENT_CODE ON) # ---- bundle I/O (json + pgm), separate so the core stays free of nlohmann --------------------- find_path(NLOHMANN_JSON_INCLUDE_DIR nlohmann/json.hpp HINTS /usr/local/include /usr/include) find_package(yaml-cpp QUIET) if(NLOHMANN_JSON_INCLUDE_DIR AND yaml-cpp_FOUND) add_library(voronoi_route_io src/bundle_io.cpp src/params_io.cpp) add_library(voronoi_route::voronoi_route_io ALIAS voronoi_route_io) target_include_directories(voronoi_route_io PUBLIC $ $ PRIVATE ${NLOHMANN_JSON_INCLUDE_DIR}) target_link_libraries(voronoi_route_io PUBLIC voronoi_route yaml-cpp) target_compile_options(voronoi_route_io PRIVATE -Wall -Wextra) set_target_properties(voronoi_route_io PROPERTIES POSITION_INDEPENDENT_CODE ON) else() message(WARNING "nlohmann/json.hpp or yaml-cpp not found — voronoi_route_io and the compile tool are skipped") endif() # ---- tool --------------------------------------------------------------------------------------- if(VORONOI_ROUTE_BUILD_TOOLS AND TARGET voronoi_route_io) find_package(OpenCV REQUIRED COMPONENTS core imgcodecs imgproc) add_executable(voronoi_route_compile tools/voronoi_route_compile.cpp) target_link_libraries(voronoi_route_compile PRIVATE voronoi_route_io ${OpenCV_LIBS}) target_compile_options(voronoi_route_compile PRIVATE -Wall -Wextra) endif() # ---- tests -------------------------------------------------------------------------------------- if(VORONOI_ROUTE_BUILD_TESTS) find_package(GTest QUIET) if(GTest_FOUND) enable_testing() set(VORONOI_ROUTE_TEST_SOURCES test/voronoi_route_test.cpp) if(TARGET voronoi_route_io) list(APPEND VORONOI_ROUTE_TEST_SOURCES test/params_io_test.cpp) endif() add_executable(voronoi_route_test ${VORONOI_ROUTE_TEST_SOURCES}) target_link_libraries(voronoi_route_test PRIVATE voronoi_route GTest::GTest GTest::Main pthread) if(TARGET voronoi_route_io) target_link_libraries(voronoi_route_test PRIVATE voronoi_route_io) target_compile_definitions(voronoi_route_test PRIVATE VORONOI_ROUTE_PACKAGED_PARAMS="${CMAKE_CURRENT_SOURCE_DIR}/config/voronoi_route_params.yaml") endif() add_test(NAME voronoi_route_test COMMAND voronoi_route_test) else() message(STATUS "GTest not found — voronoi_route_test skipped") endif() endif() # ---- install ------------------------------------------------------------------------------------ include(GNUInstallDirs) install(TARGETS voronoi_route EXPORT voronoi_route-targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) if(TARGET voronoi_route_io) install(TARGETS voronoi_route_io EXPORT voronoi_route-targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() install(DIRECTORY include/voronoi_route DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install(DIRECTORY config/ DESTINATION share/voronoi_route/config) install(EXPORT voronoi_route-targets NAMESPACE voronoi_route:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/voronoi_route) # Minimal package config so a host (RBApp) can `find_package(voronoi_route)`; voronoi_route_io # links yaml-cpp publicly, so the dependency has to be resolved on the consumer side too. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/voronoi_route-config.cmake" "include(CMakeFindDependencyMacro)\n" "find_dependency(yaml-cpp QUIET)\n" "include(\"\${CMAKE_CURRENT_LIST_DIR}/voronoi_route-targets.cmake\")\n") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/voronoi_route-config.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/voronoi_route) if(TARGET voronoi_route_compile) install(TARGETS voronoi_route_compile RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif()