forked from pvangoor/eqvio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
300 lines (261 loc) · 9.56 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
cmake_minimum_required(VERSION 3.12)
project(eqvio VERSION 1.1)
set(CMAKE_CXX_STANDARD 20)
include(CheckCXXCompilerFlag)
# Options and settings
option( EQVIO_BUILD_TESTS "Build Tests" ON)
option( EQVIO_BUILD_VISUALISATION "Build Visualisation Tool" ON)
option( EQVIO_BUILD_ROSBAG "Build EqVIO with rosbag reading enabled" OFF)
option( EQVIO_SUPPORT_CONCEPTS "Build EqVIO using c++20 concepts" ON)
option( EXTRA_WARNINGS "Enable extra warnings from gcc" ON)
if(EQVIO_SUPPORT_CONCEPTS OR (${CMAKE_CXX_STANDARD} EQUAL 20))
message("Adding the flag -fconcepts")
add_compile_options("-fconcepts")
endif()
add_compile_definitions(EQVIO_BUILD_VISUALISATION=$<BOOL:${EQVIO_BUILD_VISUALISATION}>)
add_compile_definitions(EQVIO_BUILD_ROSBAG=$<BOOL:${EQVIO_BUILD_ROSBAG}>)
add_compile_definitions(EQVIO_SUPPORT_CONCEPTS=$<BOOL:${EQVIO_SUPPORT_CONCEPTS}>)
option( EQVIO_USE_MARCH_NATIVE "Use the flag -march=native" OFF)
if (EQVIO_USE_MARCH_NATIVE AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
if(COMPILER_SUPPORTS_MARCH_NATIVE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
else()
message("-march=native was requested but is not supported.")
endif()
endif()
option( EQVIO_USE_LTO "Use the flag -flto" OFF)
if (EQVIO_USE_LTO AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-flto" COMPILER_SUPPORTS_LTO)
if(COMPILER_SUPPORTS_LTO)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
else()
message("-flto was requested but is not supported.")
endif()
endif()
option( EQVIO_USE_THREAD_SANTIZER "Use the gcc thread sanitizer option" OFF)
if (EQVIO_USE_THREAD_SANTIZER)
CHECK_CXX_COMPILER_FLAG("-fsanitize=thread" COMPILER_SUPPORTS_THREAD_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
if(NOT COMPILER_SUPPORTS_THREAD_SANITIZER)
message("-fsanitize=thread may not be supported. Trying anyway.")
endif()
endif()
option( EQVIO_USE_UB_SANTIZER "Use the gcc undefined behaviour sanitizer option" OFF)
if (EQVIO_USE_UB_SANTIZER)
CHECK_CXX_COMPILER_FLAG("-fsanitize=undefined" COMPILER_SUPPORTS_UB_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
if(NOT COMPILER_SUPPORTS_UB_SANITIZER)
message("-fsanitize=undefined may not be supported. Trying anyway.")
endif()
endif()
option( EQVIO_USE_MEM_SANTIZER "Use the gcc address sanitizer option" OFF)
if (EQVIO_USE_MEM_SANTIZER)
CHECK_CXX_COMPILER_FLAG("-fsanitize=address" COMPILER_SUPPORTS_MEM_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
if(NOT COMPILER_SUPPORTS_MEM_SANITIZER)
message("-fsanitize=address may not be supported. Trying anyway.")
endif()
endif()
# Import external dependencies
find_package(Eigen3 3 REQUIRED)
find_package(OpenCV REQUIRED)
find_package(yaml-cpp REQUIRED)
# Add GIFT
find_package(GIFT QUIET)
if (${GIFT_FOUND})
message("GIFT is being used as an installed package.")
set(GIFT_INCLUDE_DIRS "GIFT::GIFT")
else()
message("GIFT is being used as a git submodule.")
execute_process(COMMAND git submodule update --init --recursive --remote
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/external/GIFT
RESULT_VARIABLE GIFT_SUBMOD_RESULT)
if (${GIFT_SUBMOD_RESULT})
message(FATAL_ERROR "GIFT was not found as a package and could not be included as a submodule.")
endif()
add_subdirectory(external/GIFT)
set(GIFT_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/external/GIFT/GIFT/include")
endif()
# Add argparse
find_package(argparse QUIET)
if (${argparse_FOUND})
message("argparse is being used as an installed package.")
set(argparse_INCLUDE_DIRS "argparse::argparse")
else()
message("argparse is being used as a git submodule.")
execute_process(COMMAND git submodule update --init --recursive --remote
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/external/argparse
RESULT_VARIABLE argparse_SUBMOD_RESULT)
if (${argparse_SUBMOD_RESULT})
message(FATAL_ERROR "argparse was not found as a package and could not be included as a submodule.")
endif()
set(argparse_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/external/argparse/include")
endif()
# Add LiePP
message("LiePP is being used as a git submodule.")
execute_process(COMMAND git submodule update --init --recursive --remote
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/external/LiePP
RESULT_VARIABLE LiePP_SUBMOD_RESULT)
if (${argparse_SUBMOD_RESULT})
message(FATAL_ERROR "LiePP could not be included as a submodule.")
endif()
set(LiePP_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/external/LiePP/include")
# Add libs
add_subdirectory(libs)
# Add the include files
set(EQVIO_HEADER_FILES
include/eqvio/common/safeConfig.h
include/eqvio/common/LieYaml.h
include/eqvio/common/aofstream.h
include/eqvio/mathematical/EqFMatrices.h
include/eqvio/mathematical/Geometry.h
include/eqvio/mathematical/IMUVelocity.h
include/eqvio/mathematical/VIO_eqf.h
include/eqvio/mathematical/VIOGroup.h
include/eqvio/mathematical/VIOState.h
include/eqvio/mathematical/VisionMeasurement.h
include/eqvio/csv/CSVLine.h
include/eqvio/csv/CSVReader.h
include/eqvio/csv/CSVFile.h
include/eqvio/dataserver/dataservers.h
include/eqvio/dataserver/DatasetReaderBase.h
include/eqvio/dataserver/ASLDatasetReader.h
include/eqvio/dataserver/APDatasetReader.h
include/eqvio/dataserver/UZHFPVDatasetReader.h
include/eqvio/dataserver/DataServerBase.h
include/eqvio/dataserver/SimpleDataServer.h
include/eqvio/dataserver/ThreadedDataServer.h
include/eqvio/dataserver/SimulationDataServer.h
include/eqvio/VIOFilter.h
include/eqvio/VIOFilterSettings.h
include/eqvio/VIOSimulator.h
include/eqvio/LoopTimer.h
include/eqvio/VIOWriter.h
)
set(EQVIO_SOURCE_FILES
src/mathematical/VIOState.cpp
src/mathematical/VIOGroup.cpp
src/mathematical/VIO_eqf.cpp
src/mathematical/VisionMeasurement.cpp
src/mathematical/IMUVelocity.cpp
src/mathematical/EqFMatrices.cpp
src/mathematical/Geometry.cpp
src/mathematical/coordinateSuite/euclid.cpp
src/mathematical/coordinateSuite/invdepth.cpp
src/mathematical/coordinateSuite/normal.cpp
src/dataserver/ASLDatasetReader.cpp
src/dataserver/APDatasetReader.cpp
src/dataserver/UZHFPVDatasetReader.cpp
src/dataserver/DataServerBase.cpp
src/dataserver/SimpleDataServer.cpp
src/dataserver/ThreadedDataServer.cpp
src/dataserver/SimulationDataServer.cpp
src/VIOFilter.cpp
src/VIOSimulator.cpp
src/LoopTimer.cpp
src/VIOWriter.cpp
)
# Try to add rosbag
if (EQVIO_BUILD_ROSBAG)
find_package(rosbag REQUIRED)
find_package(cv_bridge REQUIRED)
set(CMAKE_CXX_STANDARD 17)
list(APPEND EQVIO_HEADER_FILES
include/eqvio/dataserver/RosbagDatasetReader.h
include/eqvio/dataserver/HiltiDatasetReader.h
)
list(APPEND EQVIO_SOURCE_FILES
src/dataserver/RosbagDatasetReader.cpp
src/dataserver/HiltiDatasetReader.cpp
)
message("Building with rosbag support.")
endif()
# Add visualisation if requested
if (EQVIO_BUILD_VISUALISATION)
list(APPEND EQVIO_HEADER_FILES
include/eqvio/VIOVisualiser.h
)
list(APPEND EQVIO_SOURCE_FILES
src/VIOVisualiser.cpp
)
message("Building with visualisation support.")
endif()
# Add the EqVIO library
add_library(eqvio_lib
${EQVIO_SOURCE_FILES}
${EQVIO_HEADER_FILES}
)
target_include_directories(eqvio_lib
PUBLIC include
PUBLIC ${EQVIO_MODULE_INCLUDE_DIRS}
PUBLIC ${OPENCV_INCLUDE_DIRS}
PUBLIC ${GIFT_INCLUDE_DIRS}
PUBLIC ${LiePP_INCLUDE_DIRS}
PUBLIC ${EIGEN_INCLUDE_DIRS}
PUBLIC ${rosbag_INCLUDE_DIRS}
PUBLIC ${cv_bridge_INCLUDE_DIRS}
)
target_link_libraries(eqvio_lib
${EQVIO_MODULE_LIBS}
${OpenCV_LIBS}
GIFT
${rosbag_LIBRARIES}
${cv_bridge_LIBRARIES}
)
if (${CMAKE_COMPILER_IS_GNUCC} AND ${CMAKE_CXX_COMPILER_VERSION} LESS 9.0)
message("GCC version is less than 9. Manually linking std::filesystem.")
target_link_libraries(eqvio_lib stdc++fs)
endif()
if (${EXTRA_WARNINGS})
message("Extra warnings are enabled.")
target_compile_options(eqvio_lib PRIVATE -Wall -Wextra -Wpedantic)
endif()
# Add the tests
if(EQVIO_BUILD_TESTS)
enable_testing()
message("Building the tests.")
add_subdirectory(test)
endif()
# Add the main executable
add_executable(eqvio_opt src/main_opt.cpp)
add_executable(eqvio_sim src/main_sim.cpp)
set(EXECUTABLES_LIST
eqvio_opt
eqvio_sim
)
foreach(EXECUTABLE_NAME ${EXECUTABLES_LIST})
target_include_directories(${EXECUTABLE_NAME}
PRIVATE include
PRIVATE ${EIGEN_INCLUDE_DIRS}
PRIVATE ${OpenCV_INCLUDE_DIRS}
PRIVATE ${YAML_CPP_INCLUDE_DIR}
PRIVATE ${LiePP_INCLUDE_DIRS}
PRIVATE ${GIFT_INCLUDE_DIRS}
PRIVATE ${argparse_INCLUDE_DIRS}
)
target_link_libraries(${EXECUTABLE_NAME}
eqvio_lib
${EQVIO_MODULE_LIBS}
${OpenCV_LIBS}
yaml-cpp
GIFT
)
endforeach()
# Add documentation
option( EQVIO_BUILD_DOCS "Use doxygen to build documentation" OFF)
if (EQVIO_BUILD_DOCS)
find_package(Doxygen REQUIRED)
message("Documentation will be built using doxygen.")
set(DOXYGEN_USE_MATHJAX true)
set(DOXYGEN_MATHJAX_EXTENSIONS TeX/AMSmath TeX/AMSsymbols)
doxygen_add_docs(eqvio_docs
${EQVIO_HEADER_FILES}
${EQVIO_SOURCE_FILES}
README.md
docs/main.md
ALL
)
endif()