forked from raulmur/ORB_SLAM2
-
Notifications
You must be signed in to change notification settings - Fork 47
/
CMakeLists.txt
412 lines (359 loc) · 12.1 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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
cmake_minimum_required(VERSION 2.8)
project(gf_orb_slam2)
find_package(catkin REQUIRED COMPONENTS
rospy
roscpp
sensor_msgs
cv_bridge
image_transport
tf
tf2
tf2_geometry_msgs
tf2_ros
geometry_msgs
# for closed-loop evaluation of Good Graph only
trajectory_state_predictor
)
message("ROS version = " $ENV{ROS_DISTRO})
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Release)
ENDIF()
MESSAGE("Build type: " ${CMAKE_BUILD_TYPE})
IF(NOT DEFINED ORB_LIB_TYPE)
SET (ORB_LIB_TYPE "SHARED") # "STATIC"
ENDIF()
IF(NOT DEFINED ENABLE_CUDA_IN_OPENCV)
SET(ENABLE_CUDA_IN_OPENCV True)
ENDIF()
message("Enable cuda support: " ${ENABLE_CUDA_IN_OPENCV})
# Check architecture
IF(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
add_definitions("-DENABLE_SSE")
MESSAGE("SSE flags: " ${SSE_FLAGS})
# Optimized for Jetson TX2 only; refer to https://devtalk.nvidia.com/default/topic/1028179/jetson-tx2/gcc-options-for-tx2
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--no-as-needed -pthread -fopenmp -Wall -O3 -ffast-math -flto -march=armv8-a+crypto -mcpu=cortex-a57+crypto")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--no-as-needed -pthread -fopenmp -Wall -O3 -ffast-math -flto -march=armv8-a+crypto -mcpu=cortex-a57+crypto")
ELSE()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--no-as-needed -pthread -fopenmp -Wall -O3 -march=native ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--no-as-needed -pthread -fopenmp -Wall -O3 -march=native")
ENDIF()
# Add CUDA support
if(ENABLE_CUDA_IN_OPENCV)
find_package(CUDA REQUIRED)
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
SET(CUDA_HOST_COMPILER /usr/bin/g++)
LIST(APPEND CUDA_NVCC_FLAGS "--compiler-options -fno-strict-aliasing -use_fast_math")
#LIST(APPEND CUDA_NVCC_FLAGS "--compiler-options -Xcompiler -fpermissive")
endif()
# Check C++11 or C++0x support
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if(ENABLE_CUDA_IN_OPENCV)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_NVTX")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_NVTX")
endif()
add_definitions(-DCOMPILEDWITHC11)
message(STATUS "Using flag -std=c++11.")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
if(ENABLE_CUDA_IN_OPENCV)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++0x")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_NVTX")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_NVTX")
endif()
add_definitions(-DCOMPILEDWITHC0X)
message(STATUS "Using flag -std=c++0x.")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
IF(SLAM_P_P_SHORT_CXSPARSE)
ADD_DEFINITIONS(-D__CXSPARSE_SHORT)
ENDIF(SLAM_P_P_SHORT_CXSPARSE)
IF(SLAM_P_P_SHORT_CHOLMOD)
ADD_DEFINITIONS(-D__CHOLMOD_SHORT)
ENDIF(SLAM_P_P_SHORT_CHOLMOD)
IF(SLAM_P_P_FLAT_SYSTEM_ALIGNED_MEMORY)
ADD_DEFINITIONS(-D__FLAT_SYSTEM_ALIGNED_MEMORY)
ENDIF(SLAM_P_P_FLAT_SYSTEM_ALIGNED_MEMORY)
# support for GPU BLAS
#IF(SLAM_P_P_GPU_BLAS)
# ADD_DEFINITIONS(
# -DGPU_BLAS
# -D__CHANNEL_DESCRIPTOR_H__
# -D__CUDA_RUNTIME_H__)
#ENDIF(SLAM_P_P_GPU_BLAS)
ADD_DEFINITIONS(-DCERES_NO_PROTOCOL_BUFFERS)
IF(SLAM_P_P_LINEAR_SOLVER_TYPE)
ADD_DEFINITIONS("-D__LINEAR_SOLVER_OVERRIDE=${SLAM_P_P_LINEAR_SOLVER_TYPE}")
ENDIF(SLAM_P_P_LINEAR_SOLVER_TYPE)
LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)
# customize opencv dir
if ($ENV{ROS_DISTRO} STREQUAL "indigo")
set( OpenCV_DIR /opt/opencv2/share/OpenCV )
find_package(OpenCV 2.4.13 REQUIRED core ocl)
elseif ($ENV{ROS_DISTRO} STREQUAL "kinetic")
set( OpenCV_DIR /opt/opencv3/share/OpenCV )
find_package(OpenCV 3.4.1 REQUIRED
PATHS /opt/opencv3
NO_DEFAULT_PATH)
endif()
MESSAGE("OpenCV include dir: " ${OpenCV_INCLUDE_DIRS})
MESSAGE("OpenCV libs: " ${OpenCV_LIBS})
# customize eigen dir
# find_package(Eigen3 3.1.0 REQUIRED)
set( EIGEN3_INCLUDE_DIR /opt/eigen33/include/eigen3/ )
# set( EIGEN3_INCLUDE_DIR /usr/include/eigen3 )
MESSAGE("EIGEN include dir: " ${EIGEN3_INCLUDE_DIR})
# MESSAGE("EIGEN libs: " ${EIGEN3_LIBS})
# customize pangolin dir
# set(Pangolin_DIR /opt/Pangolin/lib/cmake/Pangolin/)
# find_package(Pangolin REQUIRED)
set(Pangolin_INCLUDE_DIRS /opt/Pangolin/include/)
set(Pangolin_LIBRARIES /opt/Pangolin/lib/libpangolin.so)
MESSAGE("Pangolin include dir: " ${Pangolin_INCLUDE_DIRS})
# customize openblas dir
set(OpenBLAS_LIBRARIES /opt/OpenBLAS/lib/libopenblas.so)
MESSAGE("OpenBLAS libs:" ${OpenBLAS_LIBRARIES})
# customize armadillo dir
set(ARMADILLO_INCLUDE_DIR /opt/armadillo/include)
set(ARMADILLO_LIBRARIES /opt/armadillo/lib/libarmadillo.so)
MESSAGE("ARMADILLO libs: " ${ARMADILLO_LIBRARIES})
# customize gtest dir
set(GTest_INCLUDE_DIR /usr/src/gtest/src)
set(GTest_LIBRARIES /usr/src/gtest/libgtest.a)
MESSAGE("gtest libs: " ${GTest_LIBRARIES})
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
MESSAGE("ccache:" ${CCACHE_FOUND})
else (CCACHE_FOUND)
MESSAGE("No ccache detected")
endif(CCACHE_FOUND)
# GFlags
find_package(GFlags REQUIRED)
MESSAGE("gflags include dirs: " ${GFLAGS_INCLUDE_DIR})
find_package(Boost REQUIRED COMPONENTS thread system filesystem)
MESSAGE("Boost include dir: " ${Boost_INCLUDE_DIRS})
MESSAGE("Boost lib: " ${Boost_LIBRARIES})
include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/include
${PROJECT_SOURCE_DIR}/Thirdparty/sse2neon/
${OpenCV_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
${Pangolin_INCLUDE_DIRS}
${ARMADILLO_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
${GTest_INCLUDE_DIR}
${catkin_INCLUDE_DIRS}
)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
if(ENABLE_CUDA_IN_OPENCV)
cuda_include_directories(
${CUDA_TOOLKIT_ROOT_DIR}/samples/common/inc
)
cuda_add_library(${PROJECT_NAME} ${ORB_LIB_TYPE}
include/Util_cuda.hpp
include/Util.hpp
src/System.cc
src/ChArUco.cc
src/Observability.cc
src/Hashing.cc
src/Tracking.cc
src/LocalMapping.cc
src/LoopClosing.cc
src/ORBextractor.cc
src/ORBmatcher.cc
src/FrameDrawer.cc
src/Converter.cc
src/MapPoint.cc
src/KeyFrame.cc
src/Map.cc
src/MapDrawer.cc
src/MapPublisher.cc
src/Optimizer.cc
src/PnPsolver.cc
src/Frame.cc
src/KeyFrameDatabase.cc
src/Sim3Solver.cc
src/Initializer.cc
src/Viewer.cc
src/cuda/Allocator_gpu.cu
src/cuda/Fast_gpu.cu
src/cuda/Orb_gpu.cu
src/cuda/Cuda.cu
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/src/good_graph_testbed/BAOptimizer.cpp
)
IF(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
cuda_add_library(${PROJECT_NAME} ${ORB_LIB_TYPE} src/FAST_NEON.cc)
ENDIF()
else()
set(SRCS
include/Util.hpp
src/System.cc
src/ChArUco.cc
src/Hashing.cc
src/Observability.cc
src/Tracking.cc
src/LocalMapping.cc
src/LoopClosing.cc
src/ORBextractor.cc
src/ORBmatcher.cc
src/FrameDrawer.cc
src/Converter.cc
src/MapPoint.cc
src/KeyFrame.cc
src/Map.cc
src/MapDrawer.cc
src/MapPublisher.cc
src/Optimizer.cc
src/PnPsolver.cc
src/Frame.cc
src/KeyFrameDatabase.cc
src/Sim3Solver.cc
src/Initializer.cc
src/Viewer.cc
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/src/good_graph_testbed/BAOptimizer.cpp
)
IF(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
set(SRCS ${SRCS} src/FAST_NEON.cc)
ENDIF()
add_library(${PROJECT_NAME} ${ORB_LIB_TYPE} ${SRCS})
endif()
# SLAM ++ header files
FILE(GLOB_RECURSE SLAM_EXAMPLE_HEADERS
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/include/good_graph_testbed/*.h
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/include/slam/*.h)
if (${ORB_LIB_TYPE} STREQUAL "STATIC")
set(LIBS
${GFLAGS_LIBRARIES}
${OpenCV_LIBS}
# ${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${OpenBLAS_LIBRARIES}
${ARMADILLO_LIBRARIES}
${Boost_LIBRARIES}
${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.a
${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.a
#libtrajectory_state_predictor.a
)
SET(SLAM_PLUS_PLUS_LIBRARIES
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/lib/libeigen.a
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/lib/libcxsparse.a
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/lib/libcsparse.a
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/lib/libcholmod.a
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/lib/libcamd_dlong.a
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/lib/libslampp_base.a
)
else()
set(LIBS
GL
glut
GLU
${GFLAGS_LIBRARIES}
${OpenCV_LIBS}
# ${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${OpenBLAS_LIBRARIES}
${ARMADILLO_LIBRARIES}
${Boost_LIBRARIES}
${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.so
#trajectory_state_predictor
)
SET(SLAM_PLUS_PLUS_LIBRARIES
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/lib/libeigen.so
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/lib/libcxsparse.so
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/lib/libcsparse.so
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/lib/libcholmod.so
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/lib/libcamd_dlong.so
${PROJECT_SOURCE_DIR}/Thirdparty/SLAM++/lib/libslampp_base.so
)
endif()
if(ENABLE_CUDA_IN_OPENCV)
target_link_libraries(${PROJECT_NAME}
${LIBS}
${catkin_LIBRARIES}
nvToolsExt
${SLAM_PLUS_PLUS_LIBRARIES})
else()
target_link_libraries(${PROJECT_NAME}
GL
glut
GLU
${LIBS}
${catkin_LIBRARIES}
${SLAM_PLUS_PLUS_LIBRARIES})
endif()
# Build examples
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/tools)
add_executable(bin_vocabulary tools/bin_vocabulary.cc)
target_link_libraries(bin_vocabulary ${PROJECT_NAME})
# Build ROS Nodes
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/ROS/GF_ORB_SLAM2)
# Node for monocular camera
add_executable(Mono Examples/ROS/GF_ORB_SLAM2/src/ros_mono.cc)
target_link_libraries(Mono
${LIBS}
${catkin_LIBRARIES}
${PROJECT_NAME}
)
# Node for monocular camera (Augmented Reality Demo)
#add_executable(MonoAR
#src/AR/ros_mono_ar.cc
#src/AR/ViewerAR.h
#src/AR/ViewerAR.cc
#)
#target_link_libraries(MonoAR
#${LIBS}
#)
# Node for stereo camera
add_executable(Stereo Examples/ROS/GF_ORB_SLAM2/src/ros_stereo.cc)
# src/path_smoothing_ros/cubic_spline_interpolator.cpp)
target_link_libraries(Stereo
${LIBS}
${catkin_LIBRARIES}
${PROJECT_NAME}
)
# Node for RGB-D camera
add_executable(RGBD Examples/ROS/GF_ORB_SLAM2/src/ros_rgbd.cc)
# string(REPLACE "/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_core3.so.3.3.1;" "" catkin_LIBRARIES "${catkin_LIBRARIES}")
MESSAGE("catkin_LIBRARIES: " ${catkin_LIBRARIES})
target_link_libraries(RGBD
${LIBS}
${catkin_LIBRARIES}
${PROJECT_NAME}
)
# Build test cases
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/test)
add_executable(testObs
${SRCS}
./test/test_Kine_1.cpp
./test/test_Kine_2.cpp
./test/test_Jacobian.cpp
# ./test/test_Greedy.cpp
# ./test/test_GoodMap.cpp
./test/test_Stereo.cpp
# ./test/test_MapIO.cpp
./test/main.cpp
)
target_link_libraries(testObs
GL
glut
GLU
${PROJECT_NAME}
${GTest_LIBRARIES}
${SLAM_PLUS_PLUS_LIBRARIES}
${OpenBLAS_LIBRARIES}
${ARMADILLO_LIBRARIES}
${GTest_LIBRARIES}
)
# Build exec for Jetson TX2
#unset(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
#add_subdirectory(gpu)