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_NO_PROCESS_SUPPORT "Disable process support." OFF )
8+ option (RCUTILS_AVOID_DYNAMIC_ALLOCATION "Disable dynamic allocations." OFF )
9+ option (RCUTILS_NO_64_ATOMIC "Enable alternative support for 64 bits atomic operations in platforms with no native support." OFF )
10+ option (RCUTILS_MICROROS "Flag for building micro-ROS." ON )
11+
512include (CheckLibraryExists )
613
714find_package (ament_cmake REQUIRED )
@@ -17,7 +24,7 @@ if(UNIX AND NOT APPLE)
1724 endif ()
1825endif ()
1926
20- if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
27+ if (NOT RCUTILS_MICROROS AND ( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) )
2128 # enables building a static library but later link it into a dynamic library
2229 add_compile_options (-fPIC )
2330endif ()
@@ -38,7 +45,7 @@ endif()
3845set (rcutils_sources
3946 src/allocator.c
4047 src/array_list.c
41- src/base64.c
48+ $<$< NOT :$< BOOL : ${RCUTILS_MICROROS} >>: src /base64 .c >
4249 src/char_array.c
4350 src/cmdline_parser.c
4451 src/env.c
@@ -66,6 +73,7 @@ set(rcutils_sources
6673 src/time.c
6774 ${time_impl_c}
6875 src/uint8_array.c
76+ $<$<BOOL :${RCUTILS_NO_64_ATOMIC} >:src /atomic_64bits .c >
6977)
7078set_source_files_properties (
7179 ${rcutils_sources}
@@ -76,6 +84,7 @@ add_library(
7684 ${rcutils_sources} )
7785target_include_directories (${PROJECT_NAME } PUBLIC
7886 "$<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR } /include >"
87+ "$<BUILD_INTERFACE :${CMAKE_CURRENT_BINARY_DIR } /include >"
7988 "$<INSTALL_INTERFACE :include /${PROJECT_NAME } >" )
8089
8190# Causes the visibility macros to use dllexport rather than dllimport,
@@ -85,11 +94,17 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE "RCUTILS_BUILDING_DLL")
8594if (BUILD_TESTING AND NOT RCUTILS_DISABLE_FAULT_INJECTION)
8695 target_compile_definitions (${PROJECT_NAME } PUBLIC RCUTILS_ENABLE_FAULT_INJECTION )
8796endif ()
97+ configure_file (
98+ "${PROJECT_SOURCE_DIR } /include/rcutils/configuration_flags.h.in"
99+ "${PROJECT_BINARY_DIR } /include/rcutils/configuration_flags.h"
100+ )
88101
89102target_link_libraries (${PROJECT_NAME }
90- ${CMAKE_DL_LIBS }
91103 ament_cmake_ros_core::ament_ros_defaults
92104)
105+ if (NOT RCUTILS_NO_FILESYSTEM)
106+ target_link_libraries (${PROJECT_NAME } ${CMAKE_DL_LIBS } )
107+ endif ()
93108
94109check_library_exists (atomic __atomic_load_8 "" HAVE_LIBATOMICS )
95110
@@ -549,17 +564,19 @@ if(BUILD_TESTING)
549564 )
550565 endif ()
551566
552- ament_add_gtest (test_process
553- test /test_process.cpp
554- )
555- if (TARGET test_process)
556- target_link_libraries (test_process
557- ${PROJECT_NAME }
558- ament_cmake_ros_core::ament_ros_defaults
567+ if (NOT RCUTILS_NO_PROCESS_SUPPORT)
568+ ament_add_gtest (test_process
569+ test /test_process.cpp
559570 )
560- target_compile_definitions (test_process PRIVATE
561- "CMAKE_COMMAND=${CMAKE_COMMAND } " )
562- file (TOUCH "${CMAKE_CURRENT_BINARY_DIR } /file with space.txt" )
571+ if (TARGET test_process)
572+ target_link_libraries (test_process
573+ ${PROJECT_NAME }
574+ ament_cmake_ros_core::ament_ros_defaults
575+ )
576+ target_compile_definitions (test_process PRIVATE
577+ "CMAKE_COMMAND=${CMAKE_COMMAND } " )
578+ file (TOUCH "${CMAKE_CURRENT_BINARY_DIR } /file with space.txt" )
579+ endif ()
563580 endif ()
564581
565582 ament_add_gtest (test_logging_custom_env test /test_logging_custom_env.cpp
@@ -676,11 +693,13 @@ if(BUILD_TESTING)
676693 target_link_libraries (benchmark_err_handle ${PROJECT_NAME } ament_cmake_ros_core::ament_ros_defaults )
677694 endif ()
678695
679- ament_add_gtest (test_base64
680- test /test_base64.cpp
681- )
682- if (TARGET test_base64)
683- target_link_libraries (test_base64 ${PROJECT_NAME } ament_cmake_ros_core::ament_ros_defaults )
696+ if (NOT RCUTILS_MICROROS)
697+ ament_add_gtest (test_base64
698+ test /test_base64.cpp
699+ )
700+ if (TARGET test_base64)
701+ target_link_libraries (test_base64 ${PROJECT_NAME } ament_cmake_ros_core::ament_ros_defaults )
702+ endif ()
684703 endif ()
685704endif ()
686705
@@ -696,5 +715,5 @@ ament_export_dependencies(ament_cmake ament_cmake_ros_core)
696715ament_package ()
697716
698717install (
699- DIRECTORY include/
718+ DIRECTORY include/ ${ CMAKE_CURRENT_BINARY_DIR } /include/
700719 DESTINATION include/${PROJECT_NAME } )
0 commit comments