forked from ros-drivers/microstrain_mips
-
Notifications
You must be signed in to change notification settings - Fork 77
/
CMakeLists.txt
283 lines (241 loc) · 8.97 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
cmake_minimum_required(VERSION 3.0.2)
project(microstrain_inertial_driver)
# C++ 14 required
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Export compile commands by default (helpful for clang-tidy and autocomplete for certain IDEs)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "" FORCE)
# Force some options for this module and the MIP SDK
set(BUILD_SHARED_LIBS_TEMP "${BUILD_SHARED_LIBS}")
set(BUILD_EXAMPLES_TEMP "${BUILD_EXAMPLES}")
set(BUILD_TESTING_TEMP "${BUILD_TESTING}")
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
# Locate the common code and messages
set(COMMON_NAME "microstrain_inertial_driver_common")
set(COMMON_DIR "${${PROJECT_NAME}_SOURCE_DIR}/${COMMON_NAME}")
set(COMMON_SRC_DIR "${COMMON_DIR}/src")
set(COMMON_INC_DIR "${COMMON_DIR}/include/${COMMON_NAME}")
set(MIP_SDK_DIR "${COMMON_DIR}/mip_sdk")
set(MIP_SDK_SRC_DIR "${MIP_SDK_DIR}/src")
# Some helpful options for debugging
add_compile_options($<$<CONFIG:DEBUG>:-ggdb>)
# Try to find Git
find_package(Git)
# Make sure that the submodule has been properly initialized
if(NOT EXISTS "${COMMON_SRC_DIR}")
message(STATUS "Initializing ${COMMON_DIR} submodule. This should only happen once.")
# Make sure we can find the git executable
if(NOT Git_FOUND)
message(FATAL_ERROR "Unable to initialize submodule because we could not find the git executable. Please clone this repo using 'git clone --recursive'")
endif()
# Initialize and update the submodule
execute_process(
WORKING_DIRECTORY "${${PROJECT_NAME}_SOURCE_DIR}"
COMMAND ${CMAKE_COMMAND} -E env ${GIT_EXECUTABLE} submodule update --recursive --init
)
endif()
# Use Git to find the version
set(DEFAULT_DRIVER_GIT_VERSION "unknown")
if(NOT GIT_FOUND)
message(STATUS "Unable to find git, will build with unknown version")
set(DRIVER_GIT_VERSION ${DEFAULT_DRIVER_GIT_VERSION})
else()
execute_process(
COMMAND ${CMAKE_COMMAND} -E env ${GIT_EXECUTABLE} describe --tags
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE DRIVER_GIT_VERSION_OUT
ERROR_VARIABLE DRIVER_GIT_VERSION_ERR
RESULT_VARIABLE DRIVER_GIT_VERSION_RET
)
if(NOT ${DRIVER_GIT_VERSION_RET} EQUAL 0)
message(STATUS "Unable to determine version from Git, defaulting to version ${DEFAULT_DRIVER_GIT_VERSION}")
set(DRIVER_GIT_VERSION ${DEFAULT_DRIVER_GIT_VERSION})
else()
set(DRIVER_GIT_VERSION ${DRIVER_GIT_VERSION_OUT})
string(REGEX REPLACE "\n" "" DRIVER_GIT_VERSION "${DRIVER_GIT_VERSION}")
message(STATUS "Microstrain Driver Version: ${DRIVER_GIT_VERSION}")
endif()
endif()
# Set some general CMake flags
set(CMAKE_C_FLAGS "-Wno-implicit-function-declaration -Wno-incompatible-pointer-types -Wno-unused-variable -Wno-format -fno-builtin-memcpy")
# Include the MIP SDK source
add_subdirectory("${MIP_SDK_DIR}" EXCLUDE_FROM_ALL)
include_directories("${MIP_SDK_SRC_DIR}")
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
roslint
message_generation
geometry_msgs
nav_msgs
nmea_msgs
rtcm_msgs
roscpp
sensor_msgs
std_msgs
std_srvs
tf2
tf2_ros
tf2_geometry_msgs
microstrain_inertial_msgs
)
# Find some less ROS-y packages
list(APPEND CMAKE_MODULE_PATH "/usr/share/cmake/geographiclib/")
find_package(Eigen3 REQUIRED)
find_package(GeographicLib REQUIRED)
# We want to use the static library for libgeographic, but it doesn't seem to find it for us, so substitute it here
string(REGEX REPLACE "[.]so[^\\/\\s]*$" ".a" GeographicLib_LIBRARIES ${GeographicLib_LIBRARIES})
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if you package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
INCLUDE_DIRS
include
CATKIN_DEPENDS
roscpp
cmake_modules
tf2
tf2_ros
tf2_geometry_msgs
std_msgs
std_srvs
geometry_msgs
sensor_msgs
nav_msgs
nmea_msgs
rtcm_msgs
message_runtime
microstrain_inertial_msgs
)
###########
## Build ##
###########
# Add the catkin includes
include_directories(
include
${COMMON_DIR}/include
${catkin_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS}
${GeographicLib_INCLUDE_DIRS}
)
set(LIB_SRC_FILES
${COMMON_SRC_DIR}/subscribers.cpp
${COMMON_SRC_DIR}/publishers.cpp
${COMMON_SRC_DIR}/node_common.cpp
${COMMON_SRC_DIR}/services.cpp
${COMMON_SRC_DIR}/config.cpp
${COMMON_SRC_DIR}/utils/clock_bias_monitor.cpp
${COMMON_SRC_DIR}/utils/mappings/mip_mapping.cpp
${COMMON_SRC_DIR}/utils/mappings/mip_publisher_mapping.cpp
${COMMON_SRC_DIR}/utils/mip/ros_mip_device.cpp
${COMMON_SRC_DIR}/utils/mip/ros_mip_device_main.cpp
${COMMON_SRC_DIR}/utils/mip/ros_mip_device_aux.cpp
${COMMON_SRC_DIR}/utils/mip/ros_connection.cpp
src/microstrain_inertial_driver.cpp
)
set(LIB_INC_FILES
${COMMON_INC_DIR}/subscribers.h
${COMMON_INC_DIR}/publishers.h
${COMMON_INC_DIR}/node_common.h
${COMMON_INC_DIR}/services.h
${COMMON_INC_DIR}/config.h
${COMMON_INC_DIR}/utils/ros_compat.h
${COMMON_INC_DIR}/utils/clock_bias_monitor.h
${COMMON_INC_DIR}/utils/mappings/mip_mapping.h
${COMMON_INC_DIR}/utils/mappings/mip_publisher_mapping.h
${COMMON_INC_DIR}/utils/mip/ros_mip_device.h
${COMMON_INC_DIR}/utils/mip/ros_mip_device_main.h
${COMMON_INC_DIR}/utils/mip/ros_mip_device_aux.h
${COMMON_INC_DIR}/utils/mip/ros_connection.h
include/${PROJECT_NAME}/microstrain_inertial_driver.h
)
add_library(${PROJECT_NAME} ${LIB_SRC_FILES} ${LIB_INC_FILES})
add_dependencies(${PROJECT_NAME}
${${PROJECT_NAME}_EXPORTED_TARGETS}
${catkin_EXPORTED_TARGETS}
)
# Executables
set(NODE_SRC_FILES
src/microstrain_inertial_driver_node.cpp
)
set(NODE_INC_FILES
include/${PROJECT_NAME}/microstrain_inertial_driver.h
)
add_executable(${PROJECT_NAME}_node ${NODE_SRC_FILES} ${NODE_INC_FILES})
# Annoying, but the ROS types don't match up with the MIP types for floats and doubles, so ignore those warnings for now
set_source_files_properties(${COMMON_SRC_DIR}/services.cpp PROPERTIES COMPILE_FLAGS "-Wno-narrowing")
set_source_files_properties(${COMMON_SRC_DIR}/services.cpp PROPERTIES COMPILE_OPTIONS "-Wno-narrowing")
# Tell the code the version of the driver that is being build
add_definitions(-DMICROSTRAIN_DRIVER_VERSION="${DRIVER_GIT_VERSION}")
# Let the code know if it is being compiled with ROS1 or ROS2
if(DEFINED ENV{ROS_VERSION})
add_definitions(-DMICROSTRAIN_ROS_VERSION=$ENV{ROS_VERSION})
else()
message(FATAL_ERROR "ROS_VERSION environment variable is not set.")
endif()
# Allow the MSCL include directory to be accessed
include_directories(${MSCL_INC_PATH} ${BOOST_INC_PATH})
# Linking
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
mip
)
target_link_libraries(${PROJECT_NAME}_node
${PROJECT_NAME}
${catkin_LIBRARIES}
${GeographicLib_LIBRARIES}
)
#############
## Install ##
#############
install(TARGETS ${PROJECT_NAME}_node
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
PUBLIC_HEADER DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
)
install(DIRECTORY launch config
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
install(DIRECTORY ${COMMON_DIR}/config
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/${COMMON_NAME}
)
# Reset the forced options
set(BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS_TEMP}" CACHE BOOL "${BUILD_SHARED_LIBS_TEMP}" FORCE)
set(BUILD_EXAMPLES "${BUILD_EXAMPLES_TEMP}" CACHE BOOL "${BUILD_EXAMPLES_TEMP}" FORCE)
set(BUILD_TESTING "${BUILD_TESTING_TEMP}" CACHE BOOL "${BUILD_TESTING_TEMP}" FORCE)
#############
## Testing ##
#############
# build/c++11 and whitespace/braces only trip on the buildfarm which is melodic, maybe it's not needed in noetic?
set(ROSLINT_CPP_OPTS "--filter=-whitespace/line_length,-runtime/references,-readability/fn_size,-whitespace/parens,-build/c++11,-whitespace/braces")
get_target_property(ROSLINT_SOURCES ${PROJECT_NAME} SOURCES)
roslint_cpp(${ROSLINT_SOURCES})
roslint_add_test()
# Make sure that the wiki document is up to date
add_test(
NAME wiki_publishers
COMMAND ${CMAKE_COMMAND} -E env ${COMMON_DIR}/tools/check-wiki-publishers.sh
)
add_test(
NAME wiki_services
COMMAND ${CMAKE_COMMAND} -E env ${COMMON_DIR}/tools/check-wiki-services.sh
)
add_test(
NAME wiki_subscribers
COMMAND ${CMAKE_COMMAND} -E env ${COMMON_DIR}/tools/check-wiki-subscribers.sh
)
# Make the ROS tests target run our tests as well
if (BUILD_TESTING)
add_custom_target(custom_tests COMMAND ${CMAKE_CTEST_COMMAND})
add_dependencies(run_tests custom_tests)
endif()