|
| 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 | + |
1 | 5 | cmake_minimum_required(VERSION 3.16)
|
2 | 6 | project(dynamixel_hardware_interface)
|
3 | 7 |
|
4 |
| -find_package(ros2_control_cmake REQUIRED) |
| 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 | + |
5 | 62 | set_compiler_options()
|
6 | 63 | export_windows_symbols()
|
7 | 64 |
|
|
0 commit comments