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
95
votes
3 answers

Adding multiple executables in CMake

My code in a C++ project is organised as follows I have several .cpp and .h files which contains my classes I have several .cxx files which have to be compiled against the .cpp files and some external libraries. Now, each of the .cxx files have a…
ssb
  • 7,422
  • 10
  • 36
  • 61
95
votes
6 answers

How do I configure portable parallel builds in CMake?

Is it somehow possible to be able to have a parallel build no matter which build tool is used? Under Unix we can add make -jN where N are the number of threads, and under Windows I added to the CXX_FLAG "/MP" which is then used in Visual Studio to…
Gabriel
  • 8,990
  • 6
  • 57
  • 101
94
votes
2 answers

Set the number of threads in a CMake build

cmake --build . --config Release Is it possible to set the number of cores to be used by the build process? I'm looking for something similar to GNU make's -j option.
Konstantin Burlachenko
  • 5,233
  • 2
  • 41
  • 40
92
votes
5 answers

In CLion, header only library: file "does not belong to any project target, code insight features might not work properly"

I have a header-only library project set up with the cmake command: add_library(my_library INTERFACE) and I also added target_sources(my_library INTERFACE ${MY_LIRBARY_HEADER_FILES}) but when I open a source file, I get the warning: This file…
xaxxon
  • 19,189
  • 5
  • 50
  • 80
92
votes
6 answers

How to use all *.c files in a directory with the Cmake build system?

I want to find all .c files under a directory and add them all to SRC files to compile in cmake. How can I do this in CMakeList.txt. for regular makefiles I can create SPECIFIED_SRC_FILE = $(foreach d,$(SPECIFIED_SRC_DIRS),$(wildcard $(addprefix…
user256537
91
votes
16 answers

CMAKE_MAKE_PROGRAM not found

I have reached the end of my rope with CMake; it has so much potential, but I cannot seem to make it find the basic system tools (i.e. make) in order to function. SYMPTOMS CMake and the CMake GUI produce the following (after deleting the…
westie314
  • 929
  • 1
  • 6
  • 4
90
votes
3 answers

What is common way to split string into list with CMAKE?

Imagine I have the following string : set(SEXY_STRING "I love CMake") then I want to obtain SEXY_LIST from SEXY_STRING so I can do list(LENGTH SEXY_LIST len) and len is equal 3. I've found several macros on web, but I really want to know how to do…
Alexander K.
  • 1,649
  • 2
  • 15
  • 21
89
votes
6 answers

Passing compiler options in CMake command line

I know how to pass compiler options using the cmake command: set(CMAKE_CXX_FLAGS "-Wall -Wno-dev -Wl,-rpath=/home/abcd/libs/") Is there also a way to pass the options from the command line that will override the CMakeLists.txt options? Something…
infoclogged
  • 3,641
  • 5
  • 32
  • 53
88
votes
6 answers

Display CMake variables without running CMake on a CMakeLists.txt file or manually inspecting config.cmake?

Suppose I have a package called Foo. If I run CMake on a CMakeLists.txt file that contains find_package(Foo), then I can print out the values of variables such as ${Foo_LIBRARIES} and ${Foo_INCLUDES}. Is there an easy way to display these variables…
Karnivaurus
  • 22,823
  • 57
  • 147
  • 247
88
votes
7 answers

How to detect C++11 support of a compiler with CMake

Is there a way to let CMake detect automatically if a compiler supports C++11 or not? As it would be nice to inform the users during the CMake run that the code will not compile as the compiler does not support C++11. At the moment I set the C++11…
tune2fs
  • 7,605
  • 5
  • 41
  • 57
86
votes
2 answers

Are CMAKE_SOURCE_DIR and PROJECT_SOURCE_DIR the same in CMake?

This page contains a good summary of variables CMake already defines for us. I feel that some variables are the same. Take the example of CMAKE_SOURCE_DIR and PROJECT_SOURCE_DIR for example. They are the same, referring to the folder where the top…
feelfree
  • 11,175
  • 20
  • 96
  • 167
86
votes
4 answers

CMake check that a local file exists

In my CMake script I want to see if I have a file on my system, and if it is there do something with it, otherwise do something with a default file. Here is the code: find_file( ${project_name}_${customer}_config …
Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167
84
votes
7 answers

What's the proper way to enable AddressSanitizer in CMake that works in Xcode

I've added AddressSanitizer flag as follow: set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") Everything builds and runs fine when using Unix Makefiles. The problem comes when generating the Xcode project, it just doesn't want to link…
ObjSal
  • 1,494
  • 1
  • 14
  • 18
82
votes
4 answers

What are CMAKE_BUILD_TYPE: Debug, Release, RelWithDebInfo and MinSizeRel?

From the docs page: CMAKE_BUILD_TYPE Specifies the build type on single-configuration generators. This statically specifies what build type (configuration) will be built in this build tree. Possible values are empty, Debug, Release, RelWithDebInfo…
MiP
  • 5,846
  • 3
  • 26
  • 41
82
votes
4 answers

Making CMake print commands before executing

I'm working on a large C++ project built with CMake on Linux. CMake runs okay, producing a horde of Makefiles in the tree of modules and applications. Running GNU make leads to linker errors. How can I get make to print out the exact commands…
DarenW
  • 16,549
  • 7
  • 63
  • 102