From c75533fd159a284fbc602a880c546a798a7536ae Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 2 Dec 2019 16:45:01 -0800 Subject: [PATCH] [cmake] add OT_CONFIG to specify project core config header file (#4374) This commit adds new parameter `OT_CONFIG` to main `CMakeLists.txt` file. This parameter allows users to specify a project-specific core config header file (mapped to `OPENTHREAD_PROJECT_CORE_CONFIG_FILE`) during build configuration. The default value for this parameter is "none". When not specified (value is "none"), a platform cmake file may choose to change `OT_COFNIG` variable to provide its own core config header file. This commit updates platform 'posix' and 'cc2548' cmake files to provide platform specific header files when `OT_CONFIG` is not specified by user. --- CMakeLists.txt | 13 +++++++++++++ examples/platforms/cc2538/CMakeLists.txt | 8 +++++++- examples/platforms/posix/CMakeLists.txt | 8 +++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00ffb1409..e81b3fb75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,14 @@ if(NOT OT_PLATFORM IN_LIST OT_EXAMPLE_PLATFORMS) endif() endif() +# OT_CONFIG allows users to specify the path to OpenThread project core +# config header file. The default value of this parameter is empty string. +# When not specified by user (value is ""), a platform cmake file may +# choose to change this variable to provide its own core config header +# file instead. + +set(OT_CONFIG "" CACHE STRING "OpenThread project-specific config header file chosen by user at configure time") + list(APPEND OT_PUBLIC_INCLUDES ${PROJECT_BINARY_DIR}/etc/cmake) list(APPEND OT_PUBLIC_INCLUDES ${PROJECT_SOURCE_DIR}/etc/cmake) list(APPEND OT_PUBLIC_INCLUDES ${PROJECT_SOURCE_DIR}/include) @@ -71,6 +79,11 @@ elseif(NOT OT_PLATFORM MATCHES "none") add_subdirectory("${PROJECT_SOURCE_DIR}/examples/platforms/${OT_PLATFORM}") endif() +if(OT_CONFIG) + list(APPEND OT_PRIVATE_DEFINES "OPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"${OT_CONFIG}\"") + message(STATUS "Project core config: \"${OT_CONFIG}\"") +endif() + list(APPEND OT_PRIVATE_DEFINES ${OT_PLATFORM_DEFINES}) if(OT_BUILTIN_MBEDTLS) diff --git a/examples/platforms/cc2538/CMakeLists.txt b/examples/platforms/cc2538/CMakeLists.txt index f74b6b10c..13ecedb0d 100644 --- a/examples/platforms/cc2538/CMakeLists.txt +++ b/examples/platforms/cc2538/CMakeLists.txt @@ -28,13 +28,19 @@ set(OT_PLATFORM_LIB "openthread-cc2538" PARENT_SCOPE) +if(NOT OT_CONFIG) + set(OT_CONFIG "openthread-core-cc2538-config.h") + set(OT_CONFIG ${OT_CONFIG} PARENT_SCOPE) +endif() + 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(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE) +list(APPEND OT_PLATFORM_DEFINES "OPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"${OT_CONFIG}\"") + add_library(openthread-cc2538 alarm.c diag.c diff --git a/examples/platforms/posix/CMakeLists.txt b/examples/platforms/posix/CMakeLists.txt index 1de46f514..b4d7229e6 100644 --- a/examples/platforms/posix/CMakeLists.txt +++ b/examples/platforms/posix/CMakeLists.txt @@ -28,14 +28,20 @@ set(OT_PLATFORM_LIB "openthread-posix" PARENT_SCOPE) +if(NOT OT_CONFIG) + set(OT_CONFIG "openthread-core-posix-config.h") + set(OT_CONFIG ${OT_CONFIG} PARENT_SCOPE) +endif() + list(APPEND OT_PLATFORM_DEFINES - "OPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"openthread-core-posix-config.h\"" "OPENTHREAD_EXAMPLES_POSIX=1" "OPENTHREAD_POSIX=1" "OPENTHREAD_CONFIG_NCP_UART_ENABLE=1" ) set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE) +list(APPEND OT_PLATFORM_DEFINES "OPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"${OT_CONFIG}\"") + add_library(openthread-posix alarm.c diag.c