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
71
votes
6 answers

How do I change the startup project of a Visual Studio solution via CMake?

I am using CMake to generate Visual Studio projects. Everything works fine except one thing. The startup project in the solution is always ALL_BUILD. How do I change the startup project to the real project I want via CMake?
giggle
  • 1,911
  • 5
  • 21
  • 25
71
votes
3 answers

How can I build a C++ project with multiple interdependent subdirectories?

I have a C++ project where I've used directories as more of an organizational element -- the way one might use packages in Java or directories in PHP. Directories are not intended to be self-sufficient elements, but rather just a way of organizing…
Daniel Bingham
  • 12,414
  • 18
  • 67
  • 93
71
votes
2 answers

"In-source builds are not allowed" in cmake

I'm new to cmake, and I'm only using it to install opencv on my ubuntu linux. Here's the command I ran: cmake -DCMAKE_BUILD_TYPE=Release DCMAKE_INSTALL_PREFIX=/home/jinha/OCV/source Then it returns the error: FATAL: In-source builds are not allowed.…
WannabeArchitect
  • 1,058
  • 2
  • 11
  • 22
71
votes
5 answers

How to use CMAKE_EXPORT_COMPILE_COMMANDS?

I've been trying to use clang-modernize with CMAKE_EXPORT_COMPILE_COMMANDS as recommended in the help of this tool. With this option cmake generates a JSON file containing compile info like include paths (see also). This variable is accepted on the…
dzada
  • 5,344
  • 5
  • 29
  • 37
70
votes
8 answers

Ninja not found by CMake

I'm trying to build some code I got from GitHub using CMake, but keep getting the followings errors: CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a…
user3871995
  • 983
  • 1
  • 10
  • 19
70
votes
1 answer

Package vs Library

I've just started working with CMake and I noticed that they have both a find_package and a find_library. And this confuses me. Can somebody explain the difference between a package and a library in the world of programming? Or, in the world of…
assignment_operator
  • 1,213
  • 4
  • 12
  • 14
70
votes
10 answers

How can I pass git SHA1 to compiler as definition using cmake?

In a Makefile this would be done with something like: g++ -DGIT_SHA1="`git log -1 | head -n 1`" ... This is very useful, because the binary knows exact commit SHA1 so it can dump it in case of segfault. How can I achieve the same with CMake?
Łukasz Lew
  • 48,526
  • 41
  • 139
  • 208
69
votes
2 answers

Does set_target_properties in CMake override CMAKE_CXX_FLAGS?

At the beginning of my CMake project, I'm setting general compilation flags in the variable CMAKE_CXX_FLAGS, like set(CMAKE_CXX_FLAGS "-W -Wall ${CMAKE_CXX_FLAGS}") Later on, I need to append additional configuration-specific compilation flags…
Milan Hanus
  • 714
  • 1
  • 5
  • 7
69
votes
3 answers

How to install your custom CMake-Find module

I configure and package my library using CMake and CPack. I have written my own find-module: FindMyLib.cmake. How do I tell CMake/CPack to add this file to the CMake module directory, so that future developers can simply specify FIND_PACKAGE(MyLib)…
goocreations
  • 2,938
  • 8
  • 37
  • 59
68
votes
2 answers

How do I convert an Autotools project to a CMake project?

So there seems to be a lot of writing on the subject of Autotools vs. CMake, but for the life of me I can't seem to find a good tutorial on how to convert a project from Autotools (Makefile.am and configure.ac files) to CMake (CMakeLists.txt files).…
Kurtis Nusbaum
  • 30,445
  • 13
  • 78
  • 102
68
votes
2 answers

What is the difference between "option" and "set CACHE BOOL" for a CMake variable?

Is there any difference between the following two? set(FOO true CACHE BOOL "description") option(FOO "description" ON) Documentation: set - option Background: Even if I have been using CMake for a while, I only noticed the option command today and…
Antonio
  • 19,451
  • 13
  • 99
  • 197
68
votes
4 answers

How do I list the defined make targets from the command line?

I feel almost silly for asking this but I couldn't find anything on this... Suppose I have a cmake project containing a number of targets (libraries, executables, external targets, etc). How do I list them using the cmake command line interface? I…
Holger
  • 1,648
  • 1
  • 16
  • 26
68
votes
1 answer

CMake: target_include_directories() prints an error when I try to add the source directory itself, or one of its subdirectories

I am writing a C++ library (header-only) and am using CMake to generate my (Visual Studio) project and solution files. I'm also writing a test suite, which is part of the same CMake project. My problem occurs when I call target_include_directories()…
JPNotADragon
  • 2,050
  • 2
  • 25
  • 31
67
votes
5 answers

What are CMake vs qmake pros and cons?

I would like to know reasons for use CMake for particular project over qmake and vice versa. Simply what are the pros and cons of both build systems?
Hareen Laks
  • 1,432
  • 2
  • 17
  • 33
67
votes
8 answers

CMake is not able to find BOOST libraries

I tried everything like: Configure environment variable Make fresh build Re-install BOOST from source sudo apt-get install libboost-all-dev But still getting following Errors: CMake Error at /usr/share/cmake-2.8/Modules/FindBoost.cmake:1131…
Amit Pal
  • 10,604
  • 26
  • 80
  • 160