-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
198 lines (181 loc) · 6.95 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
cmake_minimum_required(VERSION 3.13)
project(
msceqf
VERSION 1.0
DESCRIPTION "Multi State Constraint Equivariant Filter for visual inertial navigation"
LANGUAGES CXX
)
# Set build type, Release by default
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
## Options
option(MSCEQF_TESTS "Build MSCEqF tests" OFF)
option(ROS_BUILD "Build MSCEqF with ROS" OFF)
option(ENABLE_ADDRESS_SANITIZER "Enable address sanitizer" OFF)
option(ENABLE_UNDEFINED_SANITIZER "Enable undefined behavior sanitizer" OFF)
option(ENABLE_THREAD_SANITIZER "Enable thread sanitizer" OFF)
## Include and set up external libraries
include(FetchContent)
# Googletest
if(MSCEQF_TESTS)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
list(APPEND external googletest)
list(APPEND include_dirs ${googletest_INCLUDE_DIR})
list(APPEND libs ${googletest_LIBRARIES})
endif()
# Lie++ (and Eigen)
FetchContent_Declare(
LiePlusPlus
GIT_REPOSITORY https://github.com/aau-cns/Lie-plusplus
GIT_TAG main
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
set(LIEPLUSPLUS_TESTS ${MSCEQF_TESTS})
list(APPEND external LiePlusPlus)
list(APPEND include_dirs ${LIEPLUSPLUS_INCLUDE_DIR})
list(APPEND libs LiePlusPlus Eigen3::Eigen)
# YamlCPP
FetchContent_Declare(
yaml-cpp
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
GIT_TAG master
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
list(APPEND external yaml-cpp)
list(APPEND include_dirs ${YAML_CPP_INCLUDE_DIR})
list(APPEND libs yaml-cpp::yaml-cpp ${YAML_CPP_LIBRARIES})
# Boost
# FetchContent_Declare(
# Boost
# GIT_REPOSITORY https://github.com/boostorg/boost.git
# GIT_TAG boost-1.81.0
# GIT_SHALLOW TRUE
# GIT_PROGRESS TRUE
# )
# list(APPEND external Boost)
find_package(Boost REQUIRED)
list(APPEND include_dirs ${Boost_INCLUDE_DIRS})
list(APPEND libs ${Boost_LIBRARIES})
# OpenCV
# FetchContent_Declare(
# opencv
# GIT_REPOSITORY https://github.com/opencv/opencv.git
# GIT_TAG 4.7.0
# GIT_SHALLOW TRUE
# GIT_PROGRESS TRUE
# )
# list(APPEND external opencv)
find_package(OpenCV 4 REQUIRED)
list(APPEND include_dirs ${OpenCV_INCLUDE_DIRS})
list(APPEND libs ${OpenCV_LIBRARIES})
FetchContent_MakeAvailable(${external})
message(STATUS "Eigen VER: " ${EIGEN3_VERSION})
message(STATUS "Lie++ VER: " ${LiePlusPlus_VERSION})
message(STATUS "Yaml-cpp VER: " ${YAML_CPP_VERSION})
message(STATUS "Boost VER: " ${Boost_VERSION})
message(STATUS "OpenCV VER: " ${OpenCV_VERSION})
include(CheckCXXCompilerFlag)
# Set compiler flags
set(RELEASE_FLAGS "-DNDEBUG" "-O3" "-fsee" "-fomit-frame-pointer" "-fno-signed-zeros" "-fno-math-errno" "-funroll-loops" "-fno-unsafe-math-optimizations" "-flto" "-march=native")
set(DEBUG_FLAGS "-O0" "-g3" "-Wall" "-Wextra" "-Werror" "-Wuninitialized" "-Wmaybe-uninitialized" "-pedantic" "-fno-omit-frame-pointer")
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
if(COMPILER_SUPPORTS_CXX17)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no c++17 support. Please use a different C++ compiler.")
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
foreach(FLAG ${DEBUG_FLAGS})
string(REPLACE "-" "" FLAG_NAME ${FLAG})
string(TOUPPER ${FLAG_NAME} FLAG_VAR_NAME)
CHECK_CXX_COMPILER_FLAG("${FLAG}" COMPILER_SUPPORTS_${FLAG_VAR_NAME})
if (COMPILER_SUPPORTS_${FLAG_VAR_NAME})
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
else()
message("${FLAG} was requested but is not supported.")
endif()
endforeach()
if (ENABLE_ADDRESS_SANITIZER)
CHECK_CXX_COMPILER_FLAG("-fsanitize=address" COMPILER_SUPPORTS_ADDRESS_SANITIZER)
if (COMPILER_SUPPORTS_ADDRESS_SANITIZER)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fsanitize-recover=address")
else()
message("-fsanitize=address -fsanitize-recover=address were requested but is not supported.")
endif()
elseif (ENABLE_UNDEFINED_SANITIZER)
CHECK_CXX_COMPILER_FLAG("-fsanitize=undefined" COMPILER_SUPPORTS_UNDEFINED_SANITIZER)
if (COMPILER_SUPPORTS_UNDEFINED_SANITIZER)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined")
else()
message("-fsanitize=undefined was requested but is not supported.")
endif()
elseif(ENABLE_THREAD_SANITIZER)
CHECK_CXX_COMPILER_FLAG("-fsanitize=thread" COMPILER_SUPPORTS_THREAD_SANITIZER)
if (COMPILER_SUPPORTS_THREAD_SANITIZER)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=thread")
else()
message("-fsanitize=thread was requested but is not supported.")
endif()
endif()
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
foreach(FLAG ${RELEASE_FLAGS})
string(REPLACE "-" "" FLAG_NAME ${FLAG})
string(TOUPPER ${FLAG_NAME} FLAG_VAR_NAME)
CHECK_CXX_COMPILER_FLAG("${FLAG}" COMPILER_SUPPORTS_${FLAG_VAR_NAME})
if (COMPILER_SUPPORTS_${FLAG_VAR_NAME})
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${FLAG}")
else()
message("${FLAG} was requested but is not supported.")
endif()
endforeach()
endif()
## List source files
list(
APPEND lib_sources
source/msceqf/msceqf.cpp
source/msceqf/options/msceqf_option_parser.cpp
source/msceqf/state/state.cpp
source/msceqf/system/system.cpp
source/msceqf/symmetry/symmetry.cpp
source/msceqf/filter/propagator/propagator.cpp
source/msceqf/filter/updater/zero_velocity_updater.cpp
source/msceqf/filter/updater/updater.cpp
source/msceqf/filter/updater/updater_helper.cpp
source/msceqf/filter/checker/checker.cpp
source/msceqf/filter/initializer/static_initializer.cpp
source/vision/camera.cpp
source/vision/tracker.cpp
source/vision/track_manager.cpp
)
## Define includes
list(APPEND include_dirs ${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${include_dirs})
# Define build
if (ROS_BUILD)
find_package(catkin QUIET COMPONENTS roscpp)
find_package(ament_cmake QUIET)
if (catkin_FOUND)
message(STATUS "ROS 1 version found, building with ROS1")
include(${CMAKE_CURRENT_SOURCE_DIR}/wrappers/ros/ros1/cmake/ros1.cmake)
elseif (ament_cmake_FOUND)
message(STATUS "ROS 2 version found, building with ROS2")
include(${CMAKE_CURRENT_SOURCE_DIR}/wrappers/ros/ros2/cmake/ros2.cmake)
else ()
message(STATUS "No ROS versions found, building native C++")
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/native.cmake)
endif ()
else ()
message(STATUS "Building native C++")
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/native.cmake)
endif ()