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
607
votes
26 answers

Looking for a 'cmake clean' command to clear up CMake output

Just as make clean deletes all the files that a makefile has produced, I would like to do the same with CMake. All too often I find myself manually going through directories removing files like cmake_install.cmake and CMakeCache.txt, and the…
Bill Cheatham
  • 11,396
  • 17
  • 69
  • 104
567
votes
6 answers

Debug vs Release in CMake

In a GCC compiled project, How do I run CMake for each target type (debug/release)? How do I specify debug and release C/C++ flags using CMake? How do I express that the main executable will be compiled with g++ and one nested library with gcc?
Cartesius00
  • 23,584
  • 43
  • 124
  • 195
508
votes
3 answers

What is the difference between using a Makefile and CMake to compile the code?

I code in C/C++ and use a (GNU) Makefile to compile the code. I can do the same with CMake and get a Makefile. However, what is the difference between using a Makefile and CMake to compile the code?
rish
  • 5,575
  • 6
  • 22
  • 27
453
votes
9 answers

What is CMake equivalent of 'configure --prefix=DIR && make all install '?

I do cmake . && make all install. This works, but installs to /usr/local. I need to install to a different prefix (for example, to /usr). What is the cmake and make command line to install to /usr instead of /usr/local?
Andrei
  • 8,606
  • 10
  • 35
  • 43
412
votes
17 answers

How do I activate C++ 11 in CMake?

When I try to run a CMake generated makefile to compile my program, I get the error that range based for loops are not supported in C++ 98 mode. I tried adding add_definitions(-std=c++0x) to my CMakeLists.txt, but it did not help. I tried this…
Subhamoy S.
  • 6,566
  • 10
  • 37
  • 53
408
votes
6 answers

Define preprocessor macro through CMake?

How do I define a preprocessor variable through CMake? The equivalent code would be #define foo.
Mythli
  • 5,995
  • 2
  • 24
  • 31
396
votes
11 answers

How to properly add include directories with CMake

About a year ago I asked about header dependencies in CMake. I realized recently that the issue seemed to be that CMake considered those header files to be external to the project. At least, when generating a Code::Blocks project the header files do…
Matthieu M.
  • 287,565
  • 48
  • 449
  • 722
350
votes
8 answers

Using CMake with GNU Make: How can I see the exact commands?

I use CMake with GNU Make and would like to see all commands exactly (for example how the compiler is executed, all the flags etc.). GNU make has --debug, but it does not seem to be that helpful are there any other options? Does CMake provide…
Nils
  • 13,319
  • 19
  • 86
  • 108
329
votes
12 answers

Switching between GCC and Clang/LLVM using CMake

I have a number of projects built using CMake and I'd like to be able to easily switch between using GCC or Clang/LLVM to compile them. I believe (please correct me if I'm mistaken!) that to use Clang I need to set the following: SET…
Rezzie
  • 4,763
  • 6
  • 26
  • 33
300
votes
7 answers

CMake: Print out all accessible variables in a script

I'm wondering if there is a way to print out all accessible variables in CMake. I'm not interested in the CMake variables - as in the --help-variables option. I'm talking about my variables that I defined, or the variables defined by included…
Michael
  • 3,604
  • 3
  • 19
  • 12
294
votes
8 answers

How do I add a linker or compile flag in a CMake file?

I am using the arm-linux-androideabi-g++ compiler. When I try to compile a simple "Hello, World!" program it compiles fine. When I test it by adding a simple exception handling in that code it works too (after adding -fexceptions .. I guess it is…
solti
  • 4,339
  • 3
  • 31
  • 51
291
votes
5 answers

What are the differences between Autotools, Cmake and Scons?

What are the differences between Autotools, Cmake and Scons?
Wazery
  • 15,394
  • 19
  • 63
  • 95
273
votes
10 answers

How do I make CMake output into a 'bin' dir?

I'm currently constructing a project with a plugin structure. I'm using CMake to compile the project. The plugins are compiled in separate directories. My problem is that CMake compiles and saves the binaries and plugins, dynamic libraries, in the…
Martin Kristiansen
  • 9,875
  • 10
  • 51
  • 83
261
votes
4 answers

cmake and libpthread

I'm running RHEL 5.1 and use gcc. How I tell cmake to add -pthread to compilation and linking?
dimba
  • 26,717
  • 34
  • 141
  • 196
256
votes
3 answers

What's the CMake syntax to set and use variables?

I'm asking this as a reminder to myself the next time I use CMake. It never sticks, and Google results aren't great. What's the syntax to set and use variables in CMake?
CivFan
  • 13,560
  • 9
  • 41
  • 58
1
2 3
99 100