Commit graph

96 commits

Author SHA1 Message Date
Torsten Rasmussen e1c1d1daca cmake: make find_package(ZephyrUnittest...) REQUIRED
This commit is a followup to PR #25808 which updates the tests to
ensure the REQUIRED keyword is also used for the ZephyrUnitest package.

This provides a better error message when building with CMake and
forgetting ZEPHYR_BASE or not registering Zephyr in the CMake package
registry.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-06-12 11:10:23 +02:00
Pete Johanson 9b27cfd8c4 cmake: Fixes for shields in multiple roots
* Reset SHIELD_LIST on each root loop, to avoid matching
  on shields from the previous iteration of the loop.

Signed-off-by: Pete Johanson <peter@peterjohanson.com>
2020-06-09 15:24:48 +02:00
Torsten Rasmussen 8d3e822e79 cmake: resolved list issue when parsing shield list
Fixes: #25656

The commit a8e90cbfb3 improved handling of
shields. Unfortunately it pops items from the SHIELD variable which
works well if SHIELD is a CMake ;-separated list, but if the list is
a space separated list, as may be provided by the user, then this
principle fails as reported in #25656.

This is fixed by keeping improved behaviour, while popping from an
alternative SHIELD-NOTFOUND list instead.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-05-29 13:11:17 +02:00
Torsten Rasmussen 9adcabe38d cmake: introduction of ZephyrBuildConfiguration package
The ZephyrBuildConfiguration package allow downstream users to control
the Zephyr build system using a cmake package.

A Zephyr Build Configuration package allows for setting of additional
DTS_ROOT, BOARD_ROOT, and similar variables without having to patch
Zephyr repo, but it also allows for inclusion of additional boilerplate
code for more advanced use cases.

The repository or folder containing the Zephyr Build Configuration
package must be on toplevel in the Zephyr workspace.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-05-27 17:58:50 +02:00
Martí Bolívar 3ea8293ef0 Revert "cmake: introduction of ZephyrExtension package"
This reverts commit ac898bc49e.

This commit was merged by mistake, but in a way that was against the
decision of the TSC on May 20, 2020, which was to wait a week to let
people digest befor merging.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-21 00:33:06 +02:00
Torsten Rasmussen ac898bc49e cmake: introduction of ZephyrExtension package
The ZephyrExtension package allow downstream users to extend the current
Zephyr package.
A ZephyrExtension package allows for setting of additional DTS_ROOT,
BOARD_ROOT, and similar variables without having to patch Zephyr repo.

The repository or folder containing the ZephyrExtension package must be
on toplevel in the Zephyr workspace.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-05-20 19:27:15 +02:00
Jukka Rissanen c6a19a2046 cmake: qemu: Allow user to add parameters to Ethernet TAP
User can now add extra Ethernet TAP parameters when starting QEMU.
This is useful if we want to set for example the MAC address
of the network interface.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-05-20 15:36:39 +02:00
Bilal Wasim 54550c04eb net: qemu: Adding support for User Networking
Added support for Qemu User Networking and tested with
qemu_x86 model. The support is kept simple assuming that
the TAP interface will always be preferred for more
sophisticated / practical use cases.

QEMU User Networking is implemented using "slirp", which
provides a full TCP/IP stack within QEMU and uses that
stack to implement a virtual NAT'd network. As this
support is built into QEMU, it can be used with any model
and requires no admin privileges on the host machine,
unlike TAP.

Added documentation to facilitate the user.

Signed-off-by: Bilal Wasim <bilalwasim676@gmail.com>
2020-05-08 10:47:38 +02:00
Torsten Rasmussen b6c18dde1f cmake: board alias message when hiding existing board
This commit will print a CMake notice if a user defines a board alias
that is identical to an existing board name.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-04-09 14:38:36 +02:00
Peter A. Bigot c790783c2e cmake: add support for user-defined board aliases
Zephyr board names must be globally unique which requires that they
encode all necessary information to identify a specific target.
Typing in these names can be inconvenient to developers working on
multiple targets within a single workspace.

Extend the cmake infrastructure to read an optional board aliases file
that will map custom aliases to the corresponding canonical Zephyr
board name.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2020-04-09 14:38:36 +02:00
Torsten Rasmussen db0b4e15e9 doc: Update documentation to describe use of find_package(Zephyr)
This commit changes the current boilerplate include description and
instead describes the use of find_package(Zephyr)

It also add a section covering additional possibilities when using
find_package(Zephyr).

- Search order
- Zephyr repository application description
- Zephyr workspace application description
- Zephyr freestanding application description
- Environment ZEPHYR_BASE setting
- Multiple Zephyr and preference setting

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-03-27 16:23:46 +01:00
Torsten Rasmussen d7862cf776 cmake: using ${ZEPHYR_BASE} instead of $ENV{ZEPHYR_BASE}
With the introduction of ZephyrConfig.cmake all parts of CMake code
should rely on the CMake ZEPHYR_BASE variable instead of the environment
setting.

This ensures that after the first CMake invocation, then all subsequent
invocation in same build folder will use same zephyr base.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-03-27 16:23:46 +01:00
Sebastian Bøe a8e90cbfb3 cmake: Fix shield bug when BOARD_ROOT is a list
Fix bug where SHIELDS would be marked as "not found" in the
NOT_FOUND_SHIELD_LIST when they were present, just not in the first
BOARD root in the BOARD_ROOT list.

Instead of marking shields in the NOT_FOUND_SHIELD_LIST, we (continue)
popping shields from SHIELD and check if there are any shields left in
SHIELD.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2020-03-25 20:23:09 +01:00
Torsten Rasmussen 1bc640b972 cmake: deprecation of board names
This commit introduces boards/deprecated.cmake to allow deprecation
of existing boards, when a board is renamed.

This allows users to still specify the old board name, and let Zephyr
build system to select the new board name.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-03-24 11:45:27 +01:00
Martí Bolívar 34a59168d5 build: clean up west build
The header printed at the beginning of every west build is kind of
annoying. Let's remove it and just print the application source
directory at cmake time instead. The build directory and board are
already printed there, anyway, and that's all IDE users will see.

Let's clean up the BOARD to make it say "board" instead. That matches
the west build --board option name a bit more closely and is still
legible.

Likewise, let's not print any west build messages if we're just
incrementally recompiling. That's noisy.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-03-10 14:53:28 +02:00
Jukka Rissanen c03336e442 cmake: Allow change of the QEMU Ethernet interface name
Instead of hardcoding the "zeth" network interface name, use the
name defined in Kconfig so that user can change it if needed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-03-10 14:38:28 +02:00
Andrei Gansari 37af9cb065 cmake: allow boards to have extra cmake parametes
This commit allows boards to have custom cmake parameters that are
loaded before device tree is processed.

Signed-off-by: Andrei Gansari <andrei.gansari@nxp.com>
2020-02-05 13:04:44 -06:00
Torsten Rasmussen 1f9723af19 cmake: app mem partion flexibility
This commit allows a more dynamic approach for specifying that a zephyr
library must be placed in a dedicated app memomory partition.
This is still done by defining the partition in code using
K_APPMEM_PARTITION_DEFINE, but now the zephyr library can be added to
the generation of partition table using zephyr_library_app_memory
instead of modifying the overall zephyr/CMakeLists.txt file.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2019-11-05 08:44:26 -08:00
Peter Bigot 0582a0c1bf cmake: add app boards subdir as search location for board overlay files
Putting overlay files in the test/sample root clutters the file
system.  Allow them to be in the boards subdirectory alongside
board.conf files.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-10-01 20:38:24 -07:00
Sebastian Bøe bb6a6e8fcc cmake: Move the invocation of 'project' earlier
The CMake documentation for 'project' states "Call the project()
command near the top of the top-level CMakeLists.txt". Meaning, it
should be run as early as possible.

An obscure internal error was observed when 'project' was located in
zephyr/CMakeLists.txt and was observed to be fixed after moving
'project' earlier, hence this patch that moves it earlier.

Invoking project depends on knowing information about the toolchain so
it is placed after target_toolchain.cmake.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-10-01 06:26:03 -05:00
Laczen JMS 78170ecd18 cmake: app: set zephyr_extra_modules from environment
This PR adds the possibility to specify ZEPHYR_EXTRA_MODULES from an
environmental variable. To add a custom module mymodule in
path/mymodule the variable ZEPHYR_EXTRA_MODULES can be set in
`.zephyrrc` as `export ZEPHYR_EXTRA_MODULES=path/mymodule`.

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-09-25 05:10:44 -04:00
Kumar Gala 2f1cd9bf0a cmake: add new search locations for shield overlay and conf files
* Add support to search for a board specific shield in
  <SHIELD DIR>/boards/<SHIELD>/<BOARD>.{overlay,conf}.  So we can
  support something like:

  x_nucleo_iks01a3/boards/x_nucleo_iks01a3_shub/stm32mp157c_dk2.overlay
  x_nucleo_iks01a3/boards/x_nucleo_iks01a3_shub/stm32mp157c_dk2.conf

Fixes #19078

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-09-12 07:17:49 -05:00
Kumar Gala b170d829f8 cmake: Fixup shield overlay and conf file search locations
* Fix dir name when shield name doesn't match the dir name.  So for
  shield 'x_nucleo_iks01a3_shub' we will look in now for
  x_nucleo_iks01a3/boards/<BOARD>.{overlay,conf} instead of
  x_nucleo_iks01a3_shub/boards/<BOARD>.{overlay,conf}

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-09-12 07:17:49 -05:00
Kumar Gala 88c4cd8273 cmake: move shield board/conf handling
Move handling for shield boards/board.overlay, shield.conf and
boards/board.conf inside the SHIELD_LIST check.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-09-12 07:17:49 -05:00
Carles Cufi 764f07c2a4 Revert "cmake: Error-out when 'project' is invoked too early"
This reverts commit 48f97ecf46.

This is causing CI failures, so revert for now.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-09-07 21:42:55 +02:00
Sebastian Bøe 48f97ecf46 cmake: Error-out when 'project' is invoked too early
Error-out when 'project' is invoked before boilerplate.cmake is
included. This is not supported and causes obscure errors.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-09-07 10:05:17 -04:00
Anas Nashif d6426226cb build: dts: also look for application specific dts overlay
Not all DTS changes are board specific and we should support overlays
that can be used with multiple boards. For example with a sensor, for
example:

Use this overlay for a sensor:

	&arduino_i2c {
		bme280@76 {
			compatible = "bosch,bme280";
			reg = <0x76>;
			label = "BME280";
		};
	};

This will work with any board that has &arduino_i2c defined, but should
also work if you specify the instance directly (&i2c0 or &i2c1).

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-07-12 05:54:16 -07:00
Marc Herbert d3d3394893 cmake: warn if inconsistency between CMAKE_SOURCE_DIR and ZEPHYR_BASE
cmake has a number of issues dealing with symbolic links:

  https://gitlab.kitware.com/cmake/cmake/issues/16228

One of them can cause cmake to rewrite the -S input from the user and
CMAKE_SOURCE_DIR to unexpectedly include symbolic links:

  https://cmake.org/pipermail/cmake/2019-May/thread.html#69496

Catch this corner case and warn about subtle issues like breaking
-fmacro-prefix-map=${ZEPHYR_BASE}=

Sample warning message:

CMake Warning at ../../CMakeLists.txt:30 (message):
  ZEPHYR_BASE doesn't match CMAKE_CURRENT_SOURCE_DIR

    ZEPHYR_BASE              = ~/zephyrproject/zephyr
    PWD                      = ~/westsymlink/zephyr/samples/hello_world
    CMAKE_CURRENT_SOURCE_DIR = ~/westsymlink/zephyr

  You may be using a mix of symbolic links and real paths which causes
  subtle and hard to debug CMake issues.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2019-06-11 12:57:18 -04:00
Carles Cufi b73790b629 cmake: Fix path handling for ZEPHYR_BASE
With the addition of a local CMake variable ZEPHYR_BASE that mirrors the
value of the environment variable the documentation build broke on
Windows. This is because CMake was incorrectly interpreting backslashes
present in the Windows path as escaping characters. In order to avoid
this, use CMake's built-in file(TO_CMAKE_PATH) functionality, which
converts the path to a canonical version using forward slashes only.
At the same time rework boilerplate.cmake to use the same mechanism
instead of manually replacing backslashes and removing trailing ones.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-05-24 11:05:04 +02:00
Michael Scott 421b426281 cmake: add handling for shield config and shield/board overlays
Shields can often be very complex to setup in a generic way for several
boards to support.  Let's allow shields to have their own .conf files
as well as specialized overlays per board (when needed).

Signed-off-by: Michael Scott <mike@foundries.io>
2019-05-21 08:17:20 -04:00
Øyvind Rønningstad f2a1572ac2 cmake: Add function for adding snippets to the linker file
Allows snippets to be placed in different locations:
 - The noinit, rwdata and rodata output sections
 - Two different locations for placing custom output sections,
   one location for RAM and another for all other sections.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2019-05-20 22:28:28 -04:00
Sigvart Hovland 3ffdcf4fca cmake: boilerplate: Fix ZEPHYR_BASE variable for windows
In windows an additional / is added when using zephyr-env.cmd
this causes a build error in some scenarios. It also creates
ugly file paths.

Signed-off-by: Sigvart Hovland <sigvart.hovland@nordicsemi.no>
2019-04-18 17:51:47 -04:00
Marcin Szymczyk fa0083ad0e cmake: fix support for out of tree shields
After the rework in #12403, specifying a shield which has overlay
out of the tree causes unnecessary inclusions of overlays.
For every board root, overlays that have same index as
expected overlay are being included.
Fix this by removing already included overlays from SHIELD list.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
2019-04-17 10:35:11 -05:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Sebastian Bøe 6d4ba3490f cmake: Deprecate 'set_conf_file'
In-tree, all usage of 'set_conf_file' is implementing the same
pattern (with some inconsequential differences).

To reduce copy-paste and get closer to dropping support for
'set_conf_file', we include this pattern into the built-in set of
patterns.

'set_conf_file' is causing issues for future extensions,
e.g. multi-image support, and is also the source of a lot of
duplicated code.

Note support for 'set_conf_file' is not dropped, it is only marked as
deprecated.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-03-01 09:44:09 +01:00
Sebastian Bøe ea57a9fb7d cmake: Omit comments that are either redunant or wrong
Drop these CMake comments. It is redundant with a below comment to
describe 'app', and it is incorrect to state that omitting
boilerplate.cmake is permitted/supported.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-02-27 08:50:59 -06:00
Sebastian Bøe 1108e38a01 cmake: Omit if statement that is always true
We had an if-statement around policy 79 because we used to need to
support CMake versions before 3.13.0. But now 3.13.1 is the minimum
required version so the if statement always evaluates to true and can
be omitted.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-02-27 08:50:59 -06:00
Torsten Rasmussen 7e9d1bdda4 CMake/Kconfig: CMake and Kconfig build integration
This commit allows for Zephyr modules to be natively integrated into
the build system with CMakeLists.txt and Kconfig files.

The sourcing of module files are done in following order:
- If <module>/zephyr/module.yml exists, use cmake and kconfig settings
  for sourcing of additional file
- Else if <module>/zephyr/CMakeLists.txt exists, source this file into
  CMake build tree and add <module>/zephyr/Kconfig as osource

If none of the above files are present, the project is considered to
not be a Zephyr module

Signed-off-by: Torsten Rasmussen <torsten.rasmussen@nordicsemi.no>
2019-02-08 22:47:02 -05:00
Klaus Petersen c66cb76fed Build: Added support for out-of-tree Arch
Introduces the ARCH_ROOT argument, similar to BOARD_ROOT and SOC_ROOT.
This enables support for out-of-tree architectures.

The ARCH_ROOT out-of-tree layout is expected to be the following:
 * ${ARCH_ROOT}/arch/${ARCH}/
 * ${ARCH_ROOT}/include/arch/${ARCH}/ (Optional)

Signed-off-by: Klaus Petersen <kape@oticon.com>
2019-02-07 17:00:43 -05:00
Kumar Gala 4b4b9bc49b cmake: Run dts before kconfig
Based on work from Sebastian Bøe and updated to current tree.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-01 10:16:06 -06:00
Erwan Gouriou 0115c47b69 cmake: dts: move to specifying shield on the command line
Rather than specifying SHIELD via Kconfig, we move it to being
specified via the command line, similar to board.

So we can do:

  -DSHIELD=x_nucleo_iks01a1

or, for multiple shields:

  -DSHIELD="x_nucleo_iks01a1 frdm_kw41z"

Following cmake change, update x_nucleo_iks01a1 sample in order
not to enable CONFIG option anymore but set SHIELD cmake option.

Last, update documentation to reflect this change.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-01-18 13:20:59 -06:00
Anas Nashif 5060ca6a30 cmake: increase minimal required version to 3.13.1
Move to latest cmake version with many bug fixes and enhancements.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-01-03 11:51:29 -05:00
Mark Ruvald Pedersen 55d6b4cd7c cmake: boilerplate: Move out finding git+python to separate cmake files
Follow the same convention as that of ccache.
Improve readability of boilerplate.cmake file.
Move inclusion of version.cmake up to satisfy git.cmake dependency.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-12-27 19:24:51 -05:00
Mark Ruvald Pedersen 0efad5f7fd cmake: Whitespace and commentary fixes
Cosmetics, no functional change expected.
Fixed leading space alignment.
Replaced tabs with spaces.
Emulation error message output is now aligned.

To locate tabs in cmake, the following bash is useful:
grep -PRil "\t" * | grep -i cmake | grep -v ^sanity

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-12-20 12:23:50 +01:00
Mark Ruvald Pedersen 6e158b1794 cmake: Document CMAKE_SYSTEM_-variables, and add CMAKE_SYSTEM_VERSION
Aid user in understanding what CMake expects of:

 * Document and add CMAKE_SYSTEM_VERSION
 * Document CMAKE_SYSTEM_NAME
 * Document CMAKE_SYSTEM_PROCESSOR
 * Document BUILD_SHARED_LIBS
 * Document Policies CMP0002, CMP0079

CMAKE_SYSTEM_VERSION is required officially by CMake, but appears
unused -- at least now we are compliant.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-12-20 11:15:20 +01:00
Mark Ruvald Pedersen 94a9d8086c cmake: boilerplate: move compiler-flag checks into boilerplate
CheckCCompilerFlag and CheckCXXCompilerFlag does not belong to
extensions.cmake since they are standard CMake files. Boilerplate
seems more appropriate.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-12-20 11:14:20 +01:00
Mark Ruvald Pedersen 722f86652c cmake: boilerplate: Move app-library to be with its documentation
Move documentation and declaration to be in the same place.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-12-20 11:13:44 +01:00
Sebastian Bøe a0a63ac344 cmake: Split toolchain configuration into pre-and post-DT
Split up the toolchain configuration into two phases, generic and
target. The 'generic' phase configures the toolchain just enough to be
able to preprocess DT files. The 'target' phase completes the
configuration with target-specific configuration.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-12-14 13:16:28 +01:00
Sebastian Bøe dc04f552b0 cmake: Fix warning related to policy CMP0079
In CMake 3.13 a warning is produced if one does not explicitly state
what the policy for CMP0079 should be. To resolve this warning we set
policy CMP0079 to OLD.

This is expected to have no semantical change. When we want a
semantical change we can flip the policy and port the build scripts to
the new behaviour.

This fixes #11794

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-12-07 11:32:08 -05:00
Adithya Baglody 62e152a8f0 cmake: Added rule and helper functions for code relocation.
This patch creates a rule in the cmake to trigger the generation
of linker_relocate.ld and code_relocation.c files.
The linker_relocate.ld will create appropriate sections and will
link the required functions or variables from all the selected
files.
The code_relocation.c will have code that is needed for
initializing data sections and copy of text sections(if XIP).
Also this will contain code that is needed for zeroing of bss.

The procedure to invoke this feature is:
1. Enable CONFIG_CODE_RELOCATION in the prj.conf

2. Inside CMakeList.txt in the project we need to mention
   all the files that needs to get relocated.

   zephyr_kernel_code_relocate(src/*.c SRAM2)

   Where the first argument is the file/files and the second
   argument is the memory where it has be placed.
   NOTE: The file argument supports glob expressions.

NOTE: Step 2 can be done as many times as required. And relative
paths can be given here.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-12-07 10:32:41 -05:00