zephyr/cmake/modules
Torsten Rasmussen 90e236581e cmake: implement zephyr_get(<variable>) function
Fixes: #40389

This commit implements zephyr_get(<variable>).

The purpose of zephyr_get(<variable>) is to ensure a uniform way to
handle variables which can be defined as:
- CMake cache variable, for example `-D<var>=<value>`.
- Environment variable
- Locally in CMakeLists.txt file before `find_package(Zephyr)`

It furthermore ensures that if an environment setting hides a local
setting then a warning is printed.

using
zephyr_get(<var>)

removes the need for constructs like:
set_ifndef(<var> "$ENV{<var>}")
set(<var> ${<var>} CACHE PATH "")

if(NOT DEFINED <var>)
  set(<var> $ENV{<var>})
endif()

if (NOT DEFINED ENV{<var>})
  message(FATAL_ERROR <error>)
endif()

and also ensures identical preference order for variables used in Zephyr
1. cache
2. environment
3. local scope var

It also ensures the variables supported through environment can also be
set using `-D<var>=<value>`

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-02 15:16:50 +02:00
..
arch.cmake cmake: kconfig: introduce dedicated unit testing board 2022-08-18 14:29:14 +02:00
boards.cmake cmake: kconfig: introduce dedicated unit testing board 2022-08-18 14:29:14 +02:00
ccache.cmake cmake: Zephyr CMake package and CMake modules 2022-02-22 10:02:39 -08:00
configuration_files.cmake everywhere: fix typos 2022-03-18 13:24:08 -04:00
doc.cmake cmake: doc: created a doc.cmake CMake module in Zephyr CMake modules dir 2022-02-22 10:02:39 -08:00
dts.cmake cmake: rework of host tools and generic toolchain handling 2022-09-01 15:59:43 +02:00
extensions.cmake cmake: implement zephyr_get(<variable>) function 2022-09-02 15:16:50 +02:00
FindDeprecated.cmake cmake: move deprecated code to FindDeprecated.cmake 2022-09-01 15:59:43 +02:00
FindDtc.cmake cmake: cleanup search for devicetree compiler, dtc 2022-09-01 15:59:43 +02:00
FindHostTools.cmake cmake: locate Zephyr SDK before locating other host tools. 2022-09-02 19:41:15 +09:00
FindTargetTools.cmake cmake: rework of target toolchain handling 2022-09-01 15:59:43 +02:00
FindZephyr-sdk.cmake cmake: rework of host tools and generic toolchain handling 2022-09-01 15:59:43 +02:00
kconfig.cmake cmake: kconfig: preserved quotes for Kconfig string values 2022-08-25 17:53:11 -07:00
kernel.cmake cmake: rework of target toolchain handling 2022-09-01 15:59:43 +02:00
python.cmake cmake: Bump the minimum required Python version to 3.8 2022-08-24 18:35:57 +02:00
root.cmake cmake: kconfig: introduce dedicated unit testing board 2022-08-18 14:29:14 +02:00
shields.cmake devicetree: drop support for dts_fixup.h files 2022-08-11 12:17:02 +02:00
soc.cmake cmake: Zephyr CMake package and CMake modules 2022-02-22 10:02:39 -08:00
unittest.cmake cmake: kconfig: introduce dedicated unit testing board 2022-08-18 14:29:14 +02:00
user_cache.cmake scripts: move dir_is_writeable.py to scripts/build 2022-07-12 10:03:45 +02:00
version.cmake cmake: Zephyr CMake package and CMake modules 2022-02-22 10:02:39 -08:00
west.cmake cmake: Zephyr CMake package and CMake modules 2022-02-22 10:02:39 -08:00
zephyr_default.cmake cmake: rework of target toolchain handling 2022-09-01 15:59:43 +02:00
zephyr_module.cmake scripts: enforce module name uniqueness 2022-03-10 09:47:58 -05:00