forked from xdspacelab/openvslam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
300 lines (250 loc) · 9.2 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.1)
project(openvslam LANGUAGES CXX C)
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()
if(POLICY CMP0074)
cmake_policy(SET CMP0074 OLD)
endif()
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
##################
# Set build type #
##################
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Release")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
###########################
# Set application options #
###########################
set(USE_CCACHE ON CACHE BOOL "Use ccache to accelerate a build")
find_program(CCACHE_EXE ccache)
if(USE_CCACHE AND CCACHE_EXE)
message(STATUS "ccache: Enabled")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_EXE}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_EXE}")
else()
message(STATUS "ccache: Disabled")
set(USE_CCACHE OFF)
endif()
set(USE_SANITIZER OFF CACHE BOOL "Enable Address/Memory sanitizer (set env as ASAN_OPTIONS=detect_leaks=1)")
if(USE_SANITIZER)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
message(STATUS "Address/Memory sanitizer: ENABLED")
else()
message(STATUS "Address/Memory sanitizer: DISABLED")
endif()
set(USE_STACK_TRACE_LOGGER OFF CACHE BOOL "Enable automatic stack trace logger of google-glog")
if(USE_STACK_TRACE_LOGGER)
message(STATUS "Stack trace logger: ENABLED")
# Glog
find_package(Glog REQUIRED)
include_directories(${GLOG_INCLUDE_DIR})
else()
message(STATUS "Stack trace logger: DISABLED")
endif()
set(USE_GOOGLE_PERFTOOLS OFF CACHE BOOL "Enable profiler of google-perftools")
if(USE_GOOGLE_PERFTOOLS)
message(STATUS "Google Perftools: ENABLED")
# Gperftools
find_package(Gperftools REQUIRED)
include_directories(${GPERFTOOLS_INCLUDE_DIRS})
else()
message(STATUS "Google Perftools: DISABLED")
endif()
########################
# Set compiler options #
########################
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Og")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -ffast-math")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -ffast-math")
set(BUILD_WITH_MARCH_NATIVE OFF CACHE BOOL "Enable architecture-aware optimization (-march=native)")
if(BUILD_WITH_MARCH_NATIVE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=native -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -mtune=native -march=native")
message(STATUS "Architecture-aware optimization (-march=native): ENABLED")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=native")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -mtune=native")
message(STATUS "Architecture-aware optimization (-march=native): DISABLED")
endif()
set(USE_SSE_ORB OFF CACHE BOOL "Enable SSE3 instruction for ORB extraction (-msse3)")
if(USE_SSE_ORB)
message(STATUS "SSE3 for ORB extraction (-msse3): ENABLED")
add_definitions(-DUSE_SSE_ORB)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3")
else()
message(STATUS "SSE3 for ORB extraction (-msse3): DISABLED")
remove_definitions(-DUSE_SSE_ORB)
endif()
set(USE_SSE_FP_MATH OFF CACHE BOOL "Enable SSE instruction for floating-point operation (-mfpmath=sse)")
if(USE_SSE_FP_MATH)
message(STATUS "SSE for floating-point operation (-mfpmath=sse): ENABLED")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpmath=sse")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=sse")
else()
message(STATUS "SSE for floating-point operation (-mfpmath=sse): DISABLED")
endif()
#######################
# Check C++11 support #
#######################
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++17" COMPILER_SUPPORTS_CXX17)
check_cxx_compiler_flag("-std=c++14" COMPILER_SUPPORTS_CXX14)
check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11)
check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
message(STATUS "C++11 support: OK (-std=c++17)")
elseif(COMPILER_SUPPORTS_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
message(STATUS "C++11 support: OK (-std=c++14)")
elseif(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
message(STATUS "C++11 support: OK (-std=c++11)")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
message(STATUS "C++11 support: OK (-std=c++0x)")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
#################
# Find packages #
#################
include_directories(${PROJECT_SOURCE_DIR}/src)
# thread library
find_package(Threads REQUIRED)
# OpenMP
set(USE_OPENMP ON CACHE BOOL "Use OpenMP")
if(USE_OPENMP)
find_package(OpenMP)
if(OpenMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
add_definitions(-DUSE_OPENMP)
message(STATUS "OpenMP: ENABLED")
else()
remove_definitions(-DUSE_OPENMP)
message(STATUS "OpenMP: DISABLED")
endif()
else()
remove_definitions(-DUSE_OPENMP)
message(STATUS "OpenMP: DISABLED")
endif()
# OpenCV
find_package(OpenCV 3.3.1 QUIET)
if(NOT OpenCV_FOUND)
find_package(OpenCV 4.0)
if(NOT OpenCV_FOUND)
message(FATAL_ERROR "OpenCV >= 3.3.1 not found")
endif()
endif()
message(STATUS "Use OpenCV ${OpenCV_VERSION}")
include_directories(${OpenCV_INCLUDE_DIRS})
# Eigen
find_package(Eigen3 3.2 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})
# g2o
find_package(G2O REQUIRED)
include_directories(${G2O_INCLUDE_DIR})
# CXSparse for g2o
find_package(CXSparse)
if(CXSPARSE_FOUND)
include_directories(${CXSPARSE_INCLUDE_DIRS})
endif()
# SuiteSparse for g2o
find_package(SuiteSparse)
if(SUITESPARSE_FOUND)
include_directories(${SUITESPARSE_INCLUDE_DIRS})
endif()
# yaml-cpp
find_package(YamlCpp REQUIRED)
include_directories(${YAMLCPP_INCLUDE_DIRS})
# spdlog
set(spdlog_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/3rd/spdlog/include)
include_directories(${spdlog_INCLUDE_DIR})
# popl
set(popl_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/3rd/popl/include)
include_directories(${popl_INCLUDE_DIR})
# json
set(json_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/3rd/json/include)
include_directories(${json_INCLUDE_DIR})
# pangolin viewer
set(USE_PANGOLIN_VIEWER ON CACHE BOOL "Enable Pangolin Viewer")
if(USE_PANGOLIN_VIEWER)
find_package(Pangolin REQUIRED)
endif()
# socket publisher
set(USE_SOCKET_PUBLISHER OFF CACHE BOOL "Enable Socket Publisher")
if(USE_SOCKET_PUBLISHER)
find_package(sioclient REQUIRED)
find_package(Protobuf REQUIRED)
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
message(FATAL_ERROR "Could not find protoc executable (PROTOBUF_PROTOC_EXECUTABLE)")
endif()
message(STATUS "Found protoc executable: ${PROTOBUF_PROTOC_EXECUTABLE}")
endif()
#################
# BoW framework #
#################
set(BOW_FRAMEWORK "DBoW2" CACHE STRING "DBoW2 or FBoW")
set_property(CACHE BOW_FRAMEWORK PROPERTY STRINGS "DBoW2" "FBoW")
if(BOW_FRAMEWORK MATCHES "DBoW2")
find_package(DBoW2 REQUIRED)
set(BOW_INCLUDE_DIRS ${DBoW2_INCLUDE_DIRS})
set(BOW_LIBS ${DBoW2_LIBS})
add_definitions(-DUSE_DBOW2)
elseif(BOW_FRAMEWORK MATCHES "FBoW")
find_package(fbow REQUIRED)
set(BOW_INCLUDE_DIRS ${fbow_INCLUDE_DIRS})
set(BOW_LIBS ${fbow_LIBS})
else()
message(FATAL_ERROR "Invalid BoW framework: ${BOW_FRAMEWORK}")
endif()
include_directories(${BOW_INCLUDE_DIRS})
message(STATUS "BoW framework: ${BOW_FRAMEWORK} (found in ${BOW_INCLUDE_DIRS})")
##############################
# Select g2o library modules #
##############################
set(USE_G2O_DEBUG OFF CACHE BOOL "Use the debug build of g2o")
if(USE_G2O_DEBUG)
set(G2O_LIBS
${G2O_CORE_LIBRARY_DEBUG}
${G2O_STUFF_LIBRARY_DEBUG}
${G2O_SOLVER_DENSE_DEBUG}
${G2O_SOLVER_EIGEN_DEBUG}
${G2O_SOLVER_CHOLMOD_DEBUG}
${G2O_SOLVER_CSPARSE_DEBUG}
${G2O_SOLVER_CSPARSE_EXTENSION_DEBUG}
${G2O_TYPES_SBA_DEBUG}
${G2O_TYPES_SIM3_DEBUG})
else()
set(G2O_LIBS
${G2O_CORE_LIBRARY}
${G2O_STUFF_LIBRARY}
${G2O_SOLVER_DENSE}
${G2O_SOLVER_EIGEN}
${G2O_SOLVER_CHOLMOD}
${G2O_SOLVER_CSPARSE}
${G2O_SOLVER_CSPARSE_EXTENSION}
${G2O_TYPES_SBA}
${G2O_TYPES_SIM3})
endif()
###################
# Build Selection #
###################
add_subdirectory(src)
add_subdirectory(example)
set(BUILD_TESTS OFF CACHE BOOL "Build tests")
if(BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()