[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.
This commit is contained in:
Jake Swensen
2023-12-13 11:02:43 -08:00
committed by Jonathan Hui
parent 83fb6c29b1
commit de67820c3c
+13
View File
@@ -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)")