115 lines
2.9 KiB
CMake
Executable File
115 lines
2.9 KiB
CMake
Executable File
cmake_minimum_required(VERSION 3.10)
|
|
|
|
# ========================================================
|
|
# Dual-mode CMakeLists.txt: Supports both Catkin and Standalone CMake
|
|
# ========================================================
|
|
|
|
# Detect if building with Catkin
|
|
if(DEFINED CATKIN_DEVEL_PREFIX OR DEFINED CATKIN_TOPLEVEL)
|
|
set(BUILDING_WITH_CATKIN TRUE)
|
|
message(STATUS "Building robot_voxel_grid with Catkin")
|
|
else()
|
|
set(BUILDING_WITH_CATKIN FALSE)
|
|
message(STATUS "Building robot_voxel_grid with Standalone CMake")
|
|
endif()
|
|
|
|
project(robot_voxel_grid)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
include(CTest)
|
|
|
|
# ========================================================
|
|
# Find dependencies
|
|
# ========================================================
|
|
|
|
if(BUILDING_WITH_CATKIN)
|
|
find_package(catkin REQUIRED)
|
|
endif()
|
|
|
|
# # Check for sys/time.h
|
|
# check_include_file(sys/time.h HAVE_SYS_TIME_H)
|
|
# if (HAVE_SYS_TIME_H)
|
|
# add_definitions(-DHAVE_SYS_TIME_H)
|
|
# endif (HAVE_SYS_TIME_H)
|
|
|
|
# ========================================================
|
|
# Catkin specific configuration
|
|
# ========================================================
|
|
|
|
if(BUILDING_WITH_CATKIN)
|
|
catkin_package(
|
|
INCLUDE_DIRS include
|
|
LIBRARIES robot_voxel_grid
|
|
)
|
|
endif()
|
|
|
|
# Include directories
|
|
include_directories(
|
|
include
|
|
${GTEST_INCLUDE_DIRS}
|
|
)
|
|
|
|
if(BUILDING_WITH_CATKIN)
|
|
include_directories(${catkin_INCLUDE_DIRS})
|
|
endif()
|
|
|
|
# Library
|
|
add_library(robot_voxel_grid SHARED src/voxel_grid.cpp)
|
|
|
|
target_include_directories(robot_voxel_grid
|
|
PUBLIC
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
|
|
)
|
|
|
|
if(BUILDING_WITH_CATKIN)
|
|
add_dependencies(robot_voxel_grid ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
|
|
endif()
|
|
|
|
# ========================================================
|
|
# Installation
|
|
# ========================================================
|
|
|
|
# Install targets
|
|
install(TARGETS robot_voxel_grid
|
|
EXPORT robot_voxel_gridTargets
|
|
ARCHIVE DESTINATION lib
|
|
LIBRARY DESTINATION lib
|
|
RUNTIME DESTINATION bin
|
|
INCLUDES DESTINATION include
|
|
)
|
|
|
|
if(NOT BUILDING_WITH_CATKIN)
|
|
# Install headers (standalone)
|
|
install(DIRECTORY include/${PROJECT_NAME}/
|
|
DESTINATION include/${PROJECT_NAME}
|
|
)
|
|
endif()
|
|
|
|
install(EXPORT robot_voxel_gridTargets
|
|
DESTINATION lib/cmake/robot_voxel_grid)
|
|
|
|
|
|
# Testing
|
|
enable_testing()
|
|
|
|
# Find Google Test
|
|
find_package(GTest QUIET)
|
|
if(GTest_FOUND OR GTEST_FOUND)
|
|
# Find pthread (required for GTest)
|
|
find_package(Threads REQUIRED)
|
|
|
|
include_directories(${GTEST_INCLUDE_DIRS})
|
|
add_executable(robot_voxel_grid_tests test/voxel_grid_tests.cpp)
|
|
target_link_libraries(robot_voxel_grid_tests
|
|
robot_voxel_grid
|
|
${GTEST_LIBRARIES}
|
|
Threads::Threads
|
|
)
|
|
add_test(NAME robot_voxel_grid_tests COMMAND robot_voxel_grid_tests)
|
|
else()
|
|
message(STATUS "Google Test not found. Tests will not be built.")
|
|
endif()
|