1
- # Portions of this file are derived from ros2_control_cmake (Apache 2.0 License)
2
- # Copyright 2025 AIT - Austrian Institute of Technology GmbH
3
- # See the LICENSE file for details.
4
-
5
- cmake_minimum_required (VERSION 3.16)
1
+ ################################################################################
2
+ # Set minimum required version of cmake, project name and compile options
3
+ ################################################################################
4
+ cmake_minimum_required (VERSION 3.5)
6
5
project (dynamixel_hardware_interface)
7
6
8
- # ==== Begin inlined content from ros2_control_cmake/cmake/ros2_control.cmake ====
9
- # Macro to extract GCC_MAJOR_VERSION and GCC_MINOR_VERSION
10
- macro (extract_gcc_version)
11
- if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
12
- string (REPLACE "." ";" VERSION_LIST ${CMAKE_CXX_COMPILER_VERSION} )
13
- list (GET VERSION_LIST 0 GCC_MAJOR_VERSION)
14
- list (GET VERSION_LIST 1 GCC_MINOR_VERSION)
15
-
16
- message (STATUS "Detected GCC Version: ${CMAKE_CXX_COMPILER_VERSION} (Major: ${GCC_MAJOR_VERSION} , Minor: ${GCC_MINOR_VERSION} )" )
17
-
18
- # Convert to a number to avoid string comparison issues
19
- if (GCC_MAJOR_VERSION MATCHES "^[0-9]+$" )
20
- math (EXPR GCC_MAJOR_VERSION "${GCC_MAJOR_VERSION} " )
21
- endif ()
22
- if (GCC_MINOR_VERSION MATCHES "^[0-9]+$" )
23
- math (EXPR GCC_MINOR_VERSION "${GCC_MINOR_VERSION} " )
24
- endif ()
25
- endif ()
26
- endmacro ()
27
-
28
- # set compiler options depending on detected compiler
29
- macro (set_compiler_options)
30
- if (CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)" )
31
- add_compile_options (-Wall -Wextra -Wpedantic -Werror=conversion -Werror=unused-but-set-variable
32
- -Werror=return-type -Werror=shadow -Werror=format
33
- -Werror=missing-braces)
34
- message (STATUS "Compiler warnings enabled for ${CMAKE_CXX_COMPILER_ID} " )
35
-
36
- # https://docs.ros.org/en/rolling/How-To-Guides/Ament-CMake-Documentation.html#compiler-and-linker-options
37
- if (NOT CMAKE_C_STANDARD)
38
- set (CMAKE_C_STANDARD 99)
39
- endif ()
40
- if (NOT CMAKE_CXX_STANDARD)
41
- set (CMAKE_CXX_STANDARD 17)
42
- endif ()
43
-
44
- # Extract major version if g++ is used
45
- if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
46
- extract_gcc_version()
47
- if (DEFINED GCC_MAJOR_VERSION AND GCC_MAJOR_VERSION GREATER 10)
48
- # GCC 11 introduced -Werror=range-loop-construct
49
- add_compile_options (-Werror=range-loop-construct)
50
- endif ()
51
- endif ()
52
- endif ()
53
- endmacro ()
54
-
55
- # using this instead of visibility macros
56
- # S1 from https://github.com/ros-controls/ros2_controllers/issues/1053
57
- macro (export_windows_symbols)
58
- set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON )
59
- endmacro ()
60
- # ==== End inlined content from ros2_control_cmake/cmake/ros2_control.cmake ====
61
-
62
- set_compiler_options()
63
- export_windows_symbols()
64
-
65
- set (THIS_PACKAGE_INCLUDE_DEPENDS
66
- hardware_interface
67
- rclcpp
68
- rclcpp_lifecycle
69
- pluginlib
70
- realtime_tools
71
- dynamixel_sdk
72
- std_srvs
73
- dynamixel_interfaces
74
- )
7
+ if (NOT CMAKE_CXX_STANDARD)
8
+ set (CMAKE_CXX_STANDARD 14)
9
+ endif ()
10
+
11
+ if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
12
+ add_compile_options (-Wall -Wextra -Wpedantic)
13
+ endif ()
75
14
15
+ ################################################################################
16
+ # Find and load build settings from external packages
17
+ ################################################################################
76
18
find_package (ament_cmake REQUIRED)
77
- foreach (Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS} )
78
- find_package (${Dependency} REQUIRED)
79
- endforeach ()
19
+ find_package (hardware_interface REQUIRED)
20
+ find_package (rclcpp REQUIRED)
21
+ find_package (rclcpp_lifecycle REQUIRED)
22
+ find_package (pluginlib REQUIRED)
23
+ find_package (realtime_tools REQUIRED)
24
+
25
+ find_package (dynamixel_sdk REQUIRED)
26
+ find_package (std_srvs REQUIRED)
27
+ find_package (dynamixel_interfaces REQUIRED)
80
28
81
29
################################################################################
82
30
# Build
@@ -88,37 +36,47 @@ add_library(
88
36
src/dynamixel/dynamixel_info.cpp
89
37
src/dynamixel/dynamixel.cpp
90
38
)
91
- target_compile_features (${PROJECT_NAME} PUBLIC cxx_std_17)
92
- target_include_directories (${PROJECT_NAME} PUBLIC
39
+
40
+ target_include_directories (
41
+ ${PROJECT_NAME}
42
+ PUBLIC
93
43
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} /include >
94
44
$<INSTALL_INTERFACE:include /dynamixel_hardware_interface>
95
45
${dynamixel_sdk_INCLUDE_DIRS}
46
+ ${hardware_interface_INCLUDE_DIRS}
47
+ ${realtime_tools_INCLUDE_DIRS}
48
+ ${rclcpp_lifecycle_INCLUDE_DIRS}
96
49
)
97
50
98
- target_link_libraries (${PROJECT_NAME} PUBLIC
51
+ target_link_libraries (${PROJECT_NAME}
52
+ PUBLIC
99
53
${hardware_interface_TARGETS}
100
54
pluginlib::pluginlib
101
55
rclcpp::rclcpp
102
56
rclcpp_lifecycle::rclcpp_lifecycle
103
- realtime_tools::realtime_tools
104
57
${dynamixel_sdk_LIBRARIES}
105
58
${std_srvs_TARGETS}
106
59
${dynamixel_interfaces_TARGETS}
60
+ ${realtime_tools_TARGETS}
107
61
)
108
62
109
63
pluginlib_export_plugin_description_file(hardware_interface dynamixel_hardware_interface_plugin.xml)
110
64
111
- install (
112
- DIRECTORY include /
113
- DESTINATION include /dynamixel_hardware_interface
114
- )
65
+ ################################################################################
66
+ # Install
67
+ ################################################################################
115
68
install (TARGETS ${PROJECT_NAME}
116
69
EXPORT export_${PROJECT_NAME}
117
70
ARCHIVE DESTINATION lib
118
71
LIBRARY DESTINATION lib
119
72
RUNTIME DESTINATION bin
120
73
)
121
74
75
+ install (
76
+ DIRECTORY include /
77
+ DESTINATION include /dynamixel_hardware_interface
78
+ )
79
+
122
80
install (PROGRAMS
123
81
scripts/create_udev_rules
124
82
DESTINATION lib/${PROJECT_NAME} /
@@ -138,6 +96,19 @@ if(BUILD_TESTING)
138
96
ament_lint_auto_find_test_dependencies()
139
97
endif ()
140
98
99
+ ################################################################################
100
+ # Macro for ament package
101
+ ################################################################################
102
+ ament_export_include_directories(include )
103
+ ament_export_libraries(${PROJECT_NAME} )
141
104
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
142
- ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS} )
105
+ ament_export_dependencies(
106
+ rclcpp
107
+ rclcpp_lifecycle
108
+ hardware_interface
109
+ pluginlib
110
+ dynamixel_sdk
111
+ dynamixel_interfaces
112
+ )
113
+
143
114
ament_package()
0 commit comments