@@ -382,6 +382,72 @@ Such a CMakeLists.txt could look as:
382
382
383
383
project(my_first_app)
384
384
385
+ .. _cmake_build_config_package :
386
+
387
+ Zephyr Build Configuration CMake package
388
+ ****************************************
389
+
390
+ The Zephyr Build Configuration CMake package provides a possibility for a Zephyr based project to
391
+ control Zephyr build settings in a generic way.
392
+
393
+ It is similar to the use of ``.zephyrrc `` but with the possibility to automatically allow all users
394
+ to share the build configuration through the project repository.
395
+ But it also allows more advanced use cases than a ``.zephyrrc ``-file, such as loading of additional
396
+ CMake boilerplate code.
397
+
398
+ The Zephyr Build Configuration CMake package will be loaded in the Zephyr boilerplate code after
399
+ initial properties and ``ZEPHYR_BASE `` has been defined, but before CMake code execution.
400
+ This allows the Zephyr Build Configuration CMake package to setup or extend properties such as:
401
+ ``DTS_ROOT ``, ``BOARD_ROOT ``, ``TOOLCHAIN_ROOT `` / other toolchain setup, fixed overlays, and any
402
+ other property that can be controlled. It also allows inclusion of additional boilerplate code.
403
+
404
+ To provide a Zephyr Build Configuration CMake package, create ``ZephyrBuildConfig.cmake `` and place
405
+ it in a Zephyr workspace top-level folder as:
406
+
407
+ .. code-block :: none
408
+
409
+ <projects>/zephyr-workspace
410
+ ├── zephyr
411
+ ├── ...
412
+ └── zephyr application (can be named anything)
413
+ └── share/zephyrbuild-package/cmake/ZephyrBuildConfig.cmake
414
+
415
+ The Zephyr Build Configuration CMake package will not search in any CMake default search paths, and
416
+ thus cannot be installed in the CMake package registry. There will be no version checking on the
417
+ Zephyr Build Configuration package.
418
+
419
+ .. note :: ``share/zephyrbuild-package/cmake/ZephyrBuildConfig.cmake`` follows the same folder
420
+ structure as the Zephyr CMake package.
421
+
422
+ It is possible to place ``ZephyrBuildConfig.cmake `` directly in a
423
+ ``<zephyr application>/cmake `` folder or another folder, as long as that folder is
424
+ honoring the `CMake package search `_ algorithm.
425
+
426
+ A sample ``ZephyrBuildConfig.cmake `` can be seen below.
427
+
428
+ .. code-block :: cmake
429
+
430
+ # ZephyrBuildConfig.cmake sample code
431
+
432
+ # To ensure final path is absolute and does not contain ../.. in variable.
433
+ get_filename_component(APPLICATION_PROJECT_DIR
434
+ ${CMAKE_CURRENT_LIST_DIR}/../../..
435
+ ABSOLUTE
436
+ )
437
+
438
+ # Add this project to list of board roots
439
+ list(APPEND BOARD_ROOT ${APPLICATION_PROJECT_DIR})
440
+
441
+ # Default to GNU Arm Embedded toolchain if no toolchain is set
442
+ if(NOT ENV{ZEPHYR_TOOLCHAIN_VARIANT})
443
+ set(ZEPHYR_TOOLCHAIN_VARIANT gnuarmemb)
444
+ find_program(GNU_ARM_GCC arm-none-eabi-gcc)
445
+ if(NOT ${GNU_ARM_GCC} STREQUAL GNU_ARM_GCC-NOTFOUND)
446
+ # The toolchain root is located above the path to the compiler.
447
+ get_filename_component(GNUARMEMB_TOOLCHAIN_PATH ${GNU_ARM_GCC}/../.. ABSOLUTE)
448
+ endif()
449
+ endif()
450
+
385
451
Zephyr CMake package source code
386
452
********************************
387
453
@@ -428,3 +494,4 @@ The following is an overview of those files
428
494
.. _CMake package : https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html
429
495
.. _CMake user package registry : https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#user-package-registry
430
496
.. _CMake package version : https://cmake.org/cmake/help/latest/command/find_package.html#version-selection
497
+ .. _CMake package search : https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure
0 commit comments