Questions tagged [cmake-language]

CMake () input files are written in the “CMake Language” in source files named CMakeLists.txt or ending in a .cmake file name extension.

Official Documentation

Additional Resources

112 questions
2
votes
1 answer

What is an INTERFACE IMPORTED library in CMake and what are its uses?

So far I've seen the INTERFACE library type used to describe header-only libraries, as it does not compile sources and does not produce library artifacts. The IMPORTED library type I've seen less of, but from what I've read it is used to describe…
Jeff L
  • 491
  • 5
  • 14
2
votes
2 answers

What is the "VERSION" in "cmake_minimum_required(VERSION 3.10)”

I know the meaning of below CMake statement: cmake_minimum_required(VERSION 3.10) I am just wondering what the VERSION part is syntactically? Is it a unquoted argument? If it is an argument, there must be some other argument choices. But according…
smwikipedia
  • 61,609
  • 92
  • 309
  • 482
2
votes
1 answer

CMake target_include_directories relative to parent directory?

How do I add lib0 path to lib1 such that from header1.h I can #include ? | CMakeLists.txt +---lib0 | CMakeLists.txt | header0.c | header0.h +---lib1 | CMakeLists.txt | header1.c | header1.h \---main …
A T
  • 13,008
  • 21
  • 97
  • 158
2
votes
1 answer

cmake find_library() not finding library specified by PATHS

I have a find_library() statement that matches below (this is based on the amazon kinesis project): find_library(SRTP_LIBRARIES NAMES srtp2 REQUIRED PATHS ${OPEN_SRC_INSTALL_LIB_PREFIX}) The OPEN_SRC_INSTALL_LIB_PREFIX correctly points to the…
ryeager
  • 873
  • 1
  • 10
  • 24
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…
ddwolf
  • 91
  • 2
  • 10
2
votes
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…
Izana
  • 2,537
  • 27
  • 33
1
vote
1 answer

What reasons are there to discourage accessing CMake cache variables using `$CACHE{variable}`?

Problem I am working through Professional CMake and section 5.5 - Potentially Surprising Behaviour of Variables discourages accessing cache variables using $CACHE{variable} except when debugging. The exact quote is: Projects should not generally…
Toggy Smith
  • 330
  • 2
  • 7
1
vote
1 answer

Why don't I need add boost::shared_ptr to target_link_libraries when linking to Boost::filesystem?

Recently, I was learning CMake using ttroy50/cmake-examples. But when I learning H-third-party-library, I meet a problem! This tutorial said we can use find_package function to find third party libraries. We have the following main.cpp: #include…
Ning Ben
  • 35
  • 6
1
vote
0 answers

CMake Prevent Need for Inclusion of Precise Header Location

I have the following directory structure: Project | |-CMakeLists.txt Library | |-LibProjectA | |-CMakeLists.txt | |-src | |-SomeHeader0.h |-LibProjectB | |-CMakeLists.txt | |-src | |-SomeHeader1.h …
Alex Baum
  • 166
  • 9
1
vote
0 answers

How to change CLion run/debug configuration working directory from CMake

In my project, with CMake 3.8 for MSVC, in order to change the working directory when debugging MY_TARGET I can put the following: set_property(TARGET ${MY_TARGET} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "$(SolutionDir)") In CLion, I get the same…
traveh
  • 2,700
  • 3
  • 27
  • 44
1
vote
2 answers

CMake function arguments -- why are they occasionally uppercase?

I've been combing through the CMake documentation for a while now trying to figure out why some function arguments are capitalised and some aren't. I was hoping someone might be able to explain the pattern of things being capitalised, or at the very…
B.Iguana
  • 23
  • 3
1
vote
1 answer

How to use empty entries in CMake lists as arguments

When using a CMake list to specify multiple arguments to a function, empty arguments are not passed as arguments to the list. In some cases an empty string is needed as an argument. Is there a way to achieve this? If I run…
mdr
  • 187
  • 1
  • 11
1
vote
1 answer

Start reading file from a specific line using CMAKE

I want to start reading a file from a specific line. Cmake official docs suggest using file() with offset but I am not sure about its usage. The file that I want to read is test.mak: #…
deb
  • 15
  • 7
1
vote
1 answer

Use CMake generator expression to conditionally link towards list of libraries

cmake-genex can be used to conditionally link libraries based on information only available at CMake build-time: Example 1: Using one genex per lib cmake_minimum_required(VERSION 3.20.0) project(cmake-genex) add_library(lib1 SHARED source1.hpp…
Joakim Thorén
  • 1,111
  • 10
  • 17
1
vote
1 answer

CMake get a cache variables list from inside a CMakeLists.txt script

I'd like to know if there's a way to get a list of cached variables from inside a CMakeLists.txt script. I mean, having something like this: cmake -S . -B build -DMY_VAR1=hello -DMY_VAR2=there and, within my CMakeLists.txt option(MY_VAR3 "a cache…
Kabu
  • 519
  • 6
  • 16