forked from PX4/PX4-SITL_gazebo-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
429 lines (362 loc) · 13.7 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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR)
cmake_policy(SET CMP0042 NEW)
cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0054 NEW)
if (NOT CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "/usr" CACHE STRING "install prefix" FORCE)
endif()
message(STATUS "install-prefix: ${CMAKE_INSTALL_PREFIX}")
project(mavlink_sitl_gazebo VERSION 1.0.0)
include(GNUInstallDirs)
#######################
## Find Dependencies ##
#######################
# Add search directory for CMake on OS X
list(APPEND CMAKE_MODULE_PATH /usr/local/share/cmake/Modules)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
option(BUILD_GSTREAMER_PLUGIN "enable gstreamer plugin" "OFF")
option(BUILD_ROS_INTERFACE "enable ROS subscriber for motor failure plugin" "OFF")
## System dependencies are found with CMake's conventions
find_package(PkgConfig REQUIRED)
find_package(gazebo REQUIRED)
find_program(px4 REQUIRED)
find_package(OpenCV REQUIRED)
find_package(Boost REQUIRED COMPONENTS system thread timer)
find_package(PythonInterp REQUIRED)
if (BUILD_GSTREAMER_PLUGIN)
find_package(GStreamer)
if (GSTREAMER_FOUND)
if("${GAZEBO_VERSION}" VERSION_LESS "8.0")
find_package (Qt4)
include (${QT_USE_FILE})
endif()
endif()
endif()
pkg_check_modules(OGRE OGRE)
include_directories(SYSTEM ${GAZEBO_INCLUDE_DIRS})
link_directories(${GAZEBO_LIBRARY_DIRS})
add_subdirectory( external/OpticalFlow OpticalFlow )
set( OpticalFlow_LIBS "OpticalFlow" )
# for ROS subscribers and publishers
if (BUILD_ROS_INTERFACE)
find_package(roscpp REQUIRED)
find_package(mavros REQUIRED)
find_package(mavros_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(mav_msgs REQUIRED)
endif()
# find MAVLink
find_package(MAVLink)
# see if catkin was invoked to build this
if (CATKIN_DEVEL_PREFIX)
message(STATUS "catkin ENABLED")
find_package(catkin REQUIRED)
if (catkin_FOUND)
catkin_package()
else()
message(FATAL_ERROR "catkin not found")
endif()
else()
message(STATUS "catkin DISABLED")
endif()
# XXX this approach is extremely error prone
# it would be preferable to either depend on the
# compiled headers from Gazebo directly
# or to have something entirely independent.
#
set(PROTOBUF_IMPORT_DIRS "")
foreach(ITR ${GAZEBO_INCLUDE_DIRS})
if(ITR MATCHES ".*gazebo-[0-9.]+$")
set(PROTOBUF_IMPORT_DIRS "${ITR}/gazebo/msgs/proto")
endif()
endforeach()
# PROTOBUF_IMPORT_DIRS has to be set before
# find_package is called
find_package(Protobuf REQUIRED)
pkg_check_modules(PROTOBUF protobuf)
if ("${PROTOBUF_VERSION}" VERSION_LESS "2.5.0")
message(FATAL_ERROR "protobuf version: ${PROTOBUF_VERSION} not compatible, must be >= 2.5.0")
endif()
if("${GAZEBO_VERSION}" VERSION_LESS "6.0")
message(FATAL_ERROR "You need at least Gazebo 6.0. Your version: ${GAZEBO_VERSION}")
else()
message("Gazebo version: ${GAZEBO_VERSION}")
endif()
find_package(Eigen3 QUIET)
if(NOT EIGEN3_FOUND)
# Fallback to cmake_modules
find_package(Eigen QUIET)
if(NOT EIGEN_FOUND)
pkg_check_modules(EIGEN3 REQUIRED eigen3)
else()
set(EIGEN3_INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS})
set(EIGEN3_LIBRARIES ${EIGEN_LIBRARIES})
endif()
else()
set(EIGEN3_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIR})
endif()
find_package(Boost 1.40 COMPONENTS system thread timer REQUIRED )
###########
## Build ##
###########
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GAZEBO_CXX_FLAGS} -std=c++11 -Wno-deprecated-declarations")
# -Wno-deprecated-declarations: Shut up warnings about std::binder1st, std::binder2nd.
set(GAZEBO_MSG_INCLUDE_DIRS)
foreach(ITR ${GAZEBO_INCLUDE_DIRS})
if(ITR MATCHES ".*gazebo-[0-9.]+$")
set(GAZEBO_MSG_INCLUDE_DIRS "${ITR}/gazebo/msgs")
endif()
endforeach()
include_directories(
include
${OpticalFlow_INCLUDE_DIRS}
${GAZEBO_INCLUDE_DIRS}
${GAZEBO_MSG_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
${Boost_INCLUDE_DIR}
# Workaround for Eigen3
${Boost_INCLUDE_DIR}/eigen3
${EIGEN3_INCLUDE_DIRS}/eigen3
${OGRE_INCLUDE_DIRS}
# workaround for: "fatal error: OgrePagedWorldSection.h: No such file or directory"
${OGRE_INCLUDE_DIRS}/Paging
# Workaround for OGRE include dirs on Mac OS
# TODO: remove these hardcoded includes now that we have
/usr/local/include/OGRE
/usr/local/include/OGRE/Paging
${MAVLINK_INCLUDE_DIRS}
)
if (GSTREAMER_FOUND)
include_directories(
${GSTREAMER_INCLUDE_DIRS}
)
endif()
link_libraries(
${PROTOBUF_LIBRARY}
${GAZEBO_LIBRARIES}
${OpenCV_LIBRARIES}
${Boost_SYSTEM_LIBRARY_RELEASE}
${Boost_THREAD_LIBRARY_RELEASE}
${Boost_TIMER_LIBRARY_RELEASE}
)
if (GSTREAMER_FOUND)
link_libraries(
${GSTREAMER_LIBRARIES}
)
endif()
link_directories(
${GAZEBO_LIBRARY_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
${OGRE_LIBRARY_DIRS}
)
#--------------------------#
# Generation of SDF models #
#--------------------------#
set(enable_mavlink_interface "true")
set(enable_ground_truth "false")
set(enable_logging "false")
set(enable_camera "false")
set(enable_wind "false")
set(rotors_description_dir "${CMAKE_CURRENT_SOURCE_DIR}/models/rotors_description")
set(scripts_dir "${CMAKE_CURRENT_SOURCE_DIR}/scripts")
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/models/iris/iris.sdf
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND rm -f ${CMAKE_CURRENT_SOURCE_DIR}/models/iris/iris.sdf
COMMAND ${PYTHON_EXECUTABLE} ${scripts_dir}/xacro.py -o ${rotors_description_dir}/urdf/iris_base.urdf ${rotors_description_dir}/urdf/iris_base.xacro enable_mavlink_interface:=${enable_mavlink_interface} enable_ground_truth:=${enable_ground_truth} enable_wind:=${enable_wind} enable_logging:=${enable_logging} rotors_description_dir:=${rotors_description_dir}
COMMAND gz sdf -p ${rotors_description_dir}/urdf/iris_base.urdf >> ${CMAKE_CURRENT_SOURCE_DIR}/models/iris/iris.sdf
COMMAND rm -f ${rotors_description_dir}/urdf/iris_base.urdf
DEPENDS ${rotors_description_dir}/urdf/iris.xacro
DEPENDS ${rotors_description_dir}/urdf/iris_base.xacro
DEPENDS ${rotors_description_dir}/urdf/component_snippets.xacro
)
add_custom_target(sdf ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/models/iris/iris.sdf)
#-----------#
# Functions #
#-----------#
function(glob_generate target file_glob)
file(GLOB_RECURSE glob_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${file_glob})
set(gen_files)
foreach(glob_file ${glob_files})
string(REGEX REPLACE "\\.[^.]*$" "" file_name ${glob_file})
string(REGEX MATCH "[^.]*$" file_ext ${glob_file})
get_filename_component(file_dir ${glob_file} DIRECTORY)
set(in_file ${CMAKE_CURRENT_SOURCE_DIR}/${glob_file})
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${file_dir})
set(out_file ${CMAKE_CURRENT_SOURCE_DIR}/${file_name})
string(REGEX REPLACE ".sdf" "-gen.sdf" out_file ${out_file})
if (${file_ext} STREQUAL "jinja")
add_custom_command(OUTPUT ${out_file}
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/jinja_gen.py
${in_file} ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${in_file}
VERBATIM
)
list(APPEND gen_files_${target} ${out_file})
endif()
endforeach()
add_custom_target(${target} ALL DEPENDS ${gen_files_${target}})
endfunction()
glob_generate(models_gen ${CMAKE_CURRENT_SOURCE_DIR}/models/*.jinja)
#--------------------#
# Message Generation #
#--------------------#
set (msgs
msgs/Float.proto
msgs/Int32.proto
msgs/SensorImu.proto
msgs/opticalFlow.proto
msgs/lidar.proto
msgs/CommandMotorSpeed.proto
msgs/MotorSpeed.proto
#msgs/Wind.proto
msgs/sonarSens.proto
msgs/irlock.proto
msgs/SITLGps.proto
msgs/Groundtruth.proto
msgs/odom.proto
)
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${msgs})
add_library(mav_msgs SHARED ${PROTO_SRCS})
#---------#
# Plugins #
#---------#
link_libraries(mav_msgs)
# add_library(hello_world SHARED src/hello_world.cc)
add_library(rotors_gazebo_gimbal_controller_plugin SHARED src/gazebo_gimbal_controller_plugin.cpp)
target_link_libraries(rotors_gazebo_gimbal_controller_plugin ${Boost_LIBRARIES} ${GAZEBO_LIBRARIES} ${Boost_SYSTEM_LIBRARY_RELEASE} ${Boost_THREAD_LIBRARY_RELEASE})
# add_dependencies(rotors_gazebo_gimbal_controller_plugin)
add_library(rotors_gazebo_controller_interface SHARED src/gazebo_controller_interface.cpp)
add_library(rotors_gazebo_motor_model SHARED src/gazebo_motor_model.cpp)
add_library(rotors_gazebo_multirotor_base_plugin SHARED src/gazebo_multirotor_base_plugin.cpp)
add_library(rotors_gazebo_imu_plugin SHARED src/gazebo_imu_plugin.cpp)
add_library(gazebo_opticalFlow_plugin SHARED src/gazebo_opticalFlow_plugin.cpp)
target_link_libraries(gazebo_opticalFlow_plugin ${OpticalFlow_LIBS})
add_library(gazebo_lidar_plugin SHARED src/gazebo_lidar_plugin.cpp)
add_library(gazebo_irlock_plugin SHARED src/gazebo_irlock_plugin.cpp)
add_library(rotors_gazebo_mavlink_interface SHARED src/gazebo_mavlink_interface.cpp src/geo_mag_declination.cpp)
#add_library(rotors_gazebo_wind_plugin SHARED src/gazebo_wind_plugin.cpp)
add_library(gazebo_sonar_plugin SHARED src/gazebo_sonar_plugin.cpp)
add_library(gazebo_uuv_plugin SHARED src/gazebo_uuv_plugin.cpp)
add_library(gazebo_gps_plugin SHARED src/gazebo_gps_plugin.cpp)
add_library(gazebo_vision_plugin SHARED src/gazebo_vision_plugin.cpp)
set(plugins
rotors_gazebo_controller_interface
rotors_gazebo_motor_model
rotors_gazebo_multirotor_base_plugin
rotors_gazebo_imu_plugin
gazebo_opticalFlow_plugin
gazebo_lidar_plugin
gazebo_irlock_plugin
rotors_gazebo_mavlink_interface
#rotors_gazebo_wind_plugin
gazebo_sonar_plugin
gazebo_uuv_plugin
gazebo_gps_plugin
gazebo_vision_plugin
)
# ROS mavlink version not compatible with geotagged images plugin
if (NOT roscpp_FOUND)
add_library(gazebo_geotagged_images_plugin SHARED src/gazebo_geotagged_images_plugin.cpp)
list(APPEND plugins gazebo_geotagged_images_plugin)
endif()
#If BUILD_ROS_INTERFACE set to ON, build gazebo_hil_interface and gazebo_motor_failure_plugin
if (BUILD_ROS_INTERFACE)
add_library(gazebo_motor_failure_plugin SHARED src/gazebo_motor_failure_plugin.cpp)
target_link_libraries(gazebo_motor_failure_plugin ${GAZEBO_libraries} ${roscpp_LIBRARIES})
list(APPEND plugins gazebo_motor_failure_plugin)
message(STATUS "adding gazebo_motor_failure_plugin to build")
include_directories(
include
${mavros_msgs_INCLUDE_DIRS}
${geometry_msgs_INCLUDE_DIRS}
${sensor_msgs_INCLUDE_DIRS}
${mav_msgs_INCLUDE_DIRS}
)
add_executable(gazebo_hil_interface
src/gazebo_hil_interface.cpp
)
add_dependencies(gazebo_hil_interface
${catkin_EXPORTED_TARGETS}
${mavros_EXPORTED_TARGETS}
${mavros_msgs_EXPORTED_TARGETS}
)
target_link_libraries(gazebo_hil_interface
${catkin_LIBRARIES}
${mavros_LIBRARIES}
)
message(STATUS "adding gazebo_hil_interface to build")
endif()
if (GSTREAMER_FOUND)
add_library(gazebo_gst_camera_plugin SHARED src/gazebo_gst_camera_plugin.cpp)
set(plugins
${plugins}
gazebo_gst_camera_plugin
)
message(STATUS "Found GStreamer: adding gst_camera_plugin")
if("${GAZEBO_VERSION}" VERSION_LESS "8.0")
QT4_WRAP_CPP(headers_MOC include/gazebo_video_stream_widget.h)
add_library(gazebo_video_stream_widget SHARED ${headers_MOC} src/gazebo_video_stream_widget.cpp)
target_link_libraries(gazebo_video_stream_widget ${GAZEBO_LIBRARIES} ${QT_LIBRARIES} ${PROTOBUF_LIBRARIES})
set(plugins
${plugins}
gazebo_video_stream_widget
)
message(STATUS "Found GStreamer: adding gst_video_stream_widget")
endif()
endif()
# Linux is not consistent with plugin availability, even on Gazebo 7
#if("${GAZEBO_VERSION}" VERSION_LESS "7.0")
add_library(LiftDragPlugin SHARED src/liftdrag_plugin/liftdrag_plugin.cpp)
list(APPEND plugins LiftDragPlugin)
#endif()
foreach(plugin ${plugins})
add_dependencies(${plugin} mav_msgs)
endforeach()
# Configure the setup script
if (catkin_FOUND)
catkin_add_env_hooks(50_sitl_gazebo_setup
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake
SHELLS sh)
endif()
#############
## Install ##
#############
set(PLUGIN_PATH ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/plugins)
set(MODEL_PATH ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/models)
set(RESOURCE_PATH ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
file(REMOVE_RECURSE ${PROJECT_SOURCE_DIR}/models/.DS_Store)
file(GLOB models_list LIST_DIRECTORIES true ${PROJECT_SOURCE_DIR}/models/*)
file(REMOVE_RECURSE ${PROJECT_SOURCE_DIR}/worlds/.DS_Store)
file(GLOB worlds_list LIST_DIRECTORIES true ${PROJECT_SOURCE_DIR}/worlds/*)
install(TARGETS ${plugins} mav_msgs DESTINATION ${PLUGIN_PATH})
install(DIRECTORY ${models_list} DESTINATION ${MODEL_PATH})
install(FILES ${worlds_list} DESTINATION ${RESOURCE_PATH}/worlds)
configure_file(src/setup.sh.in "${CMAKE_CURRENT_BINARY_DIR}/setup.sh" @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/setup.sh DESTINATION ${RESOURCE_PATH})
#############
## Testing ##
#############
###############
## Packaging ##
###############
set(CPACK_PACKAGE_NAME ${PROJECT_NAME}-${GAZEBO_MAJOR_VERSION})
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_PACKAGE_CONTACT pxusers@googlegroups.com)
set(DEBIAN_PACKAGE_DEPENDS "")
set(RPM_PACKAGE_DEPENDS "")
set(CPACK_DEBIAN_PACKAGE_DEPENDS ${DEBIAN_PACKAGE_DEPENDS})
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "gazebo plugins for px4 sitl.")
set(CPACK_RPM_PACKAGE_REQUIRES "${DEBIAN_PACKAGE_DEPENDS}")
set(CPACK_RPM_PACKAGE_DESCRIPTION "Gazebo plugins for px4 sitl.")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${GAZEBO_MAJOR_VERSION}-${PROJECT_VERSION}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${GAZEBO_MAJOR_VERSION}-${PROJECT_VERSION}")
include(CPack)