- Notifications
You must be signed in to change notification settings - Fork 8.2k
Zephyr base improvement #23054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zephyr base improvement #23054
Conversation
When ZephyrConfig package is being version checked, then ZephyrConfigVersion.cmake loads version.cmake. This causes a print message, such as the following to happen: -- Zephyr version: 2.2.0 Now, in case a user has multiple Zephyr installations, this could result in something similar to: -- Zephyr version: 2.2.0 -- Zephyr version: 2.x.0 -- Zephyr version: 3.x.0 being printed. This commit add the possibility to disable version printing. With new Zephyr base find_package, printing of ZEPHYR_BASE is added after the version, in order to make it easy for users to see which Zephyr is used. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no> Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no> suggested change: print ZEPHYR_BASE
This commit adds the possibility of using a Zephyr repository package base even when it has not been exported to CMake package registry. It also introduces the possibility of locating and using Zephyr CMake config package correctly when invoking CMake on an out-of-tree project. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit introduces ZEPHYR_BASE as a cached variable, ensures that once ZEPHYR_BASE has been set in a project, it is sticky. Using cached variable also allows users to reconfigure ZEPHYR_BASE if they so wish. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Adding ZephyrUnittestConfig.cmake and ZephyrUnittestConfigVersion.cmake to allow unittest projects to use find_package to locate ZephyrUnittest. This means that it will be possible to allow users to run CMake without the need to source zephyr-env.sh or run zephyr-env.cmd. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Using find_package to locate Zephyr. Old behavior was to use $ENV{ZEPHYR_BASE} for inclusion of boiler plate code. Whenever an automatic run of CMake happend by the build system / IDE then it was required that ZEPHYR_BASE was defined. Using ZEPHYR_BASE only to locate the Zephyr package allows CMake to cache the base variable and thus allowing subsequent invocation even if ZEPHYR_BASE is not set in the environment. It also removes the risk of strange build results if a user switchs between different Zephyr based project folders and forgetting to reset ZEPHYR_BASE before running ninja / make. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no> Changing ZEPHYR_BASE throughout Zephyr tests and samples revealed that intel s1000 crb cache test case could not be run on CI. This has now been fixed by moving the tests file located in tests/board/intel_s1000_crb folder into tests/board/intel_s1000_crb/main instead so there is now main and cache folders with test projects. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Fixed usage build target. Previously, `ninja usage` would print: Build flags: ninja VERBOSE=1 [targets] verbose build This is clearly wrong, as VERBOSE=1 is for make targets. To support both ninja based builds and make based build systems, the CMAKE_MAKE_PROGRAM is now exported from the calling CMake / build instance, and the verbose flag is set depending on whether ninja or make is used as build program. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
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>
West utilizes Zephyr base when invoked out-of-tree in order to determine west topdir. This commit ensures that zephyr base when invoking west from CMake is set to current zephyr base. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This command make it possible to use west for first time registration of a Zephyr config package in CMake. To register Zephyr as a CMake config package, invoke: west zephyr-export Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit introduces ZEPHYR_PREFER which is a list that user can specify when compiling an application. This allows a user who has multiple Zephyr installations in the same work-tree to provide a list of which Zephyr to prefer. This is an extension to CMake VERSION field, as a user who is working with multiple Zephyr installations could face a situation where multiple Zephyr's is having same version, as example 2.2.99, in which case CMake version is not sufficient. Example, workspace looking as: /projects/workspace/zephyr /projects/workspace/zephyr-alternate /projects/workspace/zephyr-wip /projects/workspace/my_app To prefer zephyr-alternate, then zephyr-wip the my_app/CMakeLists.txt should look as: set(ZEPHYR_PREFER "zephyr-alternate" "zephyr-wip") find_package(Zephyr) Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit includes the following fixes in order to remove environment setting of ZEPHYR_BASE is west extension commands. - Build command west build --pristine will now use the ZEPHYR_BASE variable found in CMakeCache.txt in the build folder. This ensures that the pristine command is executed from the same Zephyr that was used for compilation. - Board command The west boards command no longer sets Zephyr base before invoking cmake -P cmake/boards.cmake Instead boards.cmake uses find_package(Zephyr) to ensure consistent behavior with Zephyr samples, so that the detection of Zephyr base is uniform across CMake commands. It also changes BOARD_ROOT_SPACE_SEPARATED to BOARD_ROOT in order to be consistent with existing user documentation. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no> Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
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>
c18f564 to 29b5548 Compare | I'm still running full CI with this Any comments to doc can be addressed separately, as they a just minor improvements in phrasing. |
| i had CI run the ~50k builds but then something went bad at the end with the run, so do not have the exact results... It looked good in general. I think we should merge, look at first daily build after merge and fix any potential issues raised by daily build. |
I agree, let's merge and deal with the aftermath in subsequent PRs. I don't think we'll ever get closer to merging this. |
Since zephyrproject-rtos/zephyr#23054 then ZEPHYR_BASE should be used as a CMake variable. See also: d7862cf77686e607fcce776df1da6a800315bac8 in Zephyr repo. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Since zephyrproject-rtos/zephyr#23054 then ZEPHYR_BASE should be used as a CMake variable. See also: d7862cf77686e607fcce776df1da6a800315bac8 in Zephyr repo. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This PR introduces Zephyr Config package for CMake.
Today, working with Zephyr / CMake requires users to always set
ZEPHYR_BASE.This can be done in a couple of different ways, depending on OS and shell being used (manually sourcing zephyr-env.sh, sourced in bashrc, running zephyr-env.cmd, etc.)
Or when using
west buildthenZEPHYR_BASEis set automatically.Unfortunately, using an environment variable in the build system has a couple of flaws.
A couple of examples, see further down for details:
west buildis incompatible with command lineninjaif user does not setZEPHYR_BASEafter runningwestcmake -G'Eclipse CDT4 - Ninja'and Eclipse, requires re-launching of Eclipse if switching to another project that uses a different Zephyr base.west buildExample (zephyr-env.shnot sourced as that is not required forwest):Terminal 1)
$ cmake -G'Eclipse CDT4 - Ninja' -DBOARD=nrf52840_pca10056
Terminal 2 or Desktop shortcut (not sourcing `zephyr-env.sh), Eclipse error:
Having multiple Zephyrs and sourcing wrong one
as seen, the Zephyr base was wrong, but everything worked.
This might give unexpected results later.
Zephyr base changed between CMake and Ninja invocation.
This could happen to someone running CMake and ninja in a projectA.
Change into projectB to do some work, and sets
ZEPHYR_BASEto projectB.Switch back to projectA, forgetting to set
ZEPHYR_BASEand executeninjaIn this case, an error was printed to user, but in case the two Zephyr's are very close, it could happen that everything worked, and in that case harder to detect when things break.
Fixes in this PR:
ZEPHYR_BASE, theZEPHYR_BASEthat was set for the first CMake invocation in current build folder should be sticky, that is if CMake is re-invoked due to changes in any file, then the sameZEPHYR_BASEshould be used.west buildandninjato work better together.ZEPHYR_BASEfor majority of usersZEPHYR_BASEand allow it to support advange use-casesWith this PR, Zephyr now has a CMake config package.
A one-time install must be done in a Zephyr. (multiple install are allowed but not required).
To do this install, run:
Once installed, users can now do:
as seen, no
ZEPHYR_BASEwas set.and also out-of-tree builds are supported this way:
Using
ZEPHYR_BASEand enforcing another Zephyr is also possible:Creating a project also becomes much cleaner, all a user has to do, is to use
find_package.To create an application, you'll write:
This has some additional benefits, such as requesting only to compile against an exact match:
or simply accept any Zephyr:
To install Zephyr as a package, do the following:
Or manually:
Example of
west/ninjafix:Things still ToDo:
[X] - Update documentation to described workflow (depends on feedback to this PR)
[X] - Create
westextension command to make easy Zephyr config package install (instead ofcmake .)