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
173
votes
1 answer

Cause CMAKE to generate an error

How can I get CMAKE to generate an error on a particular condition. That is, I want something like this: if( SOME_COND ) error( "You can't do that" ) endif()
edA-qa mort-ora-y
  • 30,295
  • 39
  • 137
  • 267
169
votes
10 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,837
  • 2
  • 12
  • 7
168
votes
7 answers

How to specify new GCC path for CMake

My OS is centos which has a default gcc in path /usr/bin/gcc. But it is old, I need a new version of gcc. So I install a new version in a new path /usr/local/bin/gcc. But when I run cmake, it still uses the old version gcc path(/usr/bin/gcc) . How…
tidy
  • 4,747
  • 9
  • 49
  • 89
167
votes
2 answers

Difference between CMAKE_CURRENT_SOURCE_DIR and CMAKE_CURRENT_LIST_DIR

From the Wiki: CMAKE_CURRENT_SOURCE_DIR this is the directory where the currently processed CMakeLists.txt is located in CMAKE_CURRENT_LIST_DIR (since 2.8.3) this is the directory of the listfile currently being processed. From the…
William Payne
  • 3,055
  • 3
  • 23
  • 25
164
votes
8 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
  • 2,209
  • 6
  • 21
  • 25
161
votes
7 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
  • 36,122
  • 25
  • 118
  • 131
158
votes
12 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
  • 8,030
  • 4
  • 37
  • 56
158
votes
12 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
  • 5,173
  • 7
  • 34
  • 36
158
votes
6 answers

CMake how to set the build directory to be different than source 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
  • 24,987
  • 19
  • 103
  • 189
156
votes
5 answers

CMake target_link_libraries Interface Dependencies

I am new to CMake and a bit confused with the PUBLIC, PRIVATE and INTERFACE keywords related to target_link_libraries(). Documentation mentions that they can be used to specify both the link dependencies and the link interface in one command. What…
Sirish
  • 9,183
  • 22
  • 72
  • 107
150
votes
3 answers

How to set a CMake option() at command line

I created a CMakeLists.txt that contains the following project(P4V) cmake_minimum_required(VERSION 2.6) option(BUILD_STATIC_LIBS "Build the static library" ON) option(BUILD_SHARED_LIBS "Build the shared library" ON) option(BUILD_TESTS "Build test…
Denilson Amorim
  • 9,642
  • 6
  • 27
  • 31
146
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
  • 9,183
  • 22
  • 72
  • 107
142
votes
7 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
  • 3,347
  • 4
  • 20
  • 25
142
votes
4 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,753
  • 2
  • 13
  • 14
141
votes
31 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,891
  • 3
  • 13
  • 12