Cmake

From Wiki at Neela Nurseries
Revision as of 07:27, 8 December 2022 by Ted (talk | contribs) (New section on cmake functions, first function noted "ExternalProject_Add()")
Jump to: navigation, search

Zephyr RTOS building blocks   ::   Device Tree Source   ::   Kconfig   ::   cmake   ::   `west` manifest files


2021-08-06

Starting a page for cmake notes here. Links to cmake site:

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:


^ To print variables in cmake

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()

^ To Specify Source Dirs and Library Directories to Linker


^ 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:


^ Install latest version of cmake


^ 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



^ Zephyr Threads Tutorial by Maksim Drachov (should be moved)

 


^ 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


- - - top of page - - -