From de67820c3cfd250ee47b30986fb6e4be0ab71f96 Mon Sep 17 00:00:00 2001 From: Jake Swensen Date: Fri, 8 Dec 2023 17:45:11 +0000 Subject: [PATCH] [cmake] config posix config file runtime location (#9701) OpenThread defines a structure to supply runtime configuration files on a POSIX platform. These runtime configuration files contain factory and product configuration information. They can include information such as radio target power, region, and calibration settings. By default, OpenThread uses an example file located at `src/posix/platform/openthread.conf.example`. However, the file location can be modified by supplying a pre-processor definition. This approach has a few flaws: - The pre-processor definitions are not accessible outside of the OpenThread project structure. - In order to change the values in project, a new header file must be provided, the existing one modified, or the value forcibly set in the OpenThread cmake file. This change introduces OT_POSIX_FACTORY_CONFIG and OT_POSIX_PRODUCT_CONFIG to the project cmake structure. These values allow projects that are using OpenThread as a sub-project to pass in these runtime config paths at compile time. This offers project maintainers flexibility in how their project is configured. --- src/posix/CMakeLists.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/posix/CMakeLists.txt b/src/posix/CMakeLists.txt index bc605f677..d8081d616 100644 --- a/src/posix/CMakeLists.txt +++ b/src/posix/CMakeLists.txt @@ -85,6 +85,19 @@ elseif(OT_APP_CLI) endif() endif() +set(OT_POSIX_FACTORY_CONFIG "" CACHE STRING "OpenThread factory config file") +set(OT_POSIX_PRODUCT_CONFIG "" CACHE STRING "OpenThread product config file") + +if (OT_POSIX_FACTORY_CONFIG) + target_compile_definitions(ot-config INTERFACE "OPENTHREAD_POSIX_CONFIG_FACTORY_CONFIG_FILE=\"${OT_POSIX_FACTORY_CONFIG}\"") + message(STATUS "OT_POSIX_FACTORY_CONFIG=\"${OT_POSIX_FACTORY_CONFIG}\"") +endif() + +if (OT_POSIX_PRODUCT_CONFIG) + target_compile_definitions(ot-config INTERFACE "OPENTHREAD_POSIX_CONFIG_PRODUCT_CONFIG_FILE=\"${OT_POSIX_PRODUCT_CONFIG}\"") + message(STATUS "OT_POSIX_PRODUCT_CONFIG=\"${OT_POSIX_PRODUCT_CONFIG}\"") +endif() + if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) set(CPACK_GENERATOR "DEB") set(CPACK_DEBIAN_PACKAGE_MAINTAINER "OpenThread Authors (https://github.com/openthread/openthread)")