From 6a00ea0cdb883b91d0262c4cccff0c3183248a59 Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Tue, 19 Nov 2019 15:01:22 +0000 Subject: [PATCH] [cmake] remove directory scoped add_definitions calls (#4112) These won't work well if a parent project includes openthread as a subproject, and aren't as well abstracted as the target-based definitions. --- CMakeLists.txt | 12 +++++++----- examples/platforms/cc2538/CMakeLists.txt | 2 ++ examples/platforms/cc2538/platform.cmake | 8 ++++---- examples/platforms/posix/CMakeLists.txt | 2 ++ examples/platforms/posix/platform.cmake | 8 ++++---- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f55bb4fd8..62e458f9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,9 +43,9 @@ execute_process( ) set(OT_VERSION "${__version}") -add_definitions( - -DPACKAGE_NAME="OPENTHREAD" - -DPACKAGE_VERSION="${OT_VERSION}" +list(APPEND OT_PRIVATE_DEFINES + "PACKAGE_NAME=\"OPENTHREAD\"" + "PACKAGE_VERSION=\"${OT_VERSION}\"" ) set(OT_PLATFORM "none" CACHE STRING "Target platform chosen by the user at configure time") @@ -77,12 +77,14 @@ if(NOT OT_PLATFORM MATCHES "none") include("${OT_ROOT_DIR}/examples/platforms/${OT_PLATFORM}/platform.cmake") endif() +list(APPEND OT_PRIVATE_DEFINES ${OT_PLATFORM_DEFINES}) + if(OT_BUILTIN_MBEDTLS) list(APPEND OT_PRIVATE_INCLUDES ${OT_ROOT_DIR}/third_party/mbedtls) list(APPEND OT_PRIVATE_INCLUDES ${OT_ROOT_DIR}/third_party/mbedtls/repo/include) - add_definitions( - -DMBEDTLS_CONFIG_FILE="mbedtls-config.h" + list(APPEND OT_PRIVATE_DEFINES + "MBEDTLS_CONFIG_FILE=\"mbedtls-config.h\"" ) endif() diff --git a/examples/platforms/cc2538/CMakeLists.txt b/examples/platforms/cc2538/CMakeLists.txt index 3a59d40c4..27cf447ed 100644 --- a/examples/platforms/cc2538/CMakeLists.txt +++ b/examples/platforms/cc2538/CMakeLists.txt @@ -42,6 +42,8 @@ add_library(openthread-cc2538 target_link_libraries(openthread-cc2538 PRIVATE openthread-platform-utils) +target_compile_definitions(openthread-cc2538 PUBLIC ${OT_PLATFORM_DEFINES}) + target_include_directories(openthread-cc2538 PRIVATE ${OT_PUBLIC_INCLUDES} ${OT_PRIVATE_INCLUDES} diff --git a/examples/platforms/cc2538/platform.cmake b/examples/platforms/cc2538/platform.cmake index 7236492cb..f505e4efb 100644 --- a/examples/platforms/cc2538/platform.cmake +++ b/examples/platforms/cc2538/platform.cmake @@ -26,10 +26,10 @@ # POSSIBILITY OF SUCH DAMAGE. # -add_definitions( - -DOPENTHREAD_PROJECT_CORE_CONFIG_FILE="openthread-core-cc2538-config.h" - -DOPENTHREAD_CORE_CONFIG_PLATFORM_CHECK_FILE="openthread-core-cc2538-config-check.h" - -DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1 +list(APPEND OT_PLATFORM_DEFINES + "OPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"openthread-core-cc2538-config.h\"" + "OPENTHREAD_CORE_CONFIG_PLATFORM_CHECK_FILE=\"openthread-core-cc2538-config-check.h\"" + "OPENTHREAD_CONFIG_NCP_UART_ENABLE=1" ) set(common_c_flags "-mcpu=cortex-m3 -mfloat-abi=soft") diff --git a/examples/platforms/posix/CMakeLists.txt b/examples/platforms/posix/CMakeLists.txt index a21d83b8f..55f933323 100644 --- a/examples/platforms/posix/CMakeLists.txt +++ b/examples/platforms/posix/CMakeLists.txt @@ -50,6 +50,8 @@ endif() target_link_libraries(openthread-posix PRIVATE openthread-platform-utils) +target_compile_definitions(openthread-posix PUBLIC ${OT_PLATFORM_DEFINES}) + target_include_directories(openthread-posix PRIVATE ${OT_PUBLIC_INCLUDES} ${OT_PRIVATE_INCLUDES} diff --git a/examples/platforms/posix/platform.cmake b/examples/platforms/posix/platform.cmake index e2893a461..0377b83d2 100644 --- a/examples/platforms/posix/platform.cmake +++ b/examples/platforms/posix/platform.cmake @@ -26,10 +26,10 @@ # POSSIBILITY OF SUCH DAMAGE. # -add_definitions( - -DOPENTHREAD_PROJECT_CORE_CONFIG_FILE="openthread-core-posix-config.h" - -DOPENTHREAD_EXAMPLES_POSIX=1 - -DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1 +list(APPEND OT_PLATFORM_DEFINES + "OPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"openthread-core-posix-config.h\"" + "OPENTHREAD_EXAMPLES_POSIX=1" + "OPENTHREAD_CONFIG_NCP_UART_ENABLE=1" ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENTHREAD_POSIX=1")