From 0950b2549eefc1b36c890eb3aa342d6d17c6ee7f Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Fri, 21 Aug 2020 14:52:15 -0500 Subject: [PATCH] dts: support specifying preprocessor flags for devicetree In some cases it is useful to use the C preprocessor to control the content of a devicetree file. A specific use case is in testing, where different combinations of node properties must be checked. Provide a mechanism to allow arbitrary preprocessor flags to be passed through CMake to affect the devicetree content. Signed-off-by: Peter A. Bigot --- cmake/dts.cmake | 1 + doc/application/index.rst | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/cmake/dts.cmake b/cmake/dts.cmake index 0c9d990c804..f41e1aebd44 100644 --- a/cmake/dts.cmake +++ b/cmake/dts.cmake @@ -140,6 +140,7 @@ if(SUPPORTS_DTS) ${DTC_INCLUDE_FLAG_FOR_DTS} # include the DTS source and overlays ${NOSYSDEF_CFLAG} -D__DTS__ + ${DTS_EXTRA_CPPFLAGS} -P -E # Stop after preprocessing -MD # Generate a dependency file as a side-effect diff --git a/doc/application/index.rst b/doc/application/index.rst index d4965439a76..bac3044b5e0 100644 --- a/doc/application/index.rst +++ b/doc/application/index.rst @@ -783,6 +783,20 @@ You can also define the variable in the application :file:`CMakeLists.txt` file. Make sure to do so **before** pulling in the Zephyr boilerplate with ``find_package(Zephyr ...)``. +Devicetree source are passed through the C preprocessor, so you can +include files that can be located in a ``DTS_ROOT`` directory. By +convention devicetree include files have a ``.dtsi`` extension. + +You can also use the preprocessor to control the content of a devicetree +file, by specifying directives through the ``DTS_EXTRA_CPPFLAGS`` CMake +Cache variable: + +.. zephyr-app-commands:: + :tool: all + :board: + :gen-args: -DDTS_EXTRA_CPPFLAGS=-DTEST_ENABLE_FEATURE + :goals: build + :compact: Application Debugging *********************