Skip to content

Commit 0e5cf24

Browse files
committed
refactor: Simplify CMake configuration by removing deprecated macros and updating compiler settings
1 parent 433071d commit 0e5cf24

File tree

2 files changed

+55
-88
lines changed

2 files changed

+55
-88
lines changed

CMakeLists.txt

Lines changed: 55 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,30 @@
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)
65
project(dynamixel_hardware_interface)
76

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()
7514

15+
################################################################################
16+
# Find and load build settings from external packages
17+
################################################################################
7618
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)
8028

8129
################################################################################
8230
# Build
@@ -88,37 +36,47 @@ add_library(
8836
src/dynamixel/dynamixel_info.cpp
8937
src/dynamixel/dynamixel.cpp
9038
)
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
9343
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
9444
$<INSTALL_INTERFACE:include/dynamixel_hardware_interface>
9545
${dynamixel_sdk_INCLUDE_DIRS}
46+
${hardware_interface_INCLUDE_DIRS}
47+
${realtime_tools_INCLUDE_DIRS}
48+
${rclcpp_lifecycle_INCLUDE_DIRS}
9649
)
9750

98-
target_link_libraries(${PROJECT_NAME} PUBLIC
51+
target_link_libraries(${PROJECT_NAME}
52+
PUBLIC
9953
${hardware_interface_TARGETS}
10054
pluginlib::pluginlib
10155
rclcpp::rclcpp
10256
rclcpp_lifecycle::rclcpp_lifecycle
103-
realtime_tools::realtime_tools
10457
${dynamixel_sdk_LIBRARIES}
10558
${std_srvs_TARGETS}
10659
${dynamixel_interfaces_TARGETS}
60+
${realtime_tools_TARGETS}
10761
)
10862

10963
pluginlib_export_plugin_description_file(hardware_interface dynamixel_hardware_interface_plugin.xml)
11064

111-
install(
112-
DIRECTORY include/
113-
DESTINATION include/dynamixel_hardware_interface
114-
)
65+
################################################################################
66+
# Install
67+
################################################################################
11568
install(TARGETS ${PROJECT_NAME}
11669
EXPORT export_${PROJECT_NAME}
11770
ARCHIVE DESTINATION lib
11871
LIBRARY DESTINATION lib
11972
RUNTIME DESTINATION bin
12073
)
12174

75+
install(
76+
DIRECTORY include/
77+
DESTINATION include/dynamixel_hardware_interface
78+
)
79+
12280
install(PROGRAMS
12381
scripts/create_udev_rules
12482
DESTINATION lib/${PROJECT_NAME}/
@@ -138,6 +96,19 @@ if(BUILD_TESTING)
13896
ament_lint_auto_find_test_dependencies()
13997
endif()
14098

99+
################################################################################
100+
# Macro for ament package
101+
################################################################################
102+
ament_export_include_directories(include)
103+
ament_export_libraries(${PROJECT_NAME})
141104
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+
143114
ament_package()

NOTICE

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)