-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
145 lines (112 loc) · 4.44 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
cmake_minimum_required(VERSION 3.15)
project(cbr_ros VERSION 0.1.0)
# uninstall target has to be before rclcpp otherwise ament exports its own uninstall target
add_custom_target(
uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake
)
# ---------------------------------------------------------------------------------------
# GLOBAL FLAGS
# ---------------------------------------------------------------------------------------
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# ---------------------------------------------------------------------------------------
# OPTIONS
# ---------------------------------------------------------------------------------------
include(CTest)
# Release type
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
# ---------------------------------------------------------------------------------------
# DEPENDENCIES
# ---------------------------------------------------------------------------------------
find_package(rclcpp REQUIRED)
find_package(Eigen3 3.3 REQUIRED)
find_package(cbr_utils REQUIRED)
# ---------------------------------------------------------------------------------------
# TARGETS
# ---------------------------------------------------------------------------------------
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME}
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(${PROJECT_NAME}
INTERFACE
rclcpp::rclcpp
Eigen3::Eigen
cbr_utils::cbr_utils
)
# ---------------------------------------------------------------------------------------
# INSTALLATION
# ---------------------------------------------------------------------------------------
include(GNUInstallDirs)
# Header files
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# Targets
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}_targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
# ---------------------------------------------------------------------------------------
# CMAKE CONFIGURATION
# ---------------------------------------------------------------------------------------
set(export_dest_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
# Generate TARGETS files
install(
EXPORT ${PROJECT_NAME}_targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${export_dest_dir}
)
# Generate CONFIG file
include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/ConfigTemplate.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${export_dest_dir}
)
# Generate VERSION file
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Version.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY SameMajorVersion
)
# Install CONFIG and VERSION files
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Version.cmake
DESTINATION ${export_dest_dir}
)
# Generate uninstall file
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake
IMMEDIATE @ONLY
)
# ---------------------------------------------------------------------------------------
# TESTING
# ---------------------------------------------------------------------------------------
if(BUILD_TESTING)
include(GoogleTest)
find_package(GTest REQUIRED)
add_compile_options(-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Werror)
# Utils
add_executable(${PROJECT_NAME}_msg_utils test/test_msg_utils.cpp)
target_link_libraries(${PROJECT_NAME}_msg_utils PRIVATE ${PROJECT_NAME} GTest::Main)
gtest_discover_tests(${PROJECT_NAME}_msg_utils)
# Parameters
add_executable(${PROJECT_NAME}_test_parameters test/test_parameters.cpp)
target_link_libraries(${PROJECT_NAME}_test_parameters PRIVATE ${PROJECT_NAME} GTest::Main)
gtest_discover_tests(${PROJECT_NAME}_test_parameters)
endif()