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]
67 questions
5
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…
![](../../users/profiles/264052.webp)
smwikipedia
- 52,824
- 76
- 267
- 432
4
votes
0 answers
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…
![](../../users/profiles/2036673.webp)
Person93
- 1,004
- 8
- 22
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")
![](../../users/profiles/5157515.webp)
Chaitanya Bapat
- 1,328
- 2
- 17
- 37
2
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…
![](../../users/profiles/9784795.webp)
Paolo Crosetto
- 858
- 3
- 15
2
votes
1 answer
What's the execution order of CMake's `file(download)` instruction?
I have a CMakeLists.txt, which has a file(download xxx yy) command. There is also a custom_target cpx, which needs this downloaded file. But when the cpx target is invoked, the xxx file is not yet downloaded.
So my question is, when will the…
![](../../users/profiles/2692066.webp)
ddwolf
- 65
- 1
- 10
2
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…
![](../../users/profiles/11101982.webp)
mkl
- 392
- 2
- 13
2
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…
![](../../users/profiles/891439.webp)
Florian Wolters
- 3,273
- 3
- 25
- 47
1
vote
2 answers
Can I control sources exclusion from target_sources in CMake?
I am new in CMake and I was wondering whether there is a possibility to exclude certain sources from target_sources() based on a variable.
Let's say I have this below
target_sources(myTarget
PUBLIC
PRIVATE
myDir1/src/a.c
…
![](../../users/profiles/1757475.webp)
ndarkness
- 897
- 2
- 13
- 27
1
vote
2 answers
How to call a cmake method from shell script?
I have a parameterised function in mytestprogram.cmake written like below:
function(get_output_from_input output input)
set(${output} "test" PARENT_SCOPE)
endfunction()
Question:
How do I call the cmake method get_output_from_input from a…
![](../../users/profiles/6626554.webp)
TheWaterProgrammer
- 4,740
- 6
- 35
- 102
1
vote
3 answers
How to append semicolon (;) to cmake string
In cmake 3.19.2 i try to add semicolon to string by the following way:
cmake_minimum_required(VERSION 3.12)
project(some_project)
#--------------------------------------------------------------------
# Set CPP…
![](../../users/profiles/7797342.webp)
Vladimir Pogonin
- 83
- 1
- 4
1
vote
1 answer
How can I detect what version of macOS my Cmake code is running on?
I need to determine what version of MacOS the cmake file is running on.
if(BIGSUR)
# do something
else()
# do something else
endif()
![](../../users/profiles/14531530.webp)
rTanna
- 19
- 3
1
vote
1 answer
Constraining Values with ComboBoxes in CMake (cmake-gui)
I encountered CMake project where cache entry in cmake-gui was presented as combobox. But I can't find this project. How to add cache entry to CMakeLists.txt with values constrained with combobox?
![](../../users/profiles/14417225.webp)
stnk
- 13
- 4
1
vote
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…
![](../../users/profiles/1657819.webp)
The Godfather
- 3,138
- 2
- 33
- 49
1
vote
1 answer
What's the evaluated value of in if() in CMake?
My hello.txt
cmake_policy(SET CMP0054 NEW)
set(VAR ON)
# VAR will be treated as a string
if("VAR")
message(TRUE)
else()
message(FALSE)
endif()
# output prints FALSE
From policy CMP0054:
To prevent ambiguity, potential variable or keyword…
![](../../users/profiles/5335565.webp)
Izana
- 1,253
- 15
- 18
1
vote
2 answers
Problem using Qt4 with find_package of CMake, inside a macro
I have defined the following macro in CMake (version 3.10):
macro(configureQt4 requiredVersion selectedPackages)
message(STATUS "selectedPackages: ${selectedPackages}")
find_package(Qt4 ${requiredVersion} COMPONENTS ${selectedPackages}…
![](../../users/profiles/7118258.webp)
Soo
- 805
- 6
- 20