-
Notifications
You must be signed in to change notification settings - Fork 42
/
CMakeLists.txt
244 lines (199 loc) · 6.21 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
cmake_minimum_required(VERSION 3.5.1)
cmake_policy(SET CMP0048 NEW)
project(kalmanif VERSION 0.0.1 LANGUAGES CXX)
# Check that the compiler has c++17 support, crash otherwise.
if(NOT MSVC)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
if(COMPILER_SUPPORTS_CXX17)
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has C++17 support.")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} "
"has no C++17 support. Please use a different C++ compiler.")
endif()
endif()
# Options. Turn on with,
# cmake -DBUILD_TESTING=ON -DBUILD_EXAMPLES=ON
# catkin build kalmanif --cmake-args -DBUILD_TESTING=ON -DBUILD_EXAMPLES=ON
# colcon build --packages-up-to kalmanif --cmake-args '-DBUILD_TESTING=ON ' '-DBUILD_EXAMPLES=ON'
option(BUILD_EXAMPLES "Build all examples." OFF)
option(PLOT_EXAMPLES "Plot the examples outputs." OFF)
option(BUILD_TESTING "Build all tests." OFF)
# SE2 demo/example produce unstable covariance matrix.
# Until it is fixed, force disable kalmanif asserts.
add_compile_definitions(KALMANIF_NO_DEBUG)
##################
## Dependencies ##
##################
find_package(manif REQUIRED)
###########
## Build ##
###########
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>"
)
# Add manif interface dependency, depending on available cmake info
if(TARGET MANIF::manif)
target_link_libraries(${PROJECT_NAME} INTERFACE MANIF::manif)
set(manif_DEPENDENCY "find_dependency(manif ${manif_VERSION})")
else(TARGET MANIF::manif)
target_include_directories(
${PROJECT_NAME} SYSTEM INTERFACE ${manif_INCLUDE_DIRS}
)
endif(TARGET MANIF::manif)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_compile_options(${PROJECT_NAME} INTERFACE -ftemplate-depth=512)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(${PROJECT_NAME} INTERFACE /bigobj)
endif()
#############
## Install ##
#############
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
set(config_install_dir "share/${PROJECT_NAME}/cmake")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
# Targets:
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
INCLUDES DESTINATION include
)
install(
EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${PROJECT_NAME}::
DESTINATION "${config_install_dir}"
)
export(
TARGETS ${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::
FILE ${PROJECT_NAME}Targets.cmake
)
export(PACKAGE ${PROJECT_NAME})
## Configuration
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${generated_dir}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${config_install_dir}"
)
# Configure '<PROJECT-NAME>ConfigVersion.cmake'
write_basic_package_version_file(
"${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
# Config
install(
FILES "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake"
"${generated_dir}/${PROJECT_NAME}Config.cmake"
DESTINATION "${config_install_dir}"
)
# Headers
install(
DIRECTORY "${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}"
DESTINATION include
)
##############
## Examples ##
##############
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif(BUILD_EXAMPLES)
#############
## Testing ##
#############
# ------------------------------------------------------------------------------
# Unit Tests
# ------------------------------------------------------------------------------
if(BUILD_TESTING)
enable_testing()
add_subdirectory(test)
endif(BUILD_TESTING)
# ------------------------------------------------------------------------------
# Coverage
# ------------------------------------------------------------------------------
if(ENABLE_COVERAGE)
add_definitions(-DKALMANIF_COVERAGE_ENABLED)
set(
CMAKE_CXX_FLAGS
"\
${CMAKE_CXX_FLAGS} \
-g \
-O0 \
-fprofile-arcs \
-ftest-coverage \
--coverage \
"
)
endif()
# ------------------------------------------------------------------------------
# CppCheck
# ------------------------------------------------------------------------------
if(ENABLE_CPPCHECK)
# Find CppCheck executable
find_program(CPPCHECK "cppcheck")
if(CPPCHECK)
# Set export commands on
# set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
list(APPEND CPPCHECK_ARGS
--enable=all
--std=c++17
# --verbose
--quiet
# --check-config
--xml-version=2
--language=c++
# Comment the line below to run cppcheck-html
--error-exitcode=1
--inline-suppr
--suppress=*:*googletest-*
--suppress=missingIncludeSystem
# --suppress=missingInclude
--suppress=unmatchedSuppression:*
--check-config
# Uncomment the line below to run cppcheck-html
# --output-file=${CMAKE_BINARY_DIR}/cppcheck_results.xml
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/external
${CMAKE_SOURCE_DIR}/examples
${CMAKE_SOURCE_DIR}/test
)
add_custom_target(run-cppcheck
COMMAND ${CPPCHECK} ${CPPCHECK_ARGS}
COMMENT "Generate cppcheck report for the project"
)
find_program(CPPCHECK_HTML "cppcheck-htmlreport")
if(CPPCHECK_HTML)
add_custom_target(cppcheck-html
COMMAND ${CPPCHECK_HTML}
--title=${CMAKE_PROJECT_NAME}
--file=${CMAKE_BINARY_DIR}/cppcheck_results.xml
--report-dir=${CMAKE_BINARY_DIR}/cppcheck_results
--source-dir=${CMAKE_SOURCE_DIR}
COMMENT "Convert cppcheck report to HTML output"
)
ADD_DEPENDENCIES(cppcheck-html run-cppcheck)
endif()
endif()
endif()
# ------------------------------------------------------------------------------
# Valgrind
# ------------------------------------------------------------------------------
if(ENABLE_VALGRIND)
# ctest -T memcheck
include(CTest)
set(
MEMORYCHECK_COMMAND_OPTIONS
"\
${MEMORYCHECK_COMMAND_OPTIONS} \
--leak-check=full \
--track-origins=yes \
--trace-children=yes \
--show-leak-kinds=all \
--verbose \
--error-exitcode=1 \
"
)
endif()