1- cmake_minimum_required (VERSION 3.20 )
1+ cmake_minimum_required (VERSION 3.12 )
22
33project (rcutils)
44
5+ option (RCUTILS_NO_THREAD_SUPPORT "Disable thread support." OFF )
6+ option (RCUTILS_NO_FILESYSTEM "Disable filesystem usage." OFF )
7+ option (RCUTILS_AVOID_DYNAMIC_ALLOCATION "Disable dynamic allocations." OFF )
8+ option (RCUTILS_NO_64_ATOMIC "Enable alternative support for 64 bits atomic operations in platforms with no native support." OFF )
9+ option (RCUTILS_MICROROS "Flag for building micro-ROS." ON )
10+
511# Default to C11
612if (NOT CMAKE_C_STANDARD )
713 set (CMAKE_C_STANDARD 11)
@@ -16,21 +22,6 @@ include(CheckLibraryExists)
1622find_package (ament_cmake_python REQUIRED )
1723find_package (ament_cmake_ros REQUIRED )
1824
19- # By default, without the settings below, find_package(Python3) will attempt
20- # to find the newest python version it can, and additionally will find the
21- # most specific version. For instance, on a system that has
22- # /usr/bin/python3.10, /usr/bin/python3.11, and /usr/bin/python3, it will find
23- # /usr/bin/python3.11, even if /usr/bin/python3 points to /usr/bin/python3.10.
24- # The behavior we want is to prefer the "system" installed version unless the
25- # user specifically tells us othewise through the Python3_EXECUTABLE hint.
26- # Setting CMP0094 to NEW means that the search will stop after the first
27- # python version is found. Setting Python3_FIND_UNVERSIONED_NAMES means that
28- # the search will prefer /usr/bin/python3 over /usr/bin/python3.11. And that
29- # latter functionality is only available in CMake 3.20 or later, so we need
30- # at least that version.
31- cmake_policy (SET CMP0094 NEW )
32- set (Python3_FIND_UNVERSIONED_NAMES FIRST)
33-
3425find_package (Python3 REQUIRED COMPONENTS Interpreter )
3526
3627ament_python_install_package (${PROJECT_NAME } )
@@ -45,7 +36,7 @@ if(UNIX AND NOT APPLE)
4536 endif ()
4637endif ()
4738
48- if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
39+ if (NOT RCUTILS_MICROROS AND ( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) )
4940 # enables building a static library but later link it into a dynamic library
5041 add_compile_options (-fPIC )
5142endif ()
@@ -91,6 +82,7 @@ set(rcutils_sources
9182 src/time.c
9283 ${time_impl_c}
9384 src/uint8_array.c
85+ $<$<BOOL :${RCUTILS_NO_64_ATOMIC} >:src /atomic_64bits .c >
9486)
9587set_source_files_properties (
9688 ${rcutils_sources}
@@ -145,8 +137,14 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE "RCUTILS_BUILDING_DLL")
145137if (BUILD_TESTING AND NOT RCUTILS_DISABLE_FAULT_INJECTION)
146138 target_compile_definitions (${PROJECT_NAME } PUBLIC RCUTILS_ENABLE_FAULT_INJECTION )
147139endif ()
140+ configure_file (
141+ "${PROJECT_SOURCE_DIR } /include/rcutils/configuration_flags.h.in"
142+ "${PROJECT_BINARY_DIR } /include/rcutils/configuration_flags.h"
143+ )
148144
149- target_link_libraries (${PROJECT_NAME } ${CMAKE_DL_LIBS } )
145+ if (NOT RCUTILS_NO_FILESYSTEM)
146+ target_link_libraries (${PROJECT_NAME } ${CMAKE_DL_LIBS } )
147+ endif ()
150148
151149check_library_exists (atomic __atomic_load_8 "" HAVE_LIBATOMICS )
152150
@@ -292,7 +290,7 @@ if(BUILD_TESTING)
292290 )
293291 if (TARGET test_error_handling_helpers)
294292 target_include_directories (test_error_handling_helpers PUBLIC include )
295- target_link_libraries (test_error_handling_helpers osrf_testing_tools_cpp::memory_tools )
293+ target_link_libraries (test_error_handling_helpers ${ PROJECT_NAME } osrf_testing_tools_cpp::memory_tools )
296294 endif ()
297295
298296 ament_add_gtest (test_split
@@ -602,7 +600,10 @@ endif()
602600
603601# Export old-style CMake variables
604602ament_export_include_directories ("include/${PROJECT_NAME } " )
605- ament_export_libraries (${PROJECT_NAME } ${CMAKE_DL_LIBS } )
603+
604+ if (NOT RCUTILS_NO_FILESYSTEM)
605+ ament_export_libraries (${PROJECT_NAME } ${CMAKE_DL_LIBS } )
606+ endif ()
606607
607608# Export modern CMake targets
608609ament_export_targets (${PROJECT_NAME } )
0 commit comments