Difference between revisions of "Cmake"
m (→Install latest version of cmake) |
m (→^ Source and Library Path Setting) |
||
(34 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
[[Zephyr_building_blocks|Zephyr RTOS building blocks]] :: [[Device_tree|Device Tree Source]] :: [[Kconfig|Kconfig]] :: [[cmake|cmake]] :: [[west_manifest_files|`west` manifest files]] | [[Zephyr_building_blocks|Zephyr RTOS building blocks]] :: [[Device_tree|Device Tree Source]] :: [[Kconfig|Kconfig]] :: [[cmake|cmake]] :: [[west_manifest_files|`west` manifest files]] | ||
</center> | </center> | ||
+ | |||
+ | Keywords and noteworthy: [[#nn_anchor_zephyr_app_common_code|Zephyr app common code]] | ||
<!-- comment --> | <!-- comment --> | ||
+ | - Overview - | ||
+ | |||
+ | This page a starting point for cmake notes and links to references about cmake.<!-- comentario --> | ||
+ | |||
+ | |||
+ | <!-- comentario --> | ||
+ | |||
+ | == [[#top|^]] Configuration Stage and Build Stage of Cmake == | ||
+ | |||
+ | * https://docs.zephyrproject.org/3.1.0/build/cmake/index.html | ||
+ | |||
+ | <!-- comentario --> | ||
+ | |||
+ | == [[#top|^]] Important Reading == | ||
+ | |||
+ | Following sections link to and add notes about some higher level areas of cmake. | ||
+ | |||
+ | === [[#top|^]] cmake Policies === | ||
+ | |||
+ | https://cmake.org/cmake/help/v2.8.12/cmake.html#section_Policies | ||
+ | |||
+ | <!-- odne komentar --> | ||
+ | |||
+ | === [[#top|^]] cmake Commands === | ||
+ | |||
+ | * https://cmake.org/cmake/help/v2.8.12/cmake.html#section_Commands | ||
+ | |||
+ | <!-- odne komentar --> | ||
+ | |||
+ | == [[#top|^]] Practical Things to Know and Do == | ||
+ | |||
+ | <i>stub section intro</i> | ||
+ | <!-- comentario --> | ||
+ | === [[#top|^]] To Debug Cmake Scripts === | ||
+ | |||
+ | A gitlab dot io cmake resource: | ||
+ | |||
+ | * https://cliutils.gitlab.io/modern-cmake/chapters/features/debug.html | ||
+ | |||
+ | Note that the following post has a cool answer which involves a cmake macro to print all variables known to a given cmake invocation or use, and also a more simple answer to print one specific variable: | ||
+ | * https://stackoverflow.com/questions/31343813/displaying-cmake-variables | ||
+ | |||
+ | <!-- | ||
+ | - ANSWER 1 - | ||
+ | |||
+ | You asked: (1) Is there an easy way to display these variables without having to run cmake on a CMakeLists.txt file, and (2) without having to manually inspect the config.cmake file? | ||
+ | |||
+ | I can give you a yes answer to (2) but it does require that you (re)run cmake. But since you can re-run your cmake configure step by simply executing cmake . in the build directory, re-running cmake should not keep you from trying this approach. My answer is given in this SO answer and uses the get_cmake_property command. Here is that code encapsulated into a cmake macro, print_all_variables, so I can use it when debugging my cmake scripts. | ||
+ | |||
+ | macro(print_all_variables) | ||
+ | message(STATUS "print_all_variables------------------------------------------{") | ||
+ | get_cmake_property(_variableNames VARIABLES) | ||
+ | foreach (_variableName ${_variableNames}) | ||
+ | message(STATUS "${_variableName}=${${_variableName}}") | ||
+ | endforeach() | ||
+ | message(STATUS "print_all_variables------------------------------------------}") | ||
+ | endmacro() | ||
+ | |||
+ | The macros are invoked with same syntax as cmake functions: | ||
+ | |||
+ | print_all_variables() | ||
+ | |||
+ | |||
+ | |||
+ | - ANSWER 2 - | ||
+ | |||
+ | To simply print a value, you could do something like this: | ||
+ | |||
+ | message(STATUS "foo include dir: ${foo_INCLUDE}") | ||
+ | |||
+ | where ${foo_INCLUDE} is the value you desire to print. | ||
+ | |||
+ | Note: I'm using cmake > 3.14 | ||
+ | |||
+ | ---------- ---------- --------- --------- --------- -------- | ||
+ | --> | ||
+ | |||
+ | A modified generic.cmake file, changes address one or more unset variables and solved build error on newest Zephyr work station: | ||
+ | |||
+ | <pre> | ||
+ | # SPDX-License-Identifier: Apache-2.0 | ||
+ | |||
+ | set_ifndef(CC gcc) | ||
+ | |||
+ | ## 2022-03-03 - Ted moving this cmake function call beyond locally | ||
+ | ## added variable assignements: | ||
+ | ## | ||
+ | ## find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}${CC} PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) | ||
+ | |||
+ | # | ||
+ | ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
+ | ## 2022-02-08 Reference https://cmake.org/cmake/help/latest/command/message.html | ||
+ | ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
+ | # | ||
+ | message(NOTICE "*** zztop 1 *** building with user configuration var ZEPHYR_TOOLCHAIN_VARIANT set to '${ZEPHYR_TOOLCHAIN_VARIANT}'") | ||
+ | message(NOTICE "*** zztop 2 *** internal variable CROSS_COMPILE set to '${CROSS_COMPILE}'") | ||
+ | message(NOTICE "*** zztop 3 *** internal variable TOOLCHAIN_HOME set to '${TOOLCHAIN_HOME}'") | ||
+ | |||
+ | ## 2022-03-03 THU - Not ***ing sure why we need to set these today: | ||
+ | set(ZEPHYR_TOOLCHAIN_VARIANT gnuarmemb) | ||
+ | set(GNUARMEMB_TOOLCHAIN_PATH /opt/gcc-arm-none-eabi-10.3-2021.10) | ||
+ | set(TOOLCHAIN_HOME /opt/gcc-arm-none-eabi-10.3-2021.10) | ||
+ | ## ^^^ These three cmake variable settings not sufficient, trying another based on working but different | ||
+ | ## toolchain on host ind: | ||
+ | set(CROSS_COMPILE /opt/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-) | ||
+ | ## | ||
+ | ## $ ls /opt/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-* | ||
+ | ## | ||
+ | |||
+ | message(NOTICE "*** zztop 4 *** building with user configuration var ZEPHYR_TOOLCHAIN_VARIANT set to '${ZEPHYR_TOOLCHAIN_VARIANT}'") | ||
+ | message(NOTICE "*** zztop 5 *** internal variable CROSS_COMPILE set to '${CROSS_COMPILE}'") | ||
+ | message(NOTICE "*** zztop 6 *** internal variable TOOLCHAIN_HOME set to '${TOOLCHAIN_HOME}'") | ||
+ | |||
+ | |||
+ | find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}${CC} PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) | ||
− | + | if(CMAKE_C_COMPILER STREQUAL CMAKE_C_COMPILER-NOTFOUND) | |
+ | message(FATAL_ERROR "Zephyr was unable to find the toolchain. Is the environment misconfigured? | ||
+ | User-configuration: | ||
+ | ZEPHYR_TOOLCHAIN_VARIANT: ${ZEPHYR_TOOLCHAIN_VARIANT} | ||
+ | Internal variables: | ||
+ | CROSS_COMPILE: ${CROSS_COMPILE} | ||
+ | TOOLCHAIN_HOME: ${TOOLCHAIN_HOME} | ||
+ | ") | ||
+ | endif() | ||
+ | |||
+ | execute_process( | ||
+ | COMMAND ${CMAKE_C_COMPILER} --version | ||
+ | RESULT_VARIABLE ret | ||
+ | OUTPUT_QUIET | ||
+ | ERROR_QUIET | ||
+ | ) | ||
+ | if(ret) | ||
+ | message(FATAL_ERROR "Executing the below command failed. Are permissions set correctly? | ||
+ | '${CMAKE_C_COMPILER} --version' | ||
+ | " | ||
+ | ) | ||
+ | endif() | ||
+ | </pre> | ||
− | + | === [[#top|^]] Source and Library Path Setting === | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | Cmake has at least as of 2020 a notion of "translation map" which relates to the ways in which cmake determines file paths. One introduction to this concept arises at the forum post: | ||
− | + | * https://discourse.cmake.org/t/when-does-cmake-current-binary-dir-resolve-symlinks/809 | |
− | * https:// | + | * https://gitlab.kitware.com/cmake/cmake/-/issues/16228 |
+ | There is comment in cmake documentation that use of symbolic links can lead to subtle errors. Ted needs to locate this reference. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | Earlier references: | |
* https://cmake.org/cmake/help/latest/command/link_directories.html | * https://cmake.org/cmake/help/latest/command/link_directories.html | ||
+ | |||
+ | Cmake has a notion of a binary or binaries directory, and has a built-in variable CMAKE_BINARY_DIR as described here: | ||
+ | |||
+ | * https://cmake.org/cmake/help/latest/variable/CMAKE_BINARY_DIR.html?highlight=cmake_binary_dir | ||
+ | |||
+ | <!-- comment --> | ||
+ | |||
+ | === [[#top|^]] cmake Lists === | ||
+ | |||
+ | Look up `append_if_path_exists()` . . . | ||
+ | |||
+ | <!-- odne komentar --> | ||
+ | |||
+ | === [[#top|^]] cmake Functions === | ||
+ | |||
+ | An interesting pattern search in Zephyr 3.2.0 source tree and associated third party libraries is `$ grep -nr ExternalProject_Add ./*`, which reveals which projects and locations in Zephyr's source tree this cmake function is called. This function is needed when building multicore Zephyr apps. | ||
+ | |||
+ | There is a detailed document on `ExternalProject_Add()` at the Kitware public github repository: | ||
+ | |||
+ | <ul><!-- SUB-SECTION INDENT BEGIN --> | ||
+ | ==== [[#top|^]] ExternalProject_Add ==== | ||
+ | |||
+ | <!-- comment --> | ||
+ | |||
+ | Cmake function `ExternalProject_Add()` is used in multi-core Zephyr sample projects. Some refs to this function include: | ||
+ | |||
+ | * https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/ExternalProject.cmake | ||
+ | |||
+ | * https://cmake.org/cmake/help/latest/module/ExternalProject.html?highlight=externalproject_add#command:externalproject_add | ||
+ | |||
+ | * https://github.com/pyke369/sffmpeg/blob/master/CMakeLists.txt n . . . example of `INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR}/include)` | ||
+ | |||
+ | ==== [[#top|^]] find_package ==== | ||
<!-- comment --> | <!-- comment --> | ||
+ | |||
+ | * https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#manual:cmake-developer(7) | ||
+ | |||
+ | * https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#find-modules | ||
+ | |||
+ | <!-- comment --> | ||
+ | |||
+ | ==== [[#top|^]] add_subdirectory_ifdef() ==== | ||
+ | |||
+ | <span id="nn_anchor_zephyr_app_common_code"></span> | ||
+ | Really good blog post at blog.golioth.io regarding how to configure a "super project" containing multiple Zephyr based apps with shared, select-able at build time common code: | ||
+ | |||
+ | <ul> | ||
+ | * https://blog.golioth.io/cmake-and-kconfig-tricks-for-common-code-in-zephyr-apps/ | ||
+ | </ul> | ||
+ | <!-- odne komentar --> | ||
+ | ==== [[#top|^]] function() ==== | ||
+ | |||
+ | - stub - | ||
+ | <!-- odne komentar --> | ||
+ | ==== [[#top|^]] execute_process() ==== | ||
+ | |||
+ | - stub - | ||
+ | <!-- odne komentar --> | ||
+ | ==== [[#top|^]] add_custom_command() ==== | ||
+ | |||
+ | - stub - | ||
+ | <!-- odne komentar --> | ||
== [[#top|^]] Install latest version of cmake == | == [[#top|^]] Install latest version of cmake == | ||
Line 159: | Line 348: | ||
3,15522 gold badges88 silver badges9 | 3,15522 gold badges88 silver badges9 | ||
--> | --> | ||
+ | |||
+ | == [[#top|^]] cmake Package Configuration Files - What Are They? == | ||
+ | |||
+ | QUESTION (2022-12-29): what are cmake package configuration files? | ||
+ | |||
+ | When attempting to switch Zephyr sdk of original latest 2021 kionix-driver-demo, from Nordic ncs SDK to Zephyr RTOS Project itself, and a more recent release of Zephyr RTOS, get following error early early in build process: | ||
+ | |||
+ | <pre> | ||
+ | :~/projects-sandbox/workspace-out-of-tree/kionix-driver-demo$ west build -b lpcxpresso55s69_cpu0 -p | ||
+ | -- west build: making build dir /home/ted/projects-sandbox/workspace-out-of-tree/kionix-driver-demo/build pristine | ||
+ | -- west build: generating a build system | ||
+ | -- Build type: debug | ||
+ | Loading Zephyr default modules (Zephyr base). | ||
+ | -- Application: /home/ted/projects-sandbox/workspace-out-of-tree/kionix-driver-demo | ||
+ | -- Found Python3: /usr/bin/python3.8 (found suitable exact version "3.8.10") found components: Interpreter | ||
+ | -- Cache files will be written to: /home/ted/.cache/zephyr | ||
+ | -- Zephyr version: 3.1.0 (/home/ted/projects-sandbox/workspace-out-of-tree/zephyr) | ||
+ | -- Found west (found suitable version "0.12.0", minimum required is "0.7.1") | ||
+ | -- Board: lpcxpresso55s69_cpu0 | ||
+ | CMake Error at /home/ted/projects-sandbox/workspace-out-of-tree/zephyr/cmake/modules/verify-toolchain.cmake:79 (find_package): | ||
+ | Could not find a package configuration file provided by "Zephyr-sdk" | ||
+ | (requested version 0.13.1) with any of the following names: | ||
+ | |||
+ | Zephyr-sdkConfig.cmake | ||
+ | zephyr-sdk-config.cmake | ||
+ | |||
+ | Add the installation prefix of "Zephyr-sdk" to CMAKE_PREFIX_PATH or set | ||
+ | "Zephyr-sdk_DIR" to a directory containing one of the above files. If | ||
+ | "Zephyr-sdk" provides a separate development package or SDK, be sure it has | ||
+ | been installed. | ||
+ | Call Stack (most recent call first): | ||
+ | /home/ted/projects-sandbox/workspace-out-of-tree/zephyr/cmake/modules/zephyr_default.cmake:121 (include) | ||
+ | /home/ted/projects-sandbox/workspace-out-of-tree/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:51 (include) | ||
+ | /home/ted/projects-sandbox/workspace-out-of-tree/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:76 (include_boilerplate) | ||
+ | CMakeLists.txt:51 (find_package) | ||
+ | |||
+ | |||
+ | -- Configuring incomplete, errors occurred! | ||
+ | FATAL ERROR: command exited with status 1: /usr/bin/cmake -DWEST_PYTHON=/usr/bin/python3 -B/home/ted/projects-sandbox/workspace-out-of-tree/kionix-driver-demo/build -S/home/ted/projects-sandbox/workspace-out-of-tree/kionix-driver-demo -GNinja -DBOARD=lpcxpresso55s69_cpu0 | ||
+ | </pre> | ||
+ | |||
+ | So at time of above error we didn't know how to trace that problem, though there is a call stack reported by cmake which tells us some cmake files we may review for better understanding. There are notes on cmake's documentation pages as of 2022-12-27 which mention the naming conventions of files which cmake's find_package() will look for when it is invoked. | ||
+ | |||
+ | NEED to add link to cmake's find_package() documentation. | ||
+ | |||
+ | 2022-12-28 - some new cmake build errors: | ||
+ | |||
+ | (1) | ||
+ | |||
+ | <pre> | ||
+ | ted@localhost:~/projects/zephyr-based/out-of-tree/kionix-driver-demo$ west build -b lpcxpresso55s69_cpu0 -p | ||
+ | -- west build: making build dir /home/ted/projects/zephyr-based/out-of-tree/kionix-driver-demo/build pristine | ||
+ | -- west build: generating a build system | ||
+ | Loading Zephyr default modules (Zephyr base). | ||
+ | -- Application: /home/ted/projects/zephyr-based/out-of-tree/kionix-driver-demo | ||
+ | -- Found Python3: /usr/bin/python3.8 (found suitable exact version "3.8.10") found components: Interpreter | ||
+ | -- Cache files will be written to: /home/ted/.cache/zephyr | ||
+ | -- Zephyr version: 3.2.0 (/home/ted/projects/zephyr-based/out-of-tree/zephyr) | ||
+ | -- Found west (found suitable version "0.11.0", minimum required is "0.7.1") | ||
+ | -- Board: lpcxpresso55s69_cpu0 | ||
+ | -- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK | ||
+ | CMake Error at /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/modules/FindZephyr-sdk.cmake:63 (find_package): | ||
+ | Could not find a configuration file for package "Zephyr-sdk" that is | ||
+ | compatible with requested version "0.15". | ||
+ | |||
+ | The following configuration files were considered but not accepted: | ||
+ | |||
+ | /opt/zephyr-sdk-0.12.4/cmake/Zephyr-sdkConfig.cmake, version: 0.12.4 | ||
+ | /opt/zephyr-sdk-0.14.2/cmake/Zephyr-sdkConfig.cmake, version: 0.14.2 | ||
+ | /opt/zephyr-sdk-0.13.0/cmake/Zephyr-sdkConfig.cmake, version: 0.13.0 | ||
+ | |||
+ | Call Stack (most recent call first): | ||
+ | /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/modules/FindHostTools.cmake:53 (find_package) | ||
+ | /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/modules/dts.cmake:8 (find_package) | ||
+ | /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/modules/zephyr_default.cmake:108 (include) | ||
+ | /home/ted/projects/zephyr-based/out-of-tree/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include) | ||
+ | /home/ted/projects/zephyr-based/out-of-tree/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate) | ||
+ | CMakeLists.txt:15 (find_package) | ||
+ | |||
+ | |||
+ | -- Configuring incomplete, errors occurred! | ||
+ | FATAL ERROR: command exited with status 1: /usr/bin/cmake -DWEST_PYTHON=/usr/bin/python3 -B/home/ted/projects/zephyr-based/out-of-tree/kionix-driver-demo/build -GNinja -DBOARD=lpcxpresso55s69_cpu0 -S/home/ted/projects/zephyr-based/out-of-tree/kionix-driver-demo | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | After setting `ZEPHYR_TOOLCHAIN_VARIANT` in the current shell, get these cmake errors: | ||
+ | |||
+ | (2) | ||
+ | |||
+ | <pre> | ||
+ | ted@localhost:~/projects/zephyr-based/out-of-tree/kionix-driver-demo$ export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb | ||
+ | ted@localhost:~/projects/zephyr-based/out-of-tree/kionix-driver-demo$ west build -b lpcxpresso55s69_cpu0 -p | ||
+ | -- west build: making build dir /home/ted/projects/zephyr-based/out-of-tree/kionix-driver-demo/build pristine | ||
+ | -- west build: generating a build system | ||
+ | Loading Zephyr default modules (Zephyr base). | ||
+ | -- Application: /home/ted/projects/zephyr-based/out-of-tree/kionix-driver-demo | ||
+ | -- Found Python3: /usr/bin/python3.8 (found suitable exact version "3.8.10") found components: Interpreter | ||
+ | -- Cache files will be written to: /home/ted/.cache/zephyr | ||
+ | -- Zephyr version: 3.2.0 (/home/ted/projects/zephyr-based/out-of-tree/zephyr) | ||
+ | -- Found west (found suitable version "0.11.0", minimum required is "0.7.1") | ||
+ | -- Board: lpcxpresso55s69_cpu0 | ||
+ | CMake Error at /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/modules/extensions.cmake:2071 (message): | ||
+ | Assertion failed: GNUARMEMB_TOOLCHAIN_PATH is not set | ||
+ | Call Stack (most recent call first): | ||
+ | /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/toolchain/gnuarmemb/generic.cmake:4 (assert) | ||
+ | /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/modules/FindHostTools.cmake:103 (include) | ||
+ | /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/modules/dts.cmake:8 (find_package) | ||
+ | /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/modules/zephyr_default.cmake:108 (include) | ||
+ | /home/ted/projects/zephyr-based/out-of-tree/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include) | ||
+ | /home/ted/projects/zephyr-based/out-of-tree/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate) | ||
+ | CMakeLists.txt:15 (find_package) | ||
+ | |||
+ | |||
+ | -- Configuring incomplete, errors occurred! | ||
+ | FATAL ERROR: command exited with status 1: /usr/bin/cmake -DWEST_PYTHON=/usr/bin/python3 -B/home/ted/projects/zephyr-based/out-of-tree/kionix-driver-demo/build -GNinja -DBOARD=lpcxpresso55s69_cpu0 -S/home/ted/projects/zephyr-based/out-of-tree/kionix-driver-demo | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | <!-- comentario --> | ||
== [[#top|^]] Zephyr Threads Tutorial by Maksim Drachov == | == [[#top|^]] Zephyr Threads Tutorial by Maksim Drachov == | ||
+ | |||
+ | Developer [https://github.com/maksimdrachov Maksim Drachov] some helpful Zephyr build system and cmake tutorials, or explanatory documents on github. While not everything is explained, one of his example projects which builds a TCP/IP networking stack for a posix_native targeted board offers a number of more advanced cmake functions and features as part of this example project. | ||
+ | |||
+ | Earliest Maksim github link noted here is: | ||
* https://github.com/maksimdrachov/zephyr-rtos-tutorial/commit/de52c7d5d564e4990f5659f60e24b487ffdd74ae | * https://github.com/maksimdrachov/zephyr-rtos-tutorial/commit/de52c7d5d564e4990f5659f60e24b487ffdd74ae | ||
− | + | <!-- comentario --> | |
+ | |||
+ | == [[#top|^]] cmake Debugging == | ||
+ | |||
+ | <pre> | ||
+ | -- Application: /home/ted/projects/zephyr-based/kionix-driver-demo | ||
+ | -- Zephyr version: 2.6.0-rc1 (/home/ted/projects/zephyr-based/zephyr), build: v2.6.0-rc1-ncs1 | ||
+ | -- Found Python3: /usr/bin/python3.8 (found suitable exact version "3.8.10") found components: Interpreter | ||
+ | -- Found west (found suitable version "0.12.0", minimum required is "0.7.1") | ||
+ | -- Board: sparkfun_thing_plus_nrf9160 | ||
+ | -- Cache files will be written to: /home/ted/.cache/zephyr | ||
+ | -- Found dtc: /usr/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6") | ||
+ | CMake Error at /home/ted/projects/zephyr-based/zephyr/cmake/toolchain/zephyr/generic.cmake:3 (if): | ||
+ | if given arguments: | ||
+ | |||
+ | "VERSION_LESS_EQUAL" "0.11.2" | ||
+ | |||
+ | Unknown arguments specified | ||
+ | Call Stack (most recent call first): | ||
+ | /home/ted/projects/zephyr-based/zephyr/cmake/generic_toolchain.cmake:36 (include) | ||
+ | /home/ted/projects/zephyr-based/zephyr/cmake/app/boilerplate.cmake:553 (include) | ||
+ | /home/ted/projects/zephyr-based/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include) | ||
+ | /home/ted/projects/zephyr-based/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate) | ||
+ | CMakeLists.txt:40 (find_package) | ||
+ | |||
+ | |||
+ | -- Configuring incomplete, errors occurred! | ||
+ | FATAL ERROR: command exited with status 1: /usr/bin/cmake -DWEST_PYTHON=/usr/bin/python3 -B/home/ted/projects/zephyr-based/kionix-driver-demo/build -S/home/ted/projects/zephyr-based/kionix-driver-demo -GNinja -DBOARD=sparkfun_thing_plus_nrf9160 | ||
+ | </pre> | ||
+ | |||
+ | <!-- comentario --> | ||
+ | |||
+ | == [[#top|^]] Cmake links to sort == | ||
+ | |||
+ | 2021-08-06 | ||
+ | |||
+ | Starting a page for <code>cmake</code> notes here. Links to cmake site: | ||
+ | <ul> | ||
+ | * https://cmake.org/cmake/help/latest/ | ||
+ | |||
+ | * https://cmake.org/overview/ | ||
+ | * https://cmake.org/examples/ . . . very limited, need other resources | ||
+ | </ul> | ||
+ | Longer guides: | ||
+ | <ul> | ||
+ | * https://cmake.org/cmake/help/v3.21/ | ||
+ | |||
+ | * https://cmake.org/getting-started/ | ||
+ | </ul> | ||
+ | |||
+ | |||
+ | A Nordic Semi document on `cmake` and its role in the build process of Zephyr based applications: | ||
+ | * https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/build/index.html | ||
+ | |||
+ | |||
+ | 2021-08-17 - search for cmake / Zephyr means to add sources to a Zephyr based project: | ||
+ | <ul> | ||
+ | * https://github.com/zephyrproject-rtos/zephyr/blob/main/cmake/extensions.cmake | ||
+ | * https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html | ||
+ | </ul> | ||
+ | == [[#top|^]] Topics To Follow Up == | ||
+ | |||
+ | Who accepts the `--extra-args=CONFIG_*` option plus value? From `zephyr/scripts/pylib/twister/twisterlib/testinstance.py`: | ||
+ | |||
+ | <pre> | ||
+ | 225 def create_overlay(self, platform, enable_asan=False, enable_ubsan=False, enable_coverage=False, coverage_platform=[]): | ||
+ | 226 # Create this in a "twister/" subdirectory otherwise this | ||
+ | 227 # will pass this overlay to kconfig.py *twice* and kconfig.cmake | ||
+ | 228 # will silently give that second time precedence over any | ||
+ | 229 # --extra-args=CONFIG_* | ||
+ | 230 subdir = os.path.join(self.build_dir, "twister") | ||
+ | 231 | ||
+ | 232 content = "" | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | In Zephyr 3.2.0, `zephyr/cmake/modules/configuration_files.cmake` looks promising in terms of revealing where and how Kconfig processing is called during build of a Zephyr based app. An excerpt from this file: | ||
+ | |||
+ | <pre> | ||
+ | 1 # SPDX-License-Identifier: Apache-2.0 | ||
+ | 2 # | ||
+ | 3 # Copyright (c) 2021, Nordic Semiconductor ASA | ||
+ | 4 | ||
+ | 5 # Zephyr build system configuration files. | ||
+ | 6 # | ||
+ | 7 # Locate the Kconfig and DT config files that are to be used. | ||
+ | 8 # Also, locate the appropriate application config directory. | ||
+ | 9 # | ||
+ | 10 # Outcome: | ||
+ | 11 # The following variables will be defined when this CMake module completes: | ||
+ | 12 # | ||
+ | 13 # - CONF_FILE: List of Kconfig fragments | ||
+ | 14 # - DTC_OVERLAY_FILE: List of devicetree overlay files | ||
+ | 15 # - APPLICATION_CONFIG_DIR: Root folder for application configuration | ||
+ | 16 # | ||
+ | 17 # If any of the above variables are already set when this CMake module is | ||
+ | 18 # loaded, then no changes to the variable will happen. | ||
+ | 19 # | ||
+ | 20 # Variables set by this module and not mentioned above are considered internal | ||
+ | 21 # use only and may be removed, renamed, or re-purposed without prior notice. | ||
+ | </pre> | ||
+ | |||
+ | <!-- comentario --> | ||
<center> | <center> | ||
[[#top|- - - top of page - - -]] | [[#top|- - - top of page - - -]] | ||
</center> | </center> | ||
− | |||
− | |||
− | |||
<!-- EOF --> | <!-- EOF --> |
Latest revision as of 15:45, 27 September 2024
Zephyr RTOS building blocks :: Device Tree Source :: Kconfig :: cmake :: `west` manifest files
Keywords and noteworthy: Zephyr app common code
- Overview -
This page a starting point for cmake notes and links to references about cmake.
Contents
- 1 ^ Configuration Stage and Build Stage of Cmake
- 2 ^ Important Reading
- 3 ^ Practical Things to Know and Do
- 4 ^ Install latest version of cmake
- 5 ^ cmake Package Configuration Files - What Are They?
- 6 ^ Zephyr Threads Tutorial by Maksim Drachov
- 7 ^ cmake Debugging
- 8 ^ Cmake links to sort
- 9 ^ Topics To Follow Up
^ Configuration Stage and Build Stage of Cmake
^ Important Reading
Following sections link to and add notes about some higher level areas of cmake.
^ cmake Policies
https://cmake.org/cmake/help/v2.8.12/cmake.html#section_Policies
^ cmake Commands
^ Practical Things to Know and Do
stub section intro
^ To Debug Cmake Scripts
A gitlab dot io cmake resource:
Note that the following post has a cool answer which involves a cmake macro to print all variables known to a given cmake invocation or use, and also a more simple answer to print one specific variable:
A modified generic.cmake file, changes address one or more unset variables and solved build error on newest Zephyr work station:
# SPDX-License-Identifier: Apache-2.0 set_ifndef(CC gcc) ## 2022-03-03 - Ted moving this cmake function call beyond locally ## added variable assignements: ## ## find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}${CC} PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) # ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ## 2022-02-08 Reference https://cmake.org/cmake/help/latest/command/message.html ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # message(NOTICE "*** zztop 1 *** building with user configuration var ZEPHYR_TOOLCHAIN_VARIANT set to '${ZEPHYR_TOOLCHAIN_VARIANT}'") message(NOTICE "*** zztop 2 *** internal variable CROSS_COMPILE set to '${CROSS_COMPILE}'") message(NOTICE "*** zztop 3 *** internal variable TOOLCHAIN_HOME set to '${TOOLCHAIN_HOME}'") ## 2022-03-03 THU - Not ***ing sure why we need to set these today: set(ZEPHYR_TOOLCHAIN_VARIANT gnuarmemb) set(GNUARMEMB_TOOLCHAIN_PATH /opt/gcc-arm-none-eabi-10.3-2021.10) set(TOOLCHAIN_HOME /opt/gcc-arm-none-eabi-10.3-2021.10) ## ^^^ These three cmake variable settings not sufficient, trying another based on working but different ## toolchain on host ind: set(CROSS_COMPILE /opt/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-) ## ## $ ls /opt/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-* ## message(NOTICE "*** zztop 4 *** building with user configuration var ZEPHYR_TOOLCHAIN_VARIANT set to '${ZEPHYR_TOOLCHAIN_VARIANT}'") message(NOTICE "*** zztop 5 *** internal variable CROSS_COMPILE set to '${CROSS_COMPILE}'") message(NOTICE "*** zztop 6 *** internal variable TOOLCHAIN_HOME set to '${TOOLCHAIN_HOME}'") find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}${CC} PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH) if(CMAKE_C_COMPILER STREQUAL CMAKE_C_COMPILER-NOTFOUND) message(FATAL_ERROR "Zephyr was unable to find the toolchain. Is the environment misconfigured? User-configuration: ZEPHYR_TOOLCHAIN_VARIANT: ${ZEPHYR_TOOLCHAIN_VARIANT} Internal variables: CROSS_COMPILE: ${CROSS_COMPILE} TOOLCHAIN_HOME: ${TOOLCHAIN_HOME} ") endif() execute_process( COMMAND ${CMAKE_C_COMPILER} --version RESULT_VARIABLE ret OUTPUT_QUIET ERROR_QUIET ) if(ret) message(FATAL_ERROR "Executing the below command failed. Are permissions set correctly? '${CMAKE_C_COMPILER} --version' " ) endif()
^ Source and Library Path Setting
Cmake has at least as of 2020 a notion of "translation map" which relates to the ways in which cmake determines file paths. One introduction to this concept arises at the forum post:
- https://discourse.cmake.org/t/when-does-cmake-current-binary-dir-resolve-symlinks/809
- https://gitlab.kitware.com/cmake/cmake/-/issues/16228
There is comment in cmake documentation that use of symbolic links can lead to subtle errors. Ted needs to locate this reference.
Earlier references:
Cmake has a notion of a binary or binaries directory, and has a built-in variable CMAKE_BINARY_DIR as described here:
^ cmake Lists
Look up `append_if_path_exists()` . . .
^ cmake Functions
An interesting pattern search in Zephyr 3.2.0 source tree and associated third party libraries is `$ grep -nr ExternalProject_Add ./*`, which reveals which projects and locations in Zephyr's source tree this cmake function is called. This function is needed when building multicore Zephyr apps.
There is a detailed document on `ExternalProject_Add()` at the Kitware public github repository:
- https://github.com/pyke369/sffmpeg/blob/master/CMakeLists.txt n . . . example of `INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR}/include)`
^ ExternalProject_Add
Cmake function `ExternalProject_Add()` is used in multi-core Zephyr sample projects. Some refs to this function include:
^ find_package
^ add_subdirectory_ifdef()
Really good blog post at blog.golioth.io regarding how to configure a "super project" containing multiple Zephyr based apps with shared, select-able at build time common code:
^ function()
- stub -
^ execute_process()
- stub -
^ add_custom_command()
- stub -
^ Install latest version of cmake
^ cmake Package Configuration Files - What Are They?
QUESTION (2022-12-29): what are cmake package configuration files?
When attempting to switch Zephyr sdk of original latest 2021 kionix-driver-demo, from Nordic ncs SDK to Zephyr RTOS Project itself, and a more recent release of Zephyr RTOS, get following error early early in build process:
:~/projects-sandbox/workspace-out-of-tree/kionix-driver-demo$ west build -b lpcxpresso55s69_cpu0 -p -- west build: making build dir /home/ted/projects-sandbox/workspace-out-of-tree/kionix-driver-demo/build pristine -- west build: generating a build system -- Build type: debug Loading Zephyr default modules (Zephyr base). -- Application: /home/ted/projects-sandbox/workspace-out-of-tree/kionix-driver-demo -- Found Python3: /usr/bin/python3.8 (found suitable exact version "3.8.10") found components: Interpreter -- Cache files will be written to: /home/ted/.cache/zephyr -- Zephyr version: 3.1.0 (/home/ted/projects-sandbox/workspace-out-of-tree/zephyr) -- Found west (found suitable version "0.12.0", minimum required is "0.7.1") -- Board: lpcxpresso55s69_cpu0 CMake Error at /home/ted/projects-sandbox/workspace-out-of-tree/zephyr/cmake/modules/verify-toolchain.cmake:79 (find_package): Could not find a package configuration file provided by "Zephyr-sdk" (requested version 0.13.1) with any of the following names: Zephyr-sdkConfig.cmake zephyr-sdk-config.cmake Add the installation prefix of "Zephyr-sdk" to CMAKE_PREFIX_PATH or set "Zephyr-sdk_DIR" to a directory containing one of the above files. If "Zephyr-sdk" provides a separate development package or SDK, be sure it has been installed. Call Stack (most recent call first): /home/ted/projects-sandbox/workspace-out-of-tree/zephyr/cmake/modules/zephyr_default.cmake:121 (include) /home/ted/projects-sandbox/workspace-out-of-tree/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:51 (include) /home/ted/projects-sandbox/workspace-out-of-tree/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:76 (include_boilerplate) CMakeLists.txt:51 (find_package) -- Configuring incomplete, errors occurred! FATAL ERROR: command exited with status 1: /usr/bin/cmake -DWEST_PYTHON=/usr/bin/python3 -B/home/ted/projects-sandbox/workspace-out-of-tree/kionix-driver-demo/build -S/home/ted/projects-sandbox/workspace-out-of-tree/kionix-driver-demo -GNinja -DBOARD=lpcxpresso55s69_cpu0
So at time of above error we didn't know how to trace that problem, though there is a call stack reported by cmake which tells us some cmake files we may review for better understanding. There are notes on cmake's documentation pages as of 2022-12-27 which mention the naming conventions of files which cmake's find_package() will look for when it is invoked.
NEED to add link to cmake's find_package() documentation.
2022-12-28 - some new cmake build errors:
(1)
ted@localhost:~/projects/zephyr-based/out-of-tree/kionix-driver-demo$ west build -b lpcxpresso55s69_cpu0 -p -- west build: making build dir /home/ted/projects/zephyr-based/out-of-tree/kionix-driver-demo/build pristine -- west build: generating a build system Loading Zephyr default modules (Zephyr base). -- Application: /home/ted/projects/zephyr-based/out-of-tree/kionix-driver-demo -- Found Python3: /usr/bin/python3.8 (found suitable exact version "3.8.10") found components: Interpreter -- Cache files will be written to: /home/ted/.cache/zephyr -- Zephyr version: 3.2.0 (/home/ted/projects/zephyr-based/out-of-tree/zephyr) -- Found west (found suitable version "0.11.0", minimum required is "0.7.1") -- Board: lpcxpresso55s69_cpu0 -- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK CMake Error at /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/modules/FindZephyr-sdk.cmake:63 (find_package): Could not find a configuration file for package "Zephyr-sdk" that is compatible with requested version "0.15". The following configuration files were considered but not accepted: /opt/zephyr-sdk-0.12.4/cmake/Zephyr-sdkConfig.cmake, version: 0.12.4 /opt/zephyr-sdk-0.14.2/cmake/Zephyr-sdkConfig.cmake, version: 0.14.2 /opt/zephyr-sdk-0.13.0/cmake/Zephyr-sdkConfig.cmake, version: 0.13.0 Call Stack (most recent call first): /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/modules/FindHostTools.cmake:53 (find_package) /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/modules/dts.cmake:8 (find_package) /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/modules/zephyr_default.cmake:108 (include) /home/ted/projects/zephyr-based/out-of-tree/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include) /home/ted/projects/zephyr-based/out-of-tree/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate) CMakeLists.txt:15 (find_package) -- Configuring incomplete, errors occurred! FATAL ERROR: command exited with status 1: /usr/bin/cmake -DWEST_PYTHON=/usr/bin/python3 -B/home/ted/projects/zephyr-based/out-of-tree/kionix-driver-demo/build -GNinja -DBOARD=lpcxpresso55s69_cpu0 -S/home/ted/projects/zephyr-based/out-of-tree/kionix-driver-demo
After setting `ZEPHYR_TOOLCHAIN_VARIANT` in the current shell, get these cmake errors:
(2)
ted@localhost:~/projects/zephyr-based/out-of-tree/kionix-driver-demo$ export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb ted@localhost:~/projects/zephyr-based/out-of-tree/kionix-driver-demo$ west build -b lpcxpresso55s69_cpu0 -p -- west build: making build dir /home/ted/projects/zephyr-based/out-of-tree/kionix-driver-demo/build pristine -- west build: generating a build system Loading Zephyr default modules (Zephyr base). -- Application: /home/ted/projects/zephyr-based/out-of-tree/kionix-driver-demo -- Found Python3: /usr/bin/python3.8 (found suitable exact version "3.8.10") found components: Interpreter -- Cache files will be written to: /home/ted/.cache/zephyr -- Zephyr version: 3.2.0 (/home/ted/projects/zephyr-based/out-of-tree/zephyr) -- Found west (found suitable version "0.11.0", minimum required is "0.7.1") -- Board: lpcxpresso55s69_cpu0 CMake Error at /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/modules/extensions.cmake:2071 (message): Assertion failed: GNUARMEMB_TOOLCHAIN_PATH is not set Call Stack (most recent call first): /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/toolchain/gnuarmemb/generic.cmake:4 (assert) /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/modules/FindHostTools.cmake:103 (include) /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/modules/dts.cmake:8 (find_package) /home/ted/projects/zephyr-based/out-of-tree/zephyr/cmake/modules/zephyr_default.cmake:108 (include) /home/ted/projects/zephyr-based/out-of-tree/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include) /home/ted/projects/zephyr-based/out-of-tree/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate) CMakeLists.txt:15 (find_package) -- Configuring incomplete, errors occurred! FATAL ERROR: command exited with status 1: /usr/bin/cmake -DWEST_PYTHON=/usr/bin/python3 -B/home/ted/projects/zephyr-based/out-of-tree/kionix-driver-demo/build -GNinja -DBOARD=lpcxpresso55s69_cpu0 -S/home/ted/projects/zephyr-based/out-of-tree/kionix-driver-demo
^ Zephyr Threads Tutorial by Maksim Drachov
Developer Maksim Drachov some helpful Zephyr build system and cmake tutorials, or explanatory documents on github. While not everything is explained, one of his example projects which builds a TCP/IP networking stack for a posix_native targeted board offers a number of more advanced cmake functions and features as part of this example project.
Earliest Maksim github link noted here is:
^ cmake Debugging
-- Application: /home/ted/projects/zephyr-based/kionix-driver-demo -- Zephyr version: 2.6.0-rc1 (/home/ted/projects/zephyr-based/zephyr), build: v2.6.0-rc1-ncs1 -- Found Python3: /usr/bin/python3.8 (found suitable exact version "3.8.10") found components: Interpreter -- Found west (found suitable version "0.12.0", minimum required is "0.7.1") -- Board: sparkfun_thing_plus_nrf9160 -- Cache files will be written to: /home/ted/.cache/zephyr -- Found dtc: /usr/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6") CMake Error at /home/ted/projects/zephyr-based/zephyr/cmake/toolchain/zephyr/generic.cmake:3 (if): if given arguments: "VERSION_LESS_EQUAL" "0.11.2" Unknown arguments specified Call Stack (most recent call first): /home/ted/projects/zephyr-based/zephyr/cmake/generic_toolchain.cmake:36 (include) /home/ted/projects/zephyr-based/zephyr/cmake/app/boilerplate.cmake:553 (include) /home/ted/projects/zephyr-based/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include) /home/ted/projects/zephyr-based/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate) CMakeLists.txt:40 (find_package) -- Configuring incomplete, errors occurred! FATAL ERROR: command exited with status 1: /usr/bin/cmake -DWEST_PYTHON=/usr/bin/python3 -B/home/ted/projects/zephyr-based/kionix-driver-demo/build -S/home/ted/projects/zephyr-based/kionix-driver-demo -GNinja -DBOARD=sparkfun_thing_plus_nrf9160
^ Cmake links to sort
2021-08-06
Starting a page for cmake
notes here. Links to cmake site:
- https://cmake.org/overview/
- https://cmake.org/examples/ . . . very limited, need other resources
Longer guides:
A Nordic Semi document on `cmake` and its role in the build process of Zephyr based applications:
2021-08-17 - search for cmake / Zephyr means to add sources to a Zephyr based project:
^ Topics To Follow Up
Who accepts the `--extra-args=CONFIG_*` option plus value? From `zephyr/scripts/pylib/twister/twisterlib/testinstance.py`:
225 def create_overlay(self, platform, enable_asan=False, enable_ubsan=False, enable_coverage=False, coverage_platform=[]): 226 # Create this in a "twister/" subdirectory otherwise this 227 # will pass this overlay to kconfig.py *twice* and kconfig.cmake 228 # will silently give that second time precedence over any 229 # --extra-args=CONFIG_* 230 subdir = os.path.join(self.build_dir, "twister") 231 232 content = ""
In Zephyr 3.2.0, `zephyr/cmake/modules/configuration_files.cmake` looks promising in terms of revealing where and how Kconfig processing is called during build of a Zephyr based app. An excerpt from this file:
1 # SPDX-License-Identifier: Apache-2.0 2 # 3 # Copyright (c) 2021, Nordic Semiconductor ASA 4 5 # Zephyr build system configuration files. 6 # 7 # Locate the Kconfig and DT config files that are to be used. 8 # Also, locate the appropriate application config directory. 9 # 10 # Outcome: 11 # The following variables will be defined when this CMake module completes: 12 # 13 # - CONF_FILE: List of Kconfig fragments 14 # - DTC_OVERLAY_FILE: List of devicetree overlay files 15 # - APPLICATION_CONFIG_DIR: Root folder for application configuration 16 # 17 # If any of the above variables are already set when this CMake module is 18 # loaded, then no changes to the variable will happen. 19 # 20 # Variables set by this module and not mentioned above are considered internal 21 # use only and may be removed, renamed, or re-purposed without prior notice.