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

21896 questions
495
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
  • 21,471
  • 40
  • 115
  • 185
475
votes
22 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
  • 9,885
  • 15
  • 63
  • 100
414
votes
7 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
  • 7,898
  • 10
  • 32
  • 41
386
votes
2 answers

Difference between using Makefile and CMake to compile the code

I code on 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 Makefile and CMake to compile the code?
rish
  • 4,307
  • 5
  • 20
  • 24
377
votes
14 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.
  • 5,973
  • 8
  • 32
  • 49
326
votes
3 answers

Define preprocessor macro through CMake?

How do I define a preprocessor variable through CMake? The equivalent code would be #define foo.
Mythli
  • 5,127
  • 2
  • 21
  • 31
307
votes
6 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
  • 12,129
  • 17
  • 78
  • 103
290
votes
9 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,295
  • 6
  • 22
  • 30
290
votes
7 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.
  • 251,718
  • 39
  • 369
  • 642
270
votes
5 answers

What are the differences between Autotools, Cmake and Scons?

What are the differences between Autotools, Cmake and Scons?
Wazery
  • 13,971
  • 15
  • 55
  • 91
251
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,094
  • 2
  • 16
  • 12
238
votes
6 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
  • 3,720
  • 2
  • 28
  • 43
223
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
  • 24,103
  • 28
  • 127
  • 188
222
votes
9 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
  • 8,778
  • 10
  • 43
  • 81
192
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
  • 10,079
  • 9
  • 34
  • 55
1
2 3
99 100