From 7e41de50650fe46a49080262d3ac39deb87aa3cb Mon Sep 17 00:00:00 2001 From: Pablo Garrido Date: Tue, 10 Mar 2020 08:20:00 +0100 Subject: [PATCH] CMake refactor --- CMakeLists.txt | 37 +++++++------------ .../{error_handling.h.in => error_handling.h} | 3 -- 2 files changed, 13 insertions(+), 27 deletions(-) rename include/rcutils/{error_handling.h.in => error_handling.h} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1af7100e..ebcf9dc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.5) project(rcutils) +option(RCUTILS_NO_THREAD_SUPPORT "Disable thread support." OFF) +option(RCUTILS_NO_FILESYSTEM "Disable filesystem usage." OFF) +option(RCUTILS_AVOID_DYNAMIC_ALLOCATION "Disable dynamic allocations." OFF) + # Default to C11 if(NOT CMAKE_C_STANDARD) set(CMAKE_C_STANDARD 11) @@ -29,27 +33,6 @@ else() set(time_impl_c src/time_unix.c) endif() -if(RCUTILS_NO_FILESYSTEM) - add_compile_options(-DRCUTILS_NO_FILESYSTEM=1) -endif() - -if(RCUTILS_NO_THREAD_SUPPORT) - add_compile_options(-DRCUTILS_NO_THREAD_SUPPORT=1) -endif() - -if(RCUTILS_AVOID_DYNAMIC_ALLOCATION) - add_compile_options(-DRCUTILS_AVOID_DYNAMIC_ALLOCATION=1) -endif() - -# target_compile_definitions(${PROJECT_NAME} PRIVATE "RCUTILS_NO_FILESYSTEM") -# target_compile_definitions(${PROJECT_NAME} PRIVATE "RCUTILS_NO_THREAD_SUPPORT") -# target_compile_definitions(${PROJECT_NAME} PRIVATE "RCUTILS_AVOID_DYNAMIC_ALLOCATION") - -configure_file ( - "${PROJECT_SOURCE_DIR}/include/rcutils/error_handling.h.in" - "${PROJECT_BINARY_DIR}/include/rcutils/error_handling.h" -) - set(rcutils_sources src/allocator.c src/array_list.c @@ -111,8 +94,7 @@ add_custom_command(OUTPUT include/rcutils/logging_macros.h VERBATIM ) list(APPEND rcutils_sources - include/rcutils/logging_macros.h - include/rcutils/error_handling.h) + include/rcutils/logging_macros.h) include_directories("${CMAKE_CURRENT_BINARY_DIR}/include") add_library( @@ -121,7 +103,14 @@ add_library( # Causes the visibility macros to use dllexport rather than dllimport, # which is appropriate when building the dll but not consuming it. -target_compile_definitions(${PROJECT_NAME} PRIVATE "RCUTILS_BUILDING_DLL") +target_compile_definitions(${PROJECT_NAME} + PRIVATE + RCUTILS_BUILDING_DLL + PUBLIC + $<$:RCUTILS_NO_THREAD_SUPPORT> + $<$:RCUTILS_NO_FILESYSTEM> + $<$:RCUTILS_AVOID_DYNAMIC_ALLOCATION> + ) # Needed if pthread is used for thread local storage. if(IOS AND IOS_SDK_VERSION LESS 10.0) diff --git a/include/rcutils/error_handling.h.in b/include/rcutils/error_handling.h similarity index 99% rename from include/rcutils/error_handling.h.in rename to include/rcutils/error_handling.h index a248a5d3..36376e97 100644 --- a/include/rcutils/error_handling.h.in +++ b/include/rcutils/error_handling.h @@ -39,9 +39,6 @@ extern "C" #include "rcutils/types/rcutils_ret.h" #include "rcutils/visibility_control.h" -#cmakedefine RCUTILS_NO_FILESYSTEM -#cmakedefine RCUTILS_AVOID_DYNAMIC_ALLOCATION - #if defined(__STDC_LIB_EXT1__) && !defined(RCUTILS_NO_FILESYSTEM) // Limit the buffer size in the `fwrite` call to give an upper bound to buffer overrun in the case // of non-null terminated `msg`.