CMake (cmake) input files are written in the “CMake Language” in source files named CMakeLists.txt
or ending in a .cmake
file name extension.
Questions tagged [cmake-language]
112 questions
9
votes
1 answer
How can I ignore all cmake dev warnings from subdirectories?
I am using a few external libraries that are included as git submodules using the add_subdirectory command. Some of them are using old versions of cmake and they're issuing warnings about policies CMP0048 and CMP0077.
Is there a way to turn off all…

Michael
- 1,263
- 1
- 12
- 28
6
votes
1 answer
CMake - How does the if() command treat a symbol? As string or as variable?
I am not sure the CMake if() command will treat a symbol in the condition clause as a variable or a string literal. So I did some experiments.
Script1.cmake
cmake_minimum_required(VERSION 3.15)
set(XXX "YYY") #<========== HERE!!
if(XXX STREQUAL…

smwikipedia
- 61,609
- 92
- 309
- 482
4
votes
2 answers
How do I make a list in CMake with the semicolon value?
I think it should be super trivial, but seems like it's not supported... Is it even possible in CMake to have one value of a list contain a semicolon?
The reason is super simple - because I'm running on Windows, and on Windows the semicolon is the…

The Godfather
- 4,235
- 4
- 39
- 61
4
votes
3 answers
CMake set_property command with generator expressions using multiple values
I am using CMake v3.13.4 with the Visual Studio 2017 Win64 generator and I need to modify the command line options for the Visual Studio Librarian (for a CMake object library).
To achieve that CMake offers the target property STATIC_LIBRARY_OPTIONS…

Florian Wolters
- 3,820
- 5
- 35
- 55
3
votes
1 answer
How to detect accidental function overrides in CMake?
I just discovered a copy and paste error in my CMake code:
function(name)
# do something ...
endfunction()
function(name)
# do something else ...
endfunction()
I had copied, renamed and changed the function several times. Apparently I…

Benjamin Buch
- 4,752
- 7
- 28
- 51
3
votes
1 answer
Why my INCLUDE_DIRECTORIES and INTERFACE_INCLUDE_DIRECTORIES properties are empty in Cmake?
In this code, I add with target_include_directories the string "${PROJECT_BINARY_DIR}" in the properties INCLUDE_DIRECTORIES and INTERFACE_INCLUDE_DIRECTORIES. However, when I run Cmake I see with the message commands that these two properties are…

Tesla123
- 319
- 1
- 7
3
votes
0 answers
How to correctly quote CMAKE Join Generator expressions
Consider a target with compile options and include files:
target_compile_options(Tutorial PRIVATE /DC=1)
target_compile_options(Tutorial PRIVATE /DD=2)
target_include_directories(Tutorial PRIVATE "include…

Brad
- 3,190
- 1
- 22
- 36
3
votes
0 answers
Exporting and packaging prebuilt libraries in cmake
instead of asking a question directly, I'll expose my use case and the way I tried (but failed) to solve it.
Say I have:
3 shared libraries A, B and C
A require B and C
A comes with a set of headers
That's it, no extra information, it's provided…

Etienne M
- 604
- 3
- 11
3
votes
1 answer
cmake use wildcard for find_library NAMES option
In cmake to find a library we use find_library(MyLibrary_LIBRARY NAMES mylibrary mylibrary10 mylibrary11 HINTS /path/to/library). This command tells cmake to find a file named mylibrary.so or mylibrary10.so or mylibrary11.so (or files with .lib…

hzh
- 342
- 2
- 15
3
votes
1 answer
How to query whether a target is an INTERFACE library in CMake
In modern CMake one can specify a library as INTERFACE: it does not produce build output, but it can have properties associated to it, although not all properties can be set (for instance the FOLDER property is not supported). Say I have a generic…

Paolo Crosetto
- 1,038
- 7
- 17
3
votes
2 answers
CMake variable with semicolons
Say there is a programme that requires input in form --param "one;two;three": a flag --param followed by a string (enclosed in quotes) of words separated by a semicolon. For example, the following Bash scrip can be…

scrutari
- 1,378
- 2
- 17
- 33
3
votes
1 answer
What's the point of using empty string to set cache variable in CMake?
I've seen different ways of setting / using Cache variables in Cmake.
What is the standard?
What's the point of setting an empty string ("") to the cache variable?
Example
set(NVTX_ROOT_DIR "" CACHE PATH "Folder contains NVIDIA NVTX")

Chaitanya Bapat
- 3,381
- 6
- 34
- 59
3
votes
0 answers
CMake: Get environment variable with escaped characters
Suppose one wants to use the environment variable MY_VAR in CMake. This may be accomplished simply by using set(myVar $ENV{MY_VAR}).
But what if MY_VAR contains escape characters, say MY_VAR="/path/with/escaped\ chars"? CMake treats \ followed by a…

mkl
- 635
- 1
- 6
- 16
2
votes
1 answer
Is it possible to get a list of linked libraries in CMake script as it will be pass to the linker?
I need to get a list of all linked libraries in form as they will be passed to the linker in my CMake script.
For example, in my CMake project file, I define the target, which represents the build of a dynamic library. I call the functions from…

nen777w
- 87
- 1
- 1
- 6
2
votes
1 answer
Stm32 project configuration using CMake
i have recently switched my stm32 project to CMake to be independent on IDE. Root repository (application) contains multiple submodules (HAL, FreeRTOS etc.) and its CMakeLists.txt includes explicitly every single used file:
set(EXECUTABLE…

Zoltán Dolenský
- 78
- 3