Questions tagged [cmake]

CMake is a cross-platform, open-source build system generator. It generates files for build systems like native makefiles, ninja-build and project files for several integrated development environments.

CMake is a cross-platform, open-source build system generator. It generates files for build systems like native makefiles, ninja-build and project files for several integrated development environments.

It is often used along with , and .

Official

Quick Start / Howtos

Wisdom of the Stack

Books

27471 questions
61
votes
2 answers

CMAKE add sub-directory which is not sub-directory on real directory

Is It possible to include sibling directory as Sub-Directory inside cmake ? Something like A CMakeLists.txt B CMakeLists.txt and B includes A as sub-directory ?
Vivek Goel
  • 22,942
  • 29
  • 114
  • 186
61
votes
1 answer

How to read a CMake Variable in C++ source code

I'd like to store the version number of my library in just one place. So I have defined such a variable in the CMake-file: SET(LIBINTERFACE_VERSION 1 CACHE INTEGER "Version of libInterface") With this definition I can generate a version.rc file…
Snowfox
  • 1,112
  • 1
  • 10
  • 12
61
votes
1 answer

cmake: add_subdirectory() vs include()

Let's say I have a C++ unit-test project using cmake like this: $ tree . ├── C-API-ConditionVariable-unit-test │   ├── C-API-ConditionVariable-compile-link-test.c │   ├── C-API-ConditionVariable-unit-test-0.cpp │   └──…
Freddie Chopin
  • 8,440
  • 2
  • 28
  • 58
61
votes
2 answers

When should I quote CMake variable references?

I am writing CMake macros for the first time, and I have a hard time understanding how variables work. Most specifically, ${a} seems to have a different meaning than "${a}". For example here: Passing a list to a CMake macro When am I supposed to add…
Vince
  • 3,979
  • 10
  • 41
  • 69
61
votes
7 answers

Generate C# project using CMake

I'm trying to generate a C# project within an existing C++ CMake code base on Windows. After some research, I could find only two projects that built their own CSharp compilers for CMake: gdcm and kde. I tried both of them. Unfortunately, the first…
Leonid
  • 858
  • 1
  • 6
  • 13
60
votes
3 answers

Can one add further source files to an executable once defined?

Given I have defined an executable with its main source file in a CMakeList.txt file: ADD_EXECUTABLE(MyExampleApp main.cpp) Can I add further source files to this executable after this line but in the same or an included CMakeList.txt file?
Torbjörn
  • 5,512
  • 7
  • 46
  • 73
60
votes
4 answers

#ifdef DEBUG with CMake independent from platform

I am using CMake for building my projects on Windows (Visual Studio) as well as on Linux machines(gcc). I'd like to mark some code as "debugging only", like with #ifdef DEBUG //some logging here #endif The question is: what compiler definition is…
Philipp
  • 11,549
  • 8
  • 66
  • 126
60
votes
9 answers

How to use c++20 modules with CMake?

Clang and MSVC already supports Modules TS from unfinished C++20 standard. Can I build my modules based project with CMake or other build system and how? I tried build2, it supports modules and it works very well, but i have a question about it's…
Blaze
  • 813
  • 2
  • 8
  • 13
60
votes
4 answers

Passing a list to a CMake macro

I am trying to write a macro which goes through a given list of libraries. However the message call in the macro prints only the first item of the list. What am I doing wrong here? Code: macro( FindLibs LIBRARY_NAMES_LIST ) message(…
Paul
  • 2,474
  • 7
  • 33
  • 48
60
votes
6 answers

How to prepend all filenames on the list with common path?

How can I prepend all filenames on the list with a common path prefix automatically? For instance having a list of files in CMakeLists.txt: SET(SRC_FILES foo1.cpp foo2.cpp) I'd like to get a list that is equivalent to…
Pawel Stolowski
  • 1,170
  • 1
  • 10
  • 9
60
votes
3 answers

Use -isystem instead of -I with CMake

Is there any way in CMake to force a path specified via include_directories (or perhaps through a different function) to use the -isystem flag instead of the -I flag when building with gcc? See…
JRM
  • 1,134
  • 2
  • 9
  • 11
60
votes
2 answers

How to create a C project with CLion

since CLion has released a month ago there aren't many documents about it. So I'm confused about how to create a c project with CLion, when I want to create a new project I just asks the name of the project and creates a default main.cpp and…
fx773d
  • 601
  • 1
  • 5
  • 3
60
votes
3 answers

cmake if else with option

I have a problem using option together with if-else statement in cmake. project(test) option(TESTE "isso é um teste" OFF) if(TESTE) message("true") else() message("false") endif() add_executable(test main.cpp) It always displays true even if…
Alex
  • 3,301
  • 4
  • 29
  • 43
60
votes
7 answers

How to let cmake find CUDA

I am trying to build this project, which has CUDA as a dependency. But the cmake script cannot find the CUDA installation on the system: cls ~/workspace/gpucluster/cluster/build $ cmake .. -- The C compiler identification is GNU 4.7.1 -- The CXX…
clstaudt
  • 21,436
  • 45
  • 156
  • 239
59
votes
4 answers

CMake : How to get the name of all subdirectories of a directory?

I have two questions relative to CMake Assume that we have a variable ${MY_CURRENT_DIR} that contains the path of a directory that contains several subdirectories : mydir1, mydir2 and mydir3. I want to detect these subdirectories and put their…
Vincent
  • 57,703
  • 61
  • 205
  • 388