Commit graph

91 commits

Author SHA1 Message Date
Torsten Rasmussen fe3efbc6a2 cmake: BOARD_REVISION_CONFIG setting for Kconfig revision fragments
Fixes: #53696

Create a BOARD_REVISION_CONFIG setting to be consistent with the
BOARD_DEFCONFIG setting.

This allows systems which re-uses the Kconfig module to overrule the
file to be used as BOARD_REVISION_CONFIG in same way as is done for
the BOARD_DEFCONFIG file.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-01-11 08:10:45 -08:00
Marti Bolivar 951664749b cmake: fix and clean up some module doc comments
The boards, shields, and zephyr_module CMake modules have some issues
in their comments that can be trivially fixed up.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
2023-01-11 09:40:14 +01:00
Yasushi SHOJI 4f7e2bb658 cmake: Fix typo by replacing zephyr_library_add_sources
There is no function called zephyr_library_add_sources().  This must be
zephyr_library_sources().

Signed-off-by: Yasushi SHOJI <yashi@spacecubics.com>
2023-01-09 19:20:56 +01:00
Marc Herbert 3ec1bb2776 cmake: log ${CMAKE_VERSION}
Different CMake versions can have very subtle differences, for
instance CMake 3.21 links object files in a different order compared
to CMake 3.20; this produces different binaries.

CMAKE_VERSION is required information to track binary differences
between two build systems.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2022-12-22 10:55:28 +01:00
Ming Shao 632972459a cmake: fix a typo in zephyr_linker_arg_val_list() macro
The CMake list delimiter is ";" rather than ":".

Signed-off-by: Ming Shao <smrtos@163.com>
2022-12-21 16:24:37 +01:00
Martí Bolívar ba059ff9b5 cmake: shields: documentation fixes
- Fix commit b2520b09a7 ("devicetree:
  drop support for dts_fixup.h files"), which removed support for
  shield-related fixups but forgot to update the module-level
  documentation comment.

- Fix commit 61453e4a58 ("cmake: Zephyr
  CMake package and CMake modules"), which contained some
  BOARD-related copy/paste errors and omitted documentation for
  the SHIELD_DIRS output variable (this is used in the dts
  cmake module, so it's part of the shield module's contract)

- Add some other clarifying remarks and comments

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2022-12-19 11:54:25 +01:00
Martí Bolívar 23b947532c cmake: modules: extensions: fix a section header
The table of contents at the top of the file has 'Devicetree
extensions' as the name of the section containing... those things.

The actual place in the file where they are defined has a different
title, though, defeating searching in the file for that section name.

Fix it.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2022-12-19 11:54:25 +01:00
Martí Bolívar 9812447449 cmake: extensions: clarify zephyr_file() behavior
"Populate" is ambiguous here: does that mean set, or append? The
answer is "append", so use that to be clearer. Be extra clear where
we're looking in as well.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2022-12-19 11:54:25 +01:00
Torsten Rasmussen 0b845cd28c cmake: update FindDeprecated for SOURCES
PR#51049 deprecated SOURCES but placed it below the
Deprecated_FIND_COMPONENTS check causing following message to be printed
when building for the unit_testing board:
-- The following deprecated component(s) could not be found: SOURCES

Fix this by placing the deprecated SOURCES handling at proper location
and append SOURCES to Deprecated_FIND_COMPONENTS list.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-12-05 11:03:02 +01:00
Yuval Peress 49ca6f8f7d unittest: add support for coverage
Some missing features for getting coverage data for unit tests:
- Setting the unit_testing board to have coverage support and native
  application.
- Fixing the CONFIG_COVERAGE check

Signed-off-by: Yuval Peress <peress@google.com>
2022-11-28 16:26:02 -05:00
Yuval Peress fae9923ff2 unittest: update coverage library non gcc toolchains
When building with clang, the unittests were giving us an error:
```
error: undefined symbol: llvm_gcda_start_file
```

This seems to be from linking in `gcov` regardless of the toolchain.
It appears that clang doesn't need any special library for coverage.
With this change the following now produce identical coverage reports:

```
$ ZEPHYR_TOOLCHAIN_VARIANT=zephyr ./scripts/twister -p unit_testing \
  --coverage -i -T tests/unit/intmath/
$ ZEPHYR_TOOLCHAIN_VARIANT=host ./scripts/twister -p unit_testing \
  --coverage -i -T tests/unit/intmath/
$ ZEPHYR_TOOLCHAIN_VARIANT=llvm ./scripts/twister -p unit_testing \
  --coverage -i --coverage-tool lcov                              \
  --gcov-tool $(pwd)/scripts/utils/llvm-gcov.sh                   \
  -T tests/unit/intmath/
```

Signed-off-by: Yuval Peress <peress@google.com>
2022-11-21 16:09:46 -05:00
Stephanos Ioannidis a9d85ae472 cmake: Deprecate 'xtools' toolchain variant
The `xtools` toolchain variant (aka. Crosstool-NG) was originally
introduced to be used with the Crosstool-NG-based Zephyr SDK
toolchains (i.e. sdk-ng).

This is no longer necessary because the current Zephyr SDK (sdk-ng)
already has its own `zephyr` toolchain variant, which fully replaces
the `xtools` toolchain variant, and the `xtools` toolchain variant
serves no purpose at all.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2022-11-17 15:42:48 +09:00
Torsten Rasmussen e0fb04458f cmake: sysbuild: import image kconfig settings to image target
Load image kconfig setting into image target properties.
This allows sysbuild to evaluate and check image configuration as part
of CMake invocation.

sysbuild_get() is updated to support reading of CMake cache or Kconfig
settings for an image.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-11-02 15:42:23 +09:00
Torsten Rasmussen 430370c4e4 cmake: fix <keys> argument in import_kconfig()
The signature of import_kconfig() take two mandatory arguments and one
optional:
> import_kconfig(<prefix> <kconfig_fragment> [<keys>])

but has been implemented in such a way that it loops all arguments after
the two mandatory args and sets the same list on those.

Fix this error by only setting the created variables on the third and
optional argument if it exists.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-11-02 15:42:23 +09:00
Yuval Peress ffb861d1a3 unittest: warn users of deprecated SOURCES
If users set SOURCES before find_package for unit tests, we'll warn them
that this code path will no longer be supported and provide the correct
way of doing things moving forward.

Signed-off-by: Yuval Peress <peress@google.com>
2022-10-31 17:01:59 +01:00
Yuval Peress 9cebf732ee unittest: Only add main.c if it exists
Downstream it's easier to write tests that use target_sources after
including the unittest package instead of specifying a list of sources
before. But if we do that, currently, main.c is added and the build
breaks because it doesn't exist.

Signed-off-by: Yuval Peress <peress@google.com>
2022-10-31 17:01:59 +01:00
Torsten Rasmussen d79d80518b cmake: test_sysbuild() function
Introduce a `test_sysbuild()` function.

This function is intended to be used by samples that are dependent on
sysbuild. This function allows such samples to test if sysbuild was used
in the build process, and when sysbuild is not used, then print a
warning to the user, or even fail the build.

This is useful for samples that have two parts to function properly, for
example samples that needs to be build and flash on two or more cores.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-10-18 14:13:27 +02:00
Torsten Rasmussen 303c1eb60c sysbuild: support sample configuration of extra images
This commit introduces the possibility of a sample to locate
configuration files for extra images that are used when building with
MCUboot.

This allows use-cases where a sample, A, want to include MCUboot but has
adjustments to the default MCUboot configuration.

By adding a Kconfig fragment `<sample>/sysbuild/mcuboot.conf`, then that
fragment will be used together with the default configuration for
MCUboot.

It is also possible to completely replace the MCUboot configuration.
This is done by creating `<sample>/sysbuild/mcuboot/` folder.
This folder will then be used as the `APPLICATION_CONFIG_DIR` when
building MCUboot.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-10-18 14:13:27 +02:00
Gregory Shue cfcf630184 build: Overlay build vars expand ${ZEPHYR_<module>_MODULE_DIR}
Support referencing module directories by name in CONF_FILE,
OVERLAY_CONFIG, and DTC_OVERLAY_FILE so that projects can reference
overlay files in arbitrary modules.

Verified by passing all the following tests:
  ./scripts/twister -T tests/cmake/overlays/

Fixes #41830

Signed-off-by: Gregory Shue <gregory.shue@legrand.us>
2022-10-13 12:04:38 +02:00
Torsten Rasmussen 4ced8de50c cmake: propagate endianess to CMake CMAKE_<lang>_BYTE_ORDER setting
Fixes: #45270

Zephyr Kconfig defines the settings BIG_ENDIAN.
Propagate this setting to the corresponding CMAKE_C_BYTE_ORDER and
CMAKE_CXX_BYTE_ORDER variables.

This also ensures that the CMake function 'is_big_endian()' reports the
correct endianess.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-26 15:09:38 +00:00
Torsten Rasmussen af4a87af8e cmake: support relocating of a board folder
Fixes: #49116

During development of out-of-tree boards and applications it is not
uncommon to refactor / restructure code.

To allow developers more freedom, let's check that board's defconfig
still exists during a CMake re-run.
If the defconfig no longer exists, either because it's been moved or
deleted, then warn the user and set BOARD_DIR to NOTFOUND.

The NOTFOUND will request CMake to search for the new location in all
board roots. If the board has not been found, as example it's deleted,
then the existing error is printed later.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-22 17:14:20 +02:00
Torsten Rasmussen c32e4a71bf cmake: support grouping of compile options for compiler testing
Fixes: #47588

Kitware decided to fail compiler tests of single options if the
compiler reported only a warning and not an error:
github.com/Kitware/CMake/commit/f745e0497ee71d35fd1b3524b1636a72da76c266
which affects CMake 3.23.0 and 3.23.1

This change was later reverted in CMake >=3.23.2 and >=3.24.0
github.com/Kitware/CMake/commit/4941887d7defecb3016d2bd94d3a45754251ca56

Although the immediate issue is related to CMake, and has been fixed
reverted in later releases, then it still makes sense to be able to
group compiler options together that generally are depending on each
other to function correctly.

This commit introduces the possibility to group compiler options which
must be tested together.
It uses same approach as
> add_compile_options("SHELL:<option1> <option2> ...")

Usage:
> check_set_compiler_property(PROPERTY <property>
>                             "SHELL:<option1> <option2> ..."
> )

Will test the option together.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-14 09:37:59 +00:00
Torsten Rasmussen a0a72b9a96 cmake: create test_interface interface library
Creating a test_interface allows more complex unittest projects to
create additional libraries, for example mock libs, that can be re-used
between test projects.

To support the possibility of such libs to build with same flags as the
testbinary the test_interface is now populated with the public compile
and include flags from testbinary.

testbinary has been updated to use test_interface.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-09 10:06:19 +02:00
Torsten Rasmussen a5cd394758 cmake: improve warning deprecation message
The current deprecation warning could give the impression that
CROSS_COMPILE is deprecated, which is not the case.

Instead it is the behavior of defaulting to `cross-compile` when
setting CROSS_COMPILE in environment without setting
ZEPHYR_TOOLCHAIN_VARIANT that is deprecated.
Not the use of `CROSS_COMPILE` setting itself.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-07 15:38:36 +02:00
Torsten Rasmussen b066ae906b cmake: fix improper use of separate_arguments
The use of `separate_arguments()` in extra_flags.cmake and
unittest.cmake prevents the use of proper CMake lists.

A CMake list can be specified on command line as:
`-DMY_LIST="itemA;itemB;itemC"`

Users are expected to be able to provide extra compile flags using CMake
lists, like `-DEXTRA_CFLAGS="--flag1;--flag2"` but also using space
separated lists, like: `-DEXTRA_CFLAGS="--flag1 --flag2"`.

However, the way FLAGS was passed to separate_arguments() would result
in a list being treated as extra arguments to the function and thus
result in a CMake error.

To allow the use of CMake lists, the length of the argument as a CMake
list is tested. This ensures that when the argument contains a
single `;` then the length is >1 and no conversion is needed.

This allows a user to freely choose between the two forms:
- `-DFLAGS="--flag1 --flag2"`
- `-DFLAGS="--flag1;--flag2"`

or when passing flags which themselves contains spaces, like:
- `-DFLAGS="--flag1 \"val1 val2\""`
- `-DFLAGS="--flag1;val1 val2"`

Note that the extra escaped qouting is no longer needed for proper CMake
lists as the `;` itself informs the system that spaces are to be kept as
spaces.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-05 10:22:05 +02:00
Torsten Rasmussen 88ae9cbb9d cmake: extend zephyr_get() to handle build configurations from sysbuild
Enhance sysbuild controlled configurations.

The current scheme of passing settings using `-D` on the CMake
invocation is vulnerable to quoting and lists.

With `zephyr_get()` in place as a uniform way of handling user
controlled settings (CMake cache / environment / CMake local variable)
we have a mechanism in place for a cleaner handling of sysbuild
controlled settings.

This improves the robustness of variable passing and add the same cleans
up and simplifies the logic in sysbuild.

The Kconfig Zephyr CMake module has been updated accordingly so that
CONFIG settings are taken from the sysbuild shadow cache when sysbuild
is used as higher level build system.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-02 15:16:50 +02:00
Torsten Rasmussen 44a05e4439 cmake: update common Zephyr build settings to use zephyr_get()
Fixes: #40389

This commit aligns the use of the following Zephyr build variables:
- CONF_FILE
- DTC_OVERLAY_FILE
- OVERLAY_CONFIG
- WEST_DIR
- ZEPHYR_BOARD_ALIASES
- ZEPHYR_EXTRA_MODULES
- ZEPHYR_MODULES

so that they can be set in same manner and with same order of
preference.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-02 15:16:50 +02:00
Torsten Rasmussen 6d1f6c2d4e cmake: improved variable handling in zephyr_check_cache()
A cache variable specified by the user as `-DVAR=value` will have the
type UNINITIALIZED in the CMake cache.

Later CMake re-runs will execute the line:
set(${variable} ${CACHED_${variable}} CACHE STRING
    "Selected ${variable_text}" FORCE)

This will update the cache type from UNINITIALIZED to STRING and thus
may be picked up by other tools as a change.

To ensure the type is initialized to string, this is added:
set(${variable} ${${variable}} CACHE STRING "Selected ${variable_text}")

This code will not change the value of an existing CMake cache variable
because there is no FORCE, but what it will do is to update the cache
variable type to STRING.

As part of this, include the existing parent scope setting of variable
inside the `if(DEFINED ...)` as there is no reason to clear a variable
there is not having a value.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-02 15:16:50 +02:00
Torsten Rasmussen 56c827ac2c cmake: use zephyr_get in toolchains to ensure identical behavior.
Fixes: #40389

Update toolchain handling to use zephyr_get() to ensure consistent
handling of CMake cache variables, environment variable, and CMake
local variables.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-02 15:16:50 +02:00
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
Mateusz Sierszulski 6c888b2db1 soc: telink_b91: Fix ROM region section overlap
Place vector sections after ROM_START sections.
Also add init.ld script that will prevent overlapping .init sections
in telink_b91 SoC.

Fixes #49036.

Signed-off-by: Mateusz Sierszulski <msierszulski@antmicro.com>
2022-09-02 14:19:53 +02:00
Torsten Rasmussen f6979306bc cmake: locate Zephyr SDK before locating other host tools.
Follow-up: #49672

Zephyr SDK and host tools detection was reworked in #49672.

That rework accidentally changed the lookup order from:
- Zephyr SDK
- Other host tools
- Generic (host) C compiler

into
- Other host tools
- Zephyr SDK
- Generic (host) C compiler

this causes host tools shipped with Zephyr SDK, such as openocd to not
be discovered unless in path.

Restore the original order so that Zephyr SDK is located first so that
host tools from the SDK can be found without having them in path.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-02 19:41:15 +09:00
Torsten Rasmussen 980c22c92d cmake: move deprecated code to FindDeprecated.cmake
Move deprecated XCC_USE_CLANG setting to deprecated module.

Deprecated and move the use of CROSS_COMPILE to deprecated module as we
have had ZEPHYR_TOOLCHAIN_VARIANT==cross-compile for a long time.

Deprecated code is now loaded with a single line:
> find_package(Deprecated COMPONENTS XCC_USE_CLANG CROSS_COMPILE)

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-01 15:59:43 +02:00
Torsten Rasmussen 2f1637c4b4 cmake: introduce Deprecated module
The deprecated CMake module allows Zephyr to move deprecated code to a
centralized location from where it's both easy to get an overview of
deprecated code, and remove the code when it has been deprecated long
enough.

It further improve existing code, as the real CMake code now can be
changed from n-lines of deprecated code into a single line of the form:
find_package(Deprecated COMPONENTS <deprecated_name>)

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-01 15:59:43 +02:00
Torsten Rasmussen 7131d02fa4 cmake: rework of target toolchain handling
Follow-up: #41301

This commit is a rework and cleanup of the target toolchain handling in
Zephyr CMake build system.

Instead of directly loading code a CMake modules for target toolchain
lookup, the target toolchain now follows the CMake `find_package()`
pattern for finding the target toolchain.

This makes it more clear which modules are responsible for finding tools
and which modules provides build integration / features.

The following tools can now be found using `find_package()`:
- Target toolchain: find_package(TargetTools)

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-01 15:59:43 +02:00
Torsten Rasmussen 8d2998d4f9 cmake: rework of host tools and generic toolchain handling
Follow-up: #41301

This commit is a rework and cleanup of the tools handling in Zephyr
CMake build system.

Instead of directly loading code a CMake modules for tool lookup, the
host tools now follows the CMake `find_package()` pattern for finding
programs / tools in module mode.

This makes it more clear which modules are responsible for finding tools
and which modules provides build integration / features.

The following tools can now be found using `find_package()`:
- Zephyr-sdk        : find_package(Zephyr-sdk <version>)
- Generic host tools: find_package(HostTools)

This further allows us to decouple the `verify-toolchain` CMake script
part required by `twister` into a tool lookup module and a dedicated
CMake script which utilizes the lookup module.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-01 15:59:43 +02:00
Torsten Rasmussen 2bace34be3 cmake: remove unreachable Zephyr-SDK lookup code
Removing Zephyr-SDK code for searching and printing messages when Zephyr
SDK is not found in the system.

After Zephyr SDK has been made available on all platforms, including
MacOS and Windows, then `find_package(Zephyr-sdk)` is always invoked
and thus either `find_package(Zephyr-sdk)` will fail or
ZEPHYR_TOOLCHAIN_VARIANT will be defined.

Meaning the removed code block in this commit can no longer be reached.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-01 15:59:43 +02:00
Torsten Rasmussen 8f8f6cfde3 cmake: cleanup search for devicetree compiler, dtc
Cleanup CMake code by moving devicetree compiler detection to dedicated
FindDtc.cmake module.

This allows us to re-use existing CMake find_package() functionality in
module mode and thus reduce CMake logic.

It further has the benefit of being able to directly specify dtc version
like this:
> find_package(Dtc 1.4.6)

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-01 15:59:43 +02:00
Torsten Rasmussen 9a12f8b68b cmake: move testing of compile flag in environment to top CMakeLists.txt
This moves the test of compile flags set in environment from generic
toolchain to top-level ${ZEPHYR_BASE}/CMakeLists.txt.

In order to cleanup and make Zephyr CMake modules more generic then
the testing of specific compile flags and warn user is not really a
toolchain module responsible but a implementation detail of the project
itself as to how compile flags should be applied in a project.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-09-01 15:59:43 +02:00
Stephanos Ioannidis cedaa6a2e5 cmake: Fix Zephyr SDK download URL
This commit fixes the outdated Zephyr SDK download URL in the toolchain
verification script.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-29 16:57:18 +02:00
Stephanos Ioannidis 30af51fc5e cmake: Set minimum required Zephyr SDK version to 0.15
This commit sets the minimum required Zephyr SDK version to 0.15, which
is required to build the current Zephyr codebase due to the following
breaking changes:

* RISC-V ISA spec change to 20191213 requiring the Zicsr and Zifencei
  extensions to be specified to the `-march` flag
* ARC64 output format name change to `elf64-littlearc64`

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-29 16:57:18 +02:00
Mahesh Mahadevan c029b081cc cmake: Add support to add symbols to nocache section
This PR allows the user to add symbols to the nocache
section. The use for this could be as follows

zephyr_linker_sources_ifdef(CONFIG_NOCACHE_MEMORY
  NOCACHE_SECTION
  nocache.ld
)

nocache.ld (as shown below) can define additional
symbols to  go into the nocache section

. = ALIGN(4);
KEEP(*(NonCacheable))

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2022-08-29 11:19:48 +02:00
Torsten Rasmussen 4cb2ef83bf cmake: kconfig: preserved quotes for Kconfig string values
Fixes: #48950

Kconfig requires quoted strings in its configuration files, like this:
> CONFIG_A_STRING="foo bar"

But CMake requires expects that strings are without additional qoutes,
and therefore qoutes are stripped when loading Kconfig config filers
into CMake.

This is particular important when the string in Kconfig is a path to a
file. In this case, not stripping the quotes leads to an error as the
file cannot be found.

When users pass a string to Kconfig through CMake, they are expected to
pass it so that qoutes are correct seen from Kconfig, that is:
> cmake -DCONFIG_A_STRING=\"foo bar\"

In CMake, those qoutes are written as-is to Kconfig extra config file,
and then removed in the CMake cache.
After Kconfig processing, the Kconfig settings are read back to CMake
but without quotes. Settings that was passed through the CMake cache,
for example using `-D` are written back to the cache, but this time
without the qoutes. This results in Kconfig errors on sub-sequent CMake
runs.

Instead of writing the Kconfig value setting back to the CMake cache,
introduce an internal shadow symbol in the cache prefixed with `CLI_`.
This allows the CMake cache to keep the value correctly formatted for
Kconfig extra config creation, while at the same time keep existing
behavior for CONFIG_ symbols read from Kconfig.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-08-25 17:53:11 -07:00
Carles Cufi 33211b3fb4 cmake: Bump the minimum required Python version to 3.8
Given that 3.6 is now several years old and the current and previous
Ubuntu LTS ship with 3.8 or later, upgrade the minimum required Python
version from 3.6 to 3.8.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-08-24 18:35:57 +02:00
Daniel Leung 1ace8efb8a cmake: extend linker snippets for pinned sections
This extends the linker snippet code to cover pinned
sections.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-08-18 17:23:18 +02:00
Torsten Rasmussen 7a65bdbd64 cmake: kconfig: introduce dedicated unit testing board
This commit introduces a dedicated unit testing board.

Today, a dedicated Zephyr unit testing scheme exists but is different
from how a Zephyr build generally works.

For example Kconfig is not possible, resulting on various different
hacks to pass Kconfig settings from test cases / testcase.yaml through
CMake to the code.
Some directly as compile definitions, some as header files with forced
inclusion on sources, some with wrapper flags which again results in
different define being enabled. There is even cases where a second
forced header inclusion undefines previous defines.

Unit test often does a manual check for the right boards, like this:
> if (NOT BOARD STREQUAL unit_testing)
>    message(FATAL_ERROR "This project can only be used with...")
> endif()

Introducing a dedicated unit_testing board under `tests/root` allows
us to use Kconfig in unit test samples, and thus proper `prj.conf` and
extra Kconfig fragments.
Generation of autoconf.h so the overall architecture follows regular
Zephyr builds.

Proper and uniform error messages when invalid board is selected.

The unit_testing board and arch is located under: `subsys/testsuite` so
that it is only available when find_package(Zephyr COMPONENTS unittest)
is used, and not available for regular Zephyr builds.

Kconfig generates autoconf.h which is applied as compile flag to
test binary which means that kconfig defines placed in ztest.h can now
be removed.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-08-18 14:29:14 +02:00
Torsten Rasmussen a450c663f2 cmake: define and create KCONFIG_BINARY_DIR if it doesn't exists
The Zephyr CMake module kconfig.cmake will create files inside
KCONFIG_BINARY_DIR.

In a default Zephyr build setup, this directory is created by Zephyr
CMake module zephyr_module.cmake. But Zephyr CMake modules are modular
and thus it must be possible to use kconfig module without
zephyr_module.

Thus kconfig.cmake must set and create KCONFIG_BINARY_DIR if it does not
already exists.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-08-18 14:29:14 +02:00
Torsten Rasmussen c3620c8a8e scripts: remove ZEPHYR_BASE as default root for board listing
Remove ZEPHYR_BASE as default root in list_boards.py.

This allows list_boards.py to be used to only print boards at given
root(s) without printing Zephyr default boards.

Secondly it remove the need in list_boards.py to have any knowledge of
ZEPHYR_BASE.

The `west boards` command already has ZEPHYR_BASE knowledge and can
easily add ZEPHYR_BASE to the list of roots it is already constructing,
thus removing the need for knowing that ZEPHYR_BASE is always added.

Update boards.cmake to pass ZEPHYR_BASE as an additional arch root, as
arch.cmake has not yet been processed,which means ZEPHYR_BASE is missing
in ARCH_ROOT list at this point in time.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-08-18 14:29:14 +02:00
Fabio Baltieri 0226e53e23 Restore "cmake: remove device_extern.h logic"
This reverts commit 87c6789355, restoring
commit 3b341085a2.

Restore the original change now that the underlying issue has been fixed
in 6cfb18686e.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2022-08-12 07:45:01 +01:00
Fabio Baltieri 87c6789355 Revert "cmake: remove device_extern.h logic"
This reverts commit 3b341085a2.

Seems to be breaking CI for few qemu platforms.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2022-08-11 17:21:46 -05:00