Skip to content

Commit a86617b

Browse files
authored
WIP: Fix dependencies (#704)
* Fixing build process so dependencies are correctly exported.
1 parent 6e902d7 commit a86617b

File tree

5 files changed

+146
-120
lines changed

5 files changed

+146
-120
lines changed

swri_roscpp/CMakeLists.txt

+55-118
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@ cmake_minimum_required(VERSION 3.10)
22

33
project(swri_roscpp)
44

5-
set(CMAKE_CXX_STANDARD 14)
5+
# Default to C++ version appropriate for the ROS distribution
6+
if(NOT CMAKE_CXX_STANDARD)
7+
if ("$ENV{ROS_DISTRO}" STRGREATER "foxy")
8+
set(CMAKE_CXX_STANDARD 17)
9+
else()
10+
set(CMAKE_CXX_STANDARD 14)
11+
endif()
12+
endif()
13+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
14+
add_compile_options(-Wall -Wextra -Wpedantic)
15+
endif()
616

717
find_package(ament_cmake REQUIRED)
818
find_package(diagnostic_updater REQUIRED)
@@ -14,131 +24,62 @@ find_package(rosidl_default_generators REQUIRED)
1424
find_package(std_msgs REQUIRED)
1525
find_package(std_srvs REQUIRED)
1626

17-
# TODO pjr What to do about swri_roscpp-extras.cmake?
18-
add_library(${PROJECT_NAME} INTERFACE)
27+
# How we build header only libraries changed in Humble
28+
if("$ENV{ROS_DISTRO}" STRGREATER "galactic")
29+
add_library(${PROJECT_NAME}_library INTERFACE)
1930

20-
target_include_directories(${PROJECT_NAME} INTERFACE
21-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
22-
"$<INSTALL_INTERFACE:include>"
23-
)
31+
target_link_libraries(${PROJECT_NAME}_library INTERFACE
32+
${diagnostic_updater_LIBRARIES}
33+
${rclcpp_LIBRARIES}
34+
${std_msgs_LIBRARIES}
35+
)
36+
target_include_directories(${PROJECT_NAME}_library INTERFACE
37+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
38+
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
39+
${diagnostic_updater_INCLUDE_DIRS}
40+
${rclcpp_INCLUDE_DIRS}
41+
${std_msgs_INCLUDE_DIRS}
42+
)
43+
44+
install(DIRECTORY include/
45+
DESTINATION include/${PROJECT_NAME}
46+
)
47+
install(TARGETS ${PROJECT_NAME}_library
48+
EXPORT export_${PROJECT_NAME}
49+
)
2450

25-
install(TARGETS ${PROJECT_NAME}
26-
EXPORT "export_${PROJECT_NAME}"
27-
ARCHIVE DESTINATION lib
28-
LIBRARY DESTINATION lib
29-
RUNTIME DESTINATION lib
30-
INCLUDES DESTINATION include
31-
)
51+
# Export old-style CMake variables
52+
ament_export_include_directories("include/${PROJECT_NAME}")
3253

33-
install(DIRECTORY include/${PROJECT_NAME}/
34-
DESTINATION include/${PROJECT_NAME}
35-
)
54+
# Export modern CMake targets
55+
ament_export_targets(export_${PROJECT_NAME})
3656

37-
ament_export_targets("export_${PROJECT_NAME}")
57+
# Only test on Humble or newer until https://github.com/ros2/rosidl/pull/639 is merged
58+
include(cmake/swri_roscpp-test.cmake)
59+
else()
60+
install(DIRECTORY include/${PROJECT_NAME}/
61+
DESTINATION include/${PROJECT_NAME}
62+
)
63+
ament_export_include_directories(include)
64+
endif()
3865

39-
# ### Build Test Node ###
4066
add_executable(subscriber_test src/nodes/subscriber_test.cpp)
4167
target_include_directories(subscriber_test
4268
PUBLIC
4369
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
4470
$<INSTALL_INTERFACE:include>
71+
${diagnostic_updater_INCLUDE_DIRS}
72+
${nav_msgs_INCLUDE_DIRS}
73+
${rclcpp_INCLUDE_DIRS}
4574
)
46-
ament_target_dependencies(subscriber_test
47-
diagnostic_updater
48-
marti_common_msgs
49-
nav_msgs
50-
rclcpp
51-
std_msgs
52-
std_srvs
53-
)
54-
55-
add_executable(storing_subscriber_test src/nodes/storing_subscriber_test.cpp)
56-
target_include_directories(storing_subscriber_test
57-
PUBLIC
58-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
59-
$<INSTALL_INTERFACE:include>
75+
target_link_libraries(subscriber_test
76+
${diagnostic_updater_LIBRARIES}
77+
${marti_common_msgs_LIBRARIES}
78+
${nav_msgs_LIBRARIES}
79+
${rclcpp_LIBRARIES}
80+
${std_msgs_LIBRARIES}
81+
${std_srvs_LIBRARIES}
6082
)
61-
ament_target_dependencies(storing_subscriber_test
62-
diagnostic_updater
63-
marti_common_msgs
64-
nav_msgs
65-
rclcpp
66-
std_msgs
67-
std_srvs
68-
)
69-
70-
add_executable(service_server_test src/nodes/service_server_test.cpp)
71-
target_include_directories(service_server_test
72-
PUBLIC
73-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
74-
$<INSTALL_INTERFACE:include>
75-
)
76-
ament_target_dependencies(service_server_test
77-
diagnostic_updater
78-
marti_common_msgs
79-
nav_msgs
80-
rclcpp
81-
std_msgs
82-
std_srvs
83-
)
84-
85-
add_executable(timer_test src/nodes/timer_test.cpp)
86-
target_include_directories(timer_test
87-
PUBLIC
88-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
89-
$<INSTALL_INTERFACE:include>
90-
)
91-
ament_target_dependencies(timer_test
92-
diagnostic_updater
93-
marti_common_msgs
94-
nav_msgs
95-
rclcpp
96-
std_msgs
97-
std_srvs
98-
)
99-
100-
# Disabling Foxy and Galactic tests until https://github.com/ros2/rosidl/pull/639 is merged
101-
if (BUILD_TESTING AND ("$ENV{ROS_DISTRO}" STRGREATER "galactic"))
102-
find_package(ament_cmake_gtest REQUIRED)
103-
find_package(Boost REQUIRED COMPONENTS system)
104-
105-
rosidl_generate_interfaces(${PROJECT_NAME}_test
106-
msg/TestTopicServiceRequest.msg
107-
msg/TestTopicServiceResponse.msg
108-
DEPENDENCIES std_msgs marti_common_msgs
109-
LIBRARY_NAME ${PROJECT_NAME}
110-
)
111-
112-
ament_add_gtest(topic_service_test_server test/topic_service_test.cpp)
113-
114-
# Humble and onwards
115-
if ("$ENV{ROS_DISTRO}" STRGREATER "galactic")
116-
rosidl_get_typesupport_target(cpp_typesupport_target "${PROJECT_NAME}_test" "rosidl_typesupport_cpp")
117-
target_link_libraries(topic_service_test_server
118-
Boost::system
119-
"${cpp_typesupport_target}"
120-
)
121-
else()
122-
rosidl_target_interfaces(topic_service_test_server "${PROJECT_NAME}_test" "rosidl_typesupport_cpp")
123-
target_link_libraries(topic_service_test_server
124-
Boost::system
125-
swri_roscpp_test__rosidl_typesupport_cpp
126-
)
127-
endif()
128-
129-
ament_target_dependencies(topic_service_test_server
130-
rclcpp
131-
marti_common_msgs
132-
)
133-
target_include_directories(topic_service_test_server
134-
PUBLIC
135-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
136-
$<INSTALL_INTERFACE:include>
137-
)
138-
139-
ament_export_dependencies(rosidl_default_runtime)
140-
endif()
141-
14283
### Install Test Node and Headers ###
14384
install(TARGETS subscriber_test
14485
ARCHIVE DESTINATION lib
@@ -148,9 +89,6 @@ install(TARGETS subscriber_test
14889
install(PROGRAMS scripts/service_splitter.py
14990
DESTINATION bin
15091
)
151-
install(DIRECTORY include/
152-
DESTINATION include
153-
)
15492
install(DIRECTORY launch/
15593
DESTINATION launch
15694
)
@@ -162,6 +100,5 @@ ament_export_dependencies(nav_msgs)
162100
ament_export_dependencies(rclcpp)
163101
ament_export_dependencies(std_msgs)
164102
ament_export_dependencies(std_srvs)
165-
ament_export_include_directories(include)
166103

167104
ament_package(CONFIG_EXTRAS cmake/swri_roscpp-extras.cmake )
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
if(BUILD_TESTING)
2+
find_package(ament_cmake_gtest REQUIRED)
3+
find_package(Boost REQUIRED COMPONENTS system)
4+
## Storing subscriber test case
5+
add_executable(storing_subscriber_test src/nodes/storing_subscriber_test.cpp)
6+
target_include_directories(storing_subscriber_test
7+
PUBLIC
8+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
9+
$<INSTALL_INTERFACE:include>
10+
${diagnostic_updater_INCLUDE_DIRS}
11+
${nav_msgs_INCLUDE_DIRS}
12+
${rclcpp_INCLUDE_DIRS}
13+
)
14+
target_link_libraries(storing_subscriber_test
15+
${diagnostic_updater_LIBRARIES}
16+
${marti_common_msgs_LIBRARIES}
17+
${nav_msgs_LIBRARIES}
18+
${rclcpp_LIBRARIES}
19+
${std_msgs_LIBRARIES}
20+
${std_srvs_LIBRARIES}
21+
)
22+
23+
## Service server test
24+
add_executable(service_server_test src/nodes/service_server_test.cpp)
25+
target_include_directories(service_server_test
26+
PUBLIC
27+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
28+
$<INSTALL_INTERFACE:include>
29+
${diagnostic_updater_INCLUDE_DIRS}
30+
${rclcpp_INCLUDE_DIRS}
31+
${std_srvs_INCLUDE_DIRS}
32+
)
33+
target_link_libraries(service_server_test
34+
${diagnostic_updater_LIBRARIES}
35+
${marti_common_msgs_LIBRARIES}
36+
${nav_msgs_LIBRARIES}
37+
${rclcpp_LIBRARIES}
38+
${std_msgs_LIBRARIES}
39+
${std_srvs_LIBRARIES}
40+
)
41+
42+
## Timer test
43+
add_executable(timer_test src/nodes/timer_test.cpp)
44+
target_include_directories(timer_test
45+
PUBLIC
46+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
47+
$<INSTALL_INTERFACE:include>
48+
${diagnostic_updater_INCLUDE_DIRS}
49+
${rclcpp_INCLUDE_DIRS}
50+
)
51+
target_link_libraries(timer_test
52+
${diagnostic_updater_LIBRARIES}
53+
${marti_common_msgs_LIBRARIES}
54+
${nav_msgs_LIBRARIES}
55+
${rclcpp_LIBRARIES}
56+
${std_msgs_LIBRARIES}
57+
${std_srvs_LIBRARIES}
58+
)
59+
60+
rosidl_generate_interfaces(${PROJECT_NAME}_test
61+
msg/TestTopicServiceRequest.msg
62+
msg/TestTopicServiceResponse.msg
63+
DEPENDENCIES std_msgs marti_common_msgs
64+
LIBRARY_NAME ${PROJECT_NAME}
65+
)
66+
ament_add_gtest(topic_service_test_server test/topic_service_test.cpp)
67+
rosidl_get_typesupport_target(cpp_typesupport_target "${PROJECT_NAME}_test" "rosidl_typesupport_cpp")
68+
target_link_libraries(topic_service_test_server
69+
Boost::system
70+
"${cpp_typesupport_target}"
71+
)
72+
target_link_libraries(topic_service_test_server
73+
${rclcpp_LIBRARIES}
74+
${marti_common_msgs_LIBRARIES}
75+
)
76+
target_include_directories(topic_service_test_server
77+
PUBLIC
78+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
79+
$<INSTALL_INTERFACE:include>
80+
${rclcpp_INCLUDE_DIRS}
81+
${marti_common_msgs_INCLUDE_DIRS}
82+
)
83+
84+
ament_export_dependencies(rosidl_default_runtime)
85+
endif()

swri_roscpp/src/nodes/service_server_test.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class ServiceServerTest : public rclcpp::Node
8989
bool handleService1(const std::shared_ptr<std_srvs::srv::Empty::Request>& req,
9090
const std::shared_ptr<std_srvs::srv::Empty::Response>& res)
9191
{
92+
(void)req;
93+
(void)res;
9294
RCLCPP_INFO(this->get_logger(), "test service 1 called. returning %s",
9395
test1_result_ ? "true" : "false");
9496
return test1_result_;

swri_roscpp/src/nodes/subscriber_test.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ class SubscriberTest : public rclcpp::Node
9292

9393
void handleMessage(const nav_msgs::msg::Odometry::ConstSharedPtr &msg)
9494
{
95-
RCLCPP_INFO_ONCE(this->get_logger(), "Receiving messages.");
95+
// Suppresses unused parameter warning
96+
(void)msg;
97+
RCLCPP_INFO_ONCE(this->get_logger(), "Receiving messages");
9698
}
9799

98100
void handleDiagnosticsTimer()

swri_transform_util/package.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<depend>geographic_msgs</depend>
2424
<depend>geometry_msgs</depend>
2525
<depend>gps_msgs</depend>
26-
<depend>libgeos++-dev</depend>
26+
<depend>geos</depend>
2727
<depend>marti_nav_msgs</depend>
2828
<depend>proj</depend>
2929
<depend>rclcpp_components</depend>

0 commit comments

Comments
 (0)