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
139
votes
7 answers

How do you add Boost libraries in CMakeLists.txt?

I need to add Boost libraries into my CMakeLists.txt. How do you do it or how do you add it?
laksh
  • 1,929
  • 6
  • 19
  • 25
138
votes
10 answers

How to start working with GTest and CMake

I have recently been sold on using CMake for compiling my C++ projects, and would now like to start writing some unit tests for my code. I have decided to use the Google Test utility to help with this, but require some help in getting started. All…
Chris
  • 7,494
  • 4
  • 35
  • 55
132
votes
5 answers

CMake output/build directory

I'm pretty new to CMake, and read a few tutorials on how to use it, and wrote some complicated 50 lines of CMake script in order to make a program for 3 different compilers. This probably concludes all my knowledge in CMake. Now my problem is that I…
The Quantum Physicist
  • 21,050
  • 13
  • 77
  • 143
131
votes
6 answers

How to compile a 32-bit binary on a 64-bit linux machine with gcc/cmake

Is it possible to compile a project in 32-bit with cmake and gcc on a 64-bit system? It probably is, but how do I do it? When I tried it the "ignorant" way, without setting any parameters/flags/etc, just setting LD_LIBRARY_PATH to find the linked…
dala
  • 1,885
  • 2
  • 14
  • 12
129
votes
6 answers

How to set warning level in CMake?

How to set the warning level for a project (not the whole solution) using CMake? Should work on Visual Studio and GCC. I found various options but most seem either not to work or are not consistent with the documentation.
Wernight
  • 32,087
  • 22
  • 110
  • 128
129
votes
4 answers

C++ project organisation (with gtest, cmake and doxygen)

I am new to programming in general so I decided that I would start by making a simple vector class in C++. However I would like to get in to good habits from the start rather than trying to modify my workflow later on. I currently have only two…
rozzy
  • 2,598
  • 5
  • 21
  • 33
127
votes
28 answers

CMake does not find Visual C++ compiler

After installing Visual Studio 2015 and running CMake on a previous project, CMake errors stating that it could not find the C compiler. The C compiler identification is unknown The CXX compiler identification is unknown CMake Error at…
Asher
  • 2,701
  • 3
  • 10
  • 12
126
votes
3 answers

Cmake vs make sample codes?

I was wondering if there was any sample code for Makefiles (make) and CMakeLists.txt (cmake) that both do the same thing (the only difference being that one is written in make and the other in cmake). I tried looking for 'cmake vs make', but I…
jlo
  • 1,721
  • 2
  • 11
  • 17
125
votes
8 answers

OS specific instructions in CMAKE: How to?

I am a beginner to CMAKE. Below is a simple cmake file which works well in mingw environment windows. The problem is clearly with target_link_libraries() function of CMAKE where I am linking libwsock32.a. In windows this works and I get the results.…
Prasad
  • 1,401
  • 2
  • 10
  • 7
125
votes
3 answers

Most simple but complete CMake example

Somehow I am totally confused by how CMake works. Every time I think that I am getting closer to understand how CMake is meant to be written, it vanishes in the next example I read. All I want to know is, how should I structure my project, so that…
Arne
  • 7,206
  • 4
  • 41
  • 60
124
votes
8 answers

Copy file from source directory to binary directory using CMake

I'm trying to create a simple project on CLion. It uses CMake (I'm new here) to generate Makefiles to build project (or some sort of it) All I need to is transfer some non-project file (some sort of resource file) to binary directory each time when…
mongolrgata
  • 1,347
  • 2
  • 9
  • 9
123
votes
5 answers

CMake: How to build external projects and include their targets

I have a Project A that exports a static library as a target: install(TARGETS alib DESTINATION lib EXPORT project_a-targets) install(EXPORT project_a-targets DESTINATION lib/alib) Now I want to use Project A as an external project from Project B…
mirkokiefer
  • 2,861
  • 4
  • 17
  • 22
122
votes
11 answers

Using CMake, how do I get verbose output from CTest?

I'm using CMake to build my project. I have added a unit test binary which is using the Boost unit testing framework. This one binary contains all of the unit tests. I've added that binary to be run by CTest: ADD_EXECUTABLE( tftest test-main.cpp…
Skrymsli
  • 4,589
  • 5
  • 30
  • 33
121
votes
3 answers

Override compile flags for single files

I would like to use a global set of flags for compiling a project, meaning that at my top-level CMakeLists.txt file I have specified: ADD_DEFINITIONS ( -Wall -Weffc++ -pedantic -std=c++0x ) However, for a specific file (let's say "foo.cpp") in a…
J.B. Brown
  • 1,533
  • 2
  • 12
  • 14
120
votes
2 answers

CMake target_include_directories meaning of scope

What is the meaning of the keyword PUBLIC, PRIVATE, and INTERFACE related to CMake's target_include_directories?
Sirish
  • 7,948
  • 19
  • 61
  • 97