forked from PX4/px4_ros_com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
159 lines (132 loc) · 4.61 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
cmake_minimum_required(VERSION 3.5)
project(px4_ros_com)
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(EnableC++XX)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
endif()
# Check if any sanitizers set
include(EnableSanitizers)
# Check if ROS_DISTRO is greater or equal to Dashing
# Required since
# - "create_subscription()" and "create_publisher()" APIs changed
# - eigen3_cmake_module is only available in these distros
list(APPEND ROS_DISTROS "dashing" "eloquent" "foxy" "galactic" "rolling")
set(ROS_DISTRO)
if(DEFINED ENV{ROS2_DISTRO})
set(ROS_DISTRO $ENV{ROS2_DISTRO})
if(${ROS_DISTRO} IN_LIST ROS_DISTROS)
add_definitions(-DROS_DEFAULT_API=1)
endif()
elseif(DEFINED ENV{ROS_DISTRO})
set(ROS_DISTRO $ENV{ROS_DISTRO})
if(${ROS_DISTRO} IN_LIST ROS_DISTROS)
add_definitions(-DROS_DEFAULT_API=1)
endif()
else()
message(FATAL_ERROR "No ROS Distro set")
endif()
set(USES_DEPRECATED_EXPORT_API "ardent" "bouncy" "crystal" "dashing" "eloquent")
find_package(ament_cmake REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(fastcdr REQUIRED)
find_package(fastrtps REQUIRED)
find_package(rclcpp REQUIRED)
get_default_rmw_implementation(rmw_implementation)
find_package("${rmw_implementation}" REQUIRED)
find_package(px4_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(PythonInterp 3 REQUIRED)
if(ROS_DISTRO IN_LIST ROS_DISTROS)
find_package(eigen3_cmake_module REQUIRED)
endif()
find_package(Eigen3 REQUIRED NO_MODULE)
###################################
# Generate micro-RTPS agent code ##
###################################
get_filename_component(PX4_MSGS_DIR "../" ABSOLUTE BASE_DIR ${px4_msgs_DIR})
set(MSGS_DIR "${PX4_MSGS_DIR}/msg" CACHE INTERNAL "MSGS_DIR")
include(GenerateMicroRTPSAgent)
#################
# Setup targets #
#################
include_directories(include)
function(custom_executable subfolder target)
add_executable(${target} src/${subfolder}/${target}.cpp)
ament_target_dependencies(${target}
rclcpp
px4_msgs
)
install(TARGETS ${target}
DESTINATION lib/${PROJECT_NAME})
endfunction()
# Add frame_transforms lib
add_library(frame_transforms SHARED src/lib/frame_transforms.cpp)
ament_target_dependencies(frame_transforms Eigen3 geometry_msgs sensor_msgs)
target_include_directories(frame_transforms PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
${Eigen3_INCLUDE_DIRS}
)
target_link_libraries(frame_transforms Eigen3::Eigen ${geometry_msgs_LIBRARIES} ${sensor_msgs_LIBRARIES})
# Add microRTPS agent
add_executable(micrortps_agent ${MICRORTPS_AGENT_FILES})
ament_target_dependencies(micrortps_agent fastcdr fastrtps rclcpp)
target_link_libraries(micrortps_agent fastcdr fastrtps ${rclcpp_LIBRARIES})
# Add examples
custom_executable(examples/listeners sensor_combined_listener)
custom_executable(examples/listeners vehicle_gps_position_listener)
custom_executable(examples/advertisers debug_vect_advertiser)
custom_executable(examples/offboard offboard_control)
############
# Install ##
############
# Export information to downstream packages
if(ROS_DISTRO IN_LIST ROS_DISTROS)
ament_export_dependencies(ament_cmake rclcpp rosidl_default_runtime eigen3_cmake_module Eigen3 px4_msgs geometry_msgs sensor_msgs)
else()
ament_export_dependencies(ament_cmake rclcpp rosidl_default_runtime Eigen3 px4_msgs geometry_msgs sensor_msgs)
endif()
if (ROS_DISTRO IN_LIST USES_DEPRECATED_EXPORT_API)
ament_export_interfaces(export_frame_transforms HAS_LIBRARY_TARGET)
else()
ament_export_targets(export_frame_transforms HAS_LIBRARY_TARGET)
endif()
ament_export_include_directories(include)
ament_export_libraries(frame_transforms)
# Install header files
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION include/${PROJECT_NAME}
)
# Install artifacts
install(DIRECTORY cmake
DESTINATION share/${PROJECT_NAME}
)
install(TARGETS frame_transforms
EXPORT export_frame_transforms
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
install(TARGETS micrortps_agent
ARCHIVE DESTINATION lib/${PROJECT_NAME}
LIBRARY DESTINATION lib/${PROJECT_NAME}
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
# Install launch files
install(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME}
)
############
# Testing ##
############
# Install tests
install(DIRECTORY
test
DESTINATION share/${PROJECT_NAME}
)
ament_package()