Skip to content

Commit d3ad9e0

Browse files
tylerjwmamueluth
authored andcommitted
Fix CMake install so overriding works (ros-controls#926)
Signed-off-by: Tyler Weaver <[email protected]>
1 parent 7cea8da commit d3ad9e0

File tree

10 files changed

+322
-366
lines changed

10 files changed

+322
-366
lines changed
Lines changed: 52 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,88 @@
1-
cmake_minimum_required(VERSION 3.5)
2-
project(controller_interface)
1+
cmake_minimum_required(VERSION 3.16)
2+
project(controller_interface LANGUAGES CXX)
33

4-
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
4+
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
55
add_compile_options(-Wall -Wextra)
66
endif()
77

8+
set(THIS_PACKAGE_INCLUDE_DEPENDS
9+
hardware_interface
10+
rclcpp_lifecycle
11+
)
12+
813
find_package(ament_cmake REQUIRED)
9-
find_package(hardware_interface REQUIRED)
10-
find_package(rclcpp_lifecycle REQUIRED)
14+
foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
15+
find_package(${Dependency} REQUIRED)
16+
endforeach()
1117

12-
add_library(
13-
${PROJECT_NAME}
14-
SHARED
18+
add_library(controller_interface SHARED
1519
src/controller_interface_base.cpp
1620
src/controller_interface.cpp
1721
src/chainable_controller_interface.cpp
1822
)
19-
target_include_directories(
20-
${PROJECT_NAME}
21-
PRIVATE
22-
include
23-
)
24-
ament_target_dependencies(
25-
${PROJECT_NAME}
26-
hardware_interface
27-
rclcpp_lifecycle
23+
target_compile_features(controller_interface PUBLIC cxx_std_17)
24+
target_include_directories(controller_interface PUBLIC
25+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
26+
$<INSTALL_INTERFACE:include/controller_interface>
2827
)
28+
ament_target_dependencies(controller_interface PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS})
2929
# Causes the visibility macros to use dllexport rather than dllimport,
3030
# which is appropriate when building the dll but not consuming it.
31-
target_compile_definitions(${PROJECT_NAME} PRIVATE "CONTROLLER_INTERFACE_BUILDING_DLL")
32-
33-
install(DIRECTORY include/
34-
DESTINATION include
35-
)
36-
install(TARGETS ${PROJECT_NAME}
37-
ARCHIVE DESTINATION lib
38-
LIBRARY DESTINATION lib
39-
RUNTIME DESTINATION bin
40-
)
31+
target_compile_definitions(controller_interface PRIVATE "CONTROLLER_INTERFACE_BUILDING_DLL")
4132

4233
if(BUILD_TESTING)
4334
find_package(ament_cmake_gmock REQUIRED)
44-
45-
find_package(hardware_interface REQUIRED)
4635
find_package(sensor_msgs REQUIRED)
4736

4837
ament_add_gmock(test_controller_interface test/test_controller_interface.cpp)
49-
target_link_libraries(test_controller_interface ${PROJECT_NAME})
50-
target_include_directories(test_controller_interface PRIVATE include)
38+
target_link_libraries(test_controller_interface
39+
controller_interface
40+
)
5141

5242
ament_add_gmock(test_controller_with_options test/test_controller_with_options.cpp)
53-
target_link_libraries(test_controller_with_options ${PROJECT_NAME})
54-
target_include_directories(test_controller_with_options PRIVATE include)
43+
target_link_libraries(test_controller_with_options
44+
controller_interface
45+
)
5546

5647
ament_add_gmock(test_chainable_controller_interface test/test_chainable_controller_interface.cpp)
57-
target_link_libraries(test_chainable_controller_interface ${PROJECT_NAME})
58-
target_include_directories(test_chainable_controller_interface PRIVATE include)
59-
ament_target_dependencies(test_chainable_controller_interface hardware_interface)
60-
61-
ament_add_gmock(
62-
test_semantic_component_interface
63-
test/test_semantic_component_interface.cpp
64-
)
65-
target_include_directories(test_semantic_component_interface PRIVATE include)
66-
ament_target_dependencies(
67-
test_semantic_component_interface
68-
hardware_interface
48+
target_link_libraries(test_chainable_controller_interface
49+
controller_interface
50+
hardware_interface::hardware_interface
6951
)
7052

71-
ament_add_gmock(
72-
test_force_torque_sensor
73-
test/test_force_torque_sensor.cpp
53+
ament_add_gmock(test_semantic_component_interface test/test_semantic_component_interface.cpp)
54+
target_link_libraries(test_semantic_component_interface
55+
controller_interface
56+
hardware_interface::hardware_interface
7457
)
75-
target_include_directories(test_force_torque_sensor PRIVATE include)
76-
ament_target_dependencies(
77-
test_force_torque_sensor
78-
hardware_interface
58+
59+
ament_add_gmock(test_force_torque_sensor test/test_force_torque_sensor.cpp)
60+
target_link_libraries(test_force_torque_sensor
61+
controller_interface
62+
hardware_interface::hardware_interface
7963
)
8064

81-
ament_add_gmock(
82-
test_imu_sensor
83-
test/test_imu_sensor.cpp
65+
ament_add_gmock(test_imu_sensor test/test_imu_sensor.cpp)
66+
target_link_libraries(test_imu_sensor
67+
controller_interface
68+
hardware_interface::hardware_interface
8469
)
85-
target_include_directories(test_imu_sensor PRIVATE include)
86-
ament_target_dependencies(
87-
test_imu_sensor
88-
hardware_interface
70+
ament_target_dependencies(test_imu_sensor
8971
sensor_msgs
9072
)
9173
endif()
9274

93-
ament_export_dependencies(
94-
hardware_interface
95-
rclcpp_lifecycle
96-
sensor_msgs
97-
)
98-
ament_export_include_directories(
99-
include
75+
install(
76+
DIRECTORY include/
77+
DESTINATION include/controller_interface
10078
)
101-
ament_export_libraries(
102-
${PROJECT_NAME}
79+
install(TARGETS controller_interface
80+
EXPORT export_controller_interface
81+
ARCHIVE DESTINATION lib
82+
LIBRARY DESTINATION lib
83+
RUNTIME DESTINATION bin
10384
)
85+
86+
ament_export_targets(export_controller_interface HAS_LIBRARY_TARGET)
87+
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
10488
ament_package()

controller_interface/package.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@
1414
<build_depend>rclcpp_lifecycle</build_depend>
1515
<build_depend>sensor_msgs</build_depend>
1616

17-
<exec_depend>hardware_interface</exec_depend>
18-
<exec_depend>rclcpp_lifecycle</exec_depend>
19-
<exec_depend>sensor_msgs</exec_depend>
20-
2117
<test_depend>ament_cmake_gmock</test_depend>
18+
<test_depend>sensor_msgs</test_depend>
2219

2320
<export>
2421
<build_type>ament_cmake</build_type>

0 commit comments

Comments
 (0)