@@ -2,6 +2,12 @@ cmake_minimum_required(VERSION 3.20)
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+
511include (CheckLibraryExists )
612
713find_package (ament_cmake REQUIRED )
@@ -17,7 +23,7 @@ if(UNIX AND NOT APPLE)
1723 endif ()
1824endif ()
1925
20- if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
26+ if (NOT RCUTILS_MICROROS AND ( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) )
2127 # enables building a static library but later link it into a dynamic library
2228 add_compile_options (-fPIC )
2329endif ()
@@ -66,6 +72,7 @@ set(rcutils_sources
6672 src/time.c
6773 ${time_impl_c}
6874 src/uint8_array.c
75+ $<$<BOOL :${RCUTILS_NO_64_ATOMIC} >:src /atomic_64bits .c >
6976)
7077set_source_files_properties (
7178 ${rcutils_sources}
@@ -76,6 +83,7 @@ add_library(
7683 ${rcutils_sources} )
7784target_include_directories (${PROJECT_NAME } PUBLIC
7885 "$<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR } /include >"
86+ "$<BUILD_INTERFACE :${CMAKE_CURRENT_BINARY_DIR } /include >"
7987 "$<INSTALL_INTERFACE :include /${PROJECT_NAME } >" )
8088
8189# Causes the visibility macros to use dllexport rather than dllimport,
@@ -87,10 +95,18 @@ if(BUILD_TESTING AND NOT RCUTILS_DISABLE_FAULT_INJECTION)
8795endif ()
8896
8997target_link_libraries (${PROJECT_NAME }
90- ${CMAKE_DL_LIBS }
9198 ament_cmake_ros_core::ament_ros_defaults
9299)
93100
101+ configure_file (
102+ "${PROJECT_SOURCE_DIR } /include/rcutils/configuration_flags.h.in"
103+ "${PROJECT_BINARY_DIR } /include/rcutils/configuration_flags.h"
104+ )
105+
106+ if (NOT RCUTILS_NO_FILESYSTEM)
107+ target_link_libraries (${PROJECT_NAME } ${CMAKE_DL_LIBS } )
108+ endif ()
109+
94110check_library_exists (atomic __atomic_load_8 "" HAVE_LIBATOMICS )
95111
96112if (HAVE_LIBATOMICS AND NOT WIN32 AND NOT APPLE )
@@ -162,20 +178,22 @@ if(BUILD_TESTING)
162178 TIMEOUT 10
163179 )
164180
165- ament_add_gmock (test_logging_macros test /test_logging_macros.cpp )
166- target_link_libraries (test_logging_macros
167- ${PROJECT_NAME }
168- ament_cmake_ros_core::ament_ros_defaults
169- )
181+ if (NOT RCUTILS_MICROROS)
182+ ament_add_gmock (test_logging_macros test /test_logging_macros.cpp )
183+ target_link_libraries (test_logging_macros
184+ ${PROJECT_NAME }
185+ ament_cmake_ros_core::ament_ros_defaults
186+ )
170187
171- add_executable (test_logging_macros_c test /test_logging_macros.c )
172- target_link_libraries (test_logging_macros_c
173- ${PROJECT_NAME }
174- ament_cmake_ros_core::ament_ros_defaults
175- )
176- ament_add_test (test_logging_macros_c
177- COMMAND "$<TARGET_FILE :test_logging_macros_c >"
178- GENERATE_RESULT_FOR_RETURN_CODE_ZERO )
188+ add_executable (test_logging_macros_c test /test_logging_macros.c )
189+ target_link_libraries (test_logging_macros_c
190+ ${PROJECT_NAME }
191+ ament_cmake_ros_core::ament_ros_defaults
192+ )
193+ ament_add_test (test_logging_macros_c
194+ COMMAND "$<TARGET_FILE :test_logging_macros_c >"
195+ GENERATE_RESULT_FOR_RETURN_CODE_ZERO )
196+ endif ()
179197
180198 set (SKIP_MEMORY_TOOLS_TEST "" )
181199 if (NOT memory_tools_is_available)
@@ -637,15 +655,17 @@ if(BUILD_TESTING)
637655 )
638656 endif ()
639657
640- ament_add_gtest (test_logging_enable_for
641- test /test_logging_enable_for.cpp
642- )
643- if (TARGET test_logging_enable_for)
644- target_link_libraries (test_logging_enable_for
645- ${PROJECT_NAME }
646- osrf_testing_tools_cpp::memory_tools
647- ament_cmake_ros_core::ament_ros_defaults
658+ if (NOT RCUTILS_MICROROS)
659+ ament_add_gtest (test_logging_enable_for
660+ test /test_logging_enable_for.cpp
648661 )
662+ if (TARGET test_logging_enable_for)
663+ target_link_libraries (test_logging_enable_for
664+ ${PROJECT_NAME }
665+ osrf_testing_tools_cpp::memory_tools
666+ ament_cmake_ros_core::ament_ros_defaults
667+ )
668+ endif ()
649669 endif ()
650670
651671 ament_add_gtest (test_logging_console_output_handler
@@ -696,5 +716,5 @@ ament_export_dependencies(ament_cmake ament_cmake_ros_core)
696716ament_package ()
697717
698718install (
699- DIRECTORY include/
719+ DIRECTORY include/ ${ CMAKE_CURRENT_BINARY_DIR } /include/
700720 DESTINATION include/${PROJECT_NAME } )
0 commit comments