Difference between revisions of "Cmake"

From Wiki at Neela Nurseries
Jump to: navigation, search
m (To print variables in cmake.)
m (^ To print variables in cmake)
Line 32: Line 32:
  
 
== [[#top|^]] To print variables in cmake ==
 
== [[#top|^]] 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:
 +
*  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 -
  
*  https://stackoverflow.com/questions/31343813/displaying-cmake-variables
+
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
 +
 
 +
 
 +
 
 +
 
 +
-->
  
 
== [[#top|^]] To Specify Source Dirs and Library Directories to Linker ==
 
== [[#top|^]] To Specify Source Dirs and Library Directories to Linker ==

Revision as of 17:50, 29 March 2022

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:


^ To Specify Source Dirs and Library Directories to Linker


^ Install latest version of cmake


^ Zephyr Threads Tutorial by Maksim Drachov

 

- - - top of page - - -