-
Notifications
You must be signed in to change notification settings - Fork 17
/
CMakeLists.txt
211 lines (177 loc) · 6.22 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
cmake_minimum_required(VERSION 3.8)
project(ros2_orb_slam3)
# Make sure to set this path before building the
set(ENV{PYTHONPATH} "/opt/ros/humble/lib/python3.10/site-packages/") # Must be set to match your installation
# Must use C++17 to make it compatible with rclcpp
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3")
# Check C++17 support
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
if(COMPILER_SUPPORTS_CXX17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
add_definitions(-DCOMPILEDWITHC17)
message(STATUS "Using flag -std=c++17.")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support. Please use a different C++ compiler.")
endif()
LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules) # REDUNDANT?
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclpy REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
# find_package(your_custom_msg_interface REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(OpenCV 4.2 REQUIRED)
find_package(Eigen3 3.3.0 REQUIRED) # Matched with Sophus
find_package(Pangolin REQUIRED)
find_package(image_transport REQUIRED)
# Header file locations [C++ node]
include_directories(include) # Add .hpp, .h files from include/ros2_orb_slam3
include_directories(${EIGEN3_INCLUDE_DIRS}) # Include headers for eigen3
include_directories(${Pangolin_INCLUDE_DIRS}) # include headers for pangolin
include_directories(${OpenCV_INCLUDE_DIRS}) # include headers for pangolin
# ORB-SLAM3 includes [VSLAM library]
include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/orb_slam3
${PROJECT_SOURCE_DIR}/orb_slam3/include
${PROJECT_SOURCE_DIR}/orb_slam3/include/CameraModels
${PROJECT_SOURCE_DIR}/orb_slam3/Thirdparty
${PROJECT_SOURCE_DIR}/orb_slam3/Thirdparty/Sophus
${ament_INCLUDE_DIRS}
)
set(THIS_PACKAGE_INCLUDE_DEPENDS
rclcpp
rclpy
std_msgs
sensor_msgs
# your_custom_msg_interface
cv_bridge
image_transport
OpenCV
Eigen3
Pangolin
)
#* ORB SLAM3 as a shared library
# Whenever you add a new .h, .hpp or .cc, .cpp file in the ros2_orb_slam3/orb_slam3/include and os2_orb_slam3/orb_slam3/src directories, make sure to add them here as shown below
add_library(orb_slam3_lib SHARED
orb_slam3/src/System.cc
orb_slam3/src/Tracking.cc
orb_slam3/src/LocalMapping.cc
orb_slam3/src/LoopClosing.cc
orb_slam3/src/ORBextractor.cc
orb_slam3/src/ORBmatcher.cc
orb_slam3/src/FrameDrawer.cc
orb_slam3/src/Converter.cc
orb_slam3/src/MapPoint.cc
orb_slam3/src/KeyFrame.cc
orb_slam3/src/Atlas.cc
orb_slam3/src/Map.cc
orb_slam3/src/MapDrawer.cc
orb_slam3/src/Optimizer.cc
orb_slam3/src/Frame.cc
orb_slam3/src/KeyFrameDatabase.cc
orb_slam3/src/Sim3Solver.cc
orb_slam3/src/Viewer.cc
orb_slam3/src/ImuTypes.cc
orb_slam3/src/G2oTypes.cc
orb_slam3/src/CameraModels/Pinhole.cpp
orb_slam3/src/CameraModels/KannalaBrandt8.cpp
orb_slam3/src/OptimizableTypes.cpp
orb_slam3/src/MLPnPsolver.cpp
orb_slam3/src/GeometricTools.cc
orb_slam3/src/TwoViewReconstruction.cc
orb_slam3/src/Config.cc
orb_slam3/src/Settings.cc
orb_slam3/include/System.h
orb_slam3/include/Tracking.h
orb_slam3/include/LocalMapping.h
orb_slam3/include/LoopClosing.h
orb_slam3/include/ORBextractor.h
orb_slam3/include/ORBmatcher.h
orb_slam3/include/FrameDrawer.h
orb_slam3/include/Converter.h
orb_slam3/include/MapPoint.h
orb_slam3/include/KeyFrame.h
orb_slam3/include/Atlas.h
orb_slam3/include/Map.h
orb_slam3/include/MapDrawer.h
orb_slam3/include/Optimizer.h
orb_slam3/include/Frame.h
orb_slam3/include/KeyFrameDatabase.h
orb_slam3/include/Sim3Solver.h
orb_slam3/include/Viewer.h
orb_slam3/include/ImuTypes.h
orb_slam3/include/G2oTypes.h
orb_slam3/include/CameraModels/GeometricCamera.h
orb_slam3/include/CameraModels/Pinhole.h
orb_slam3/include/CameraModels/KannalaBrandt8.h
orb_slam3/include/OptimizableTypes.h
orb_slam3/include/MLPnPsolver.h
orb_slam3/include/GeometricTools.h
orb_slam3/include/TwoViewReconstruction.h
orb_slam3/include/SerializationUtils.h
orb_slam3/include/Config.h
orb_slam3/include/Settings.h
)
set_target_properties(orb_slam3_lib PROPERTIES VERSION "${orb_slam3_lib_VERSION}") # TODO need to findout why this is required
ament_target_dependencies(orb_slam3_lib
${THIS_PACKAGE_INCLUDE_DEPENDS}
)
# Link libraries
target_link_libraries(orb_slam3_lib
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/orb_slam3/Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/orb_slam3/Thirdparty/g2o/lib/libg2o.so
-lboost_system
-lboost_serialization
-lcrypto
)
# Find the .so files provided in ros2_orb_slam3/orb_slam3/Thirdparty projects
set(DBoW2_PATH "${PROJECT_SOURCE_DIR}/orb_slam3/Thirdparty/DBoW2/lib/libDBoW2.so")
set(g2o_PATH "${PROJECT_SOURCE_DIR}/orb_slam3/Thirdparty/g2o/lib/libg2o.so")
# Install .so files to the lib directory in the install space
install(FILES ${DBoW2_PATH} DESTINATION lib)
install(FILES ${g2o_PATH} DESTINATION lib)
# Add executable
add_executable(mono_node_cpp
src/mono_example.cpp
src/common.cpp
)
ament_target_dependencies(mono_node_cpp
PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS}
)
target_link_libraries(mono_node_cpp PUBLIC orb_slam3_lib) # Link a node with the internal shared library
# Install all the header files in package/package/include
install (DIRECTORY include/
DESTINATION include
)
# Install our node and library
install(TARGETS mono_node_cpp orb_slam3_lib
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION lib/${PROJECT_NAME}
INCLUDES DESTINATION include/${PROJECT_NAME}
)
# Tell downstream packages where to find the headers
ament_export_include_directories(include)
# Help downstream packages to find transitive dependencies
ament_export_dependencies(
orb_slam3_lib
${THIS_PACKAGE_INCLUDE_DEPENDS}
)
# Python node
# Install Python modules, submodules
ament_python_install_package(${PROJECT_NAME}) # Install the modules in ros2_orb_slam3/ros2_orb_slam3 folder
# Install Python executibles
install(PROGRAMS
scripts/mono_driver_node.py
DESTINATION lib/${PROJECT_NAME}
)
ament_package()