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

Using CMake to generate Visual Studio C++ project files

I am working on an open source C++ project, for code that compiles on Linux and Windows. I use CMake to build the code on Linux. For ease of development setup and political reasons, I must stick to Visual Studio project files/editor on Windows (I…
amit kumar
  • 20,438
  • 23
  • 90
  • 126
107
votes
19 answers

Cmake Error: could not load cache

I'm using Cmake to try to build a project for Eclipse. When I try running Cmake, I get the following error: Error: could not load cache Error: Batch build stopped due to Eclipse CDT4 - Unix Makefiles error. ---- Time Elapsed: 3 secs ---- Error:…
robhasacamera
  • 2,967
  • 2
  • 28
  • 41
106
votes
8 answers

How to specify a compiler in CMake?

I would like to use the IAR compiler. I noticed CMake has already have a bunch of files about this compiler: https://github.com/jevinskie/cmake/blob/master/Modules/Compiler/IAR.cmake From what I read the common solution is to specify manually ALL…
nowox
  • 25,978
  • 39
  • 143
  • 293
106
votes
6 answers

Function vs. Macro in CMake

The official document of CMake 2.8.12 says about macro When it is invoked, the commands recorded in the macro are first modified by replacing formal parameters (${arg1}) with the arguments passed, and then invoked as normal commands. and about…
Yantao Xie
  • 12,300
  • 15
  • 49
  • 79
103
votes
3 answers

CMake and finding other projects and their dependencies

Imagine the following scenario: Project A is a shared library which has several dependencies (LibA, LibB, and LibC). Project B is an executable that has a dependency on project A, and therefore requires all of Project A's dependencies also in order…
blockchaindev
  • 3,134
  • 3
  • 22
  • 30
103
votes
6 answers

Compile with /MT instead of /MD using CMake

I'm using CMake on windows with the Windows SDK and NMake Makefiles. By default it compiles with the /MD compiler switch. How can I change it to compile with the /MT switch instead?
Josh
  • 6,046
  • 11
  • 52
  • 83
103
votes
5 answers

How to copy contents of a directory into build directory after make with CMake?

I've got some config files (xml, ini, ...) in the config directory next to the source files. How can I copy all the files in the config directory into the build directory (next to the executable file) each time I make the project?
B Faley
  • 17,120
  • 43
  • 133
  • 223
102
votes
1 answer

How do I initialize a CMake variable with the result of a shell command

Is there a way to set a variable in a CMake script to the output of a shell command? Something like SET(FOO COMMAND "echo bar") would come to mind
Sasha
  • 1,559
  • 2
  • 10
  • 10
101
votes
3 answers

Installing cmake with home-brew

I'm new to programming. Can you please help me install cmake? I typed brew install cmake. What should I do next?
Raag Saluja
  • 1,037
  • 2
  • 7
  • 5
101
votes
3 answers

How to list all CMake build options and their default values?

How can I list cmake default build option in command-line? I need to build OpenCV libraries from source. Before that, I want to know what are the default build settings.
Haris
  • 13,645
  • 12
  • 90
  • 121
100
votes
2 answers

Why is a variable value not available after add_subdirectory-ing a CMakeLists.txt that defines it? How can I make it so?

I have a CMakeLists.txt in my project root and one in my /src folder. The one in the /src folder only contains a variable with the .cpp files (set (SOURCEFILES main.cpp foo.cpp)) and in the root CMakeLists.txt I do add_subdirectory(src) and later I…
blubberbernd
  • 3,641
  • 8
  • 35
  • 46
100
votes
2 answers

What are ALL_BUILD and ZERO_CHECK and do I need them?

I've created a simple CMakeLists.txt: cmake_minimum_required(VERSION 2.8) project (HelloWorld) add_executable (HelloWorld main.cpp) When I generate a VS2012 or VS2010 project from CMake, however, I get these 2 additional entries - ALL_BUILD and…
sashoalm
  • 75,001
  • 122
  • 434
  • 781
98
votes
14 answers

CMake: Visual Studio 15 2017 could not find any instance of Visual Studio

When I am trying to install CMake I get the error: Visual Studio 15 2017 could not find any instance of Visual Studio. I am using Windows 7 and Visual Studio 2017. The CMakeOutput.log file writes: The system is: Windows - 6.1.7601 - AMD64 Any…
barkman345
  • 1,021
  • 1
  • 7
  • 8
98
votes
4 answers

CMake Multiple line comments - Block Comment

Is there any way to comment a block in CMake in notepad++ editor? I have tried searching on Google, but couldn't find much. Help is needed! Thanks,
thestar
  • 4,959
  • 2
  • 28
  • 22
96
votes
8 answers

How to change the build type to Release mode in cmake?

I am trying to build a project in Release mode. By default it is built in debug mode. I am setting the variable CMAKE_BUILD_TYPE to "Release" in CMakeLists.txt. But it is still building the project in debug mode. When I pass "Release" as the build…
123r789
  • 1,600
  • 3
  • 22
  • 33