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
123
votes
4 answers

How do I exclude a single file from a cmake `file(GLOB ... )` pattern?

My CMakeLists.txt contains this line: file(GLOB lib_srcs Half/half.cpp Iex/*.cpp IlmThread/*.cpp Imath/*.cpp IlmImf/*.cpp) and the IlmImf folder contains b44ExpLogTable.cpp, which I need to exclude from the build. How to achieve that?
berak
  • 39,159
  • 9
  • 91
  • 89
122
votes
1 answer

How is CMake used?

It is notoriously difficult to get any useful information on CMake as a beginner. So far, I've seen a few tutorials on how to set up some very basic project or another. However, none of these explain the reasoning behind anything that is shown in…
leinaD_natipaC
  • 4,299
  • 5
  • 21
  • 40
122
votes
10 answers

How to Use CCache with CMake?

I would like to do the following: If CCache is present in PATH, use "ccache g++" for compilation, else use g++. I tried writing a small my-cmake script containing CC="ccache gcc" CXX="ccache g++" cmake $* but it does not seem to work (running…
amit kumar
  • 20,438
  • 23
  • 90
  • 126
120
votes
4 answers

How to retrieve a user environment variable in CMake (Windows)

I know how to retrieve a normal machine wide environment variable in CMAKE using $ENV{EnvironmentVariableName} but I can not retrieve a user specific environment variable. Is it possible and how?
Lars Bilke
  • 4,940
  • 6
  • 45
  • 63
120
votes
12 answers

Using pre-compiled headers with CMake

I have seen a few (old) posts on the 'net about hacking together some support for pre-compiled headers in CMake. They all seem a bit all-over the place and everyone has their own way of doing it. What is the best way of doing it currently?
Glutinous
  • 1,201
  • 2
  • 9
  • 3
116
votes
7 answers

How to split strings across multiple lines in CMake?

I usually have a policy in my project, to never create lines in text files that exceed a line length of 80, so they are easily editable in all kinds of editors (you know the deal). But with CMake I get the problem that I do not know how to split a…
Lukas Schmelzeisen
  • 2,934
  • 4
  • 24
  • 30
112
votes
16 answers

Unable to find CMake in Android Studio

I need to add C/C++ code in my Android program for which I needed LLDB, CMake, and NDK. I found LLDB and NDK in SDK manager, but CMake is missing from there. I tried manually downloading it from the CMake official site and found out that for Android…
ashish mishra
  • 1,401
  • 2
  • 10
  • 13
112
votes
1 answer

What is the modern method for setting general compile flags in CMake?

There are multiple mechanisms offered by CMake for getting flags to the compiler: CMAKE__FLAGS_ variables add_compile_options command set_target_properties command Is there one method that is preferred over the other in modern use?…
Peter Clark
  • 2,863
  • 3
  • 23
  • 37
112
votes
7 answers

How can I debug CMakeLists.txt files?

How can I debug CMakeLists.txt files (at least doing things like listing of variables) other than just using the message() command?
Peter Petrik
  • 9,701
  • 5
  • 41
  • 65
112
votes
10 answers

How to build & install GLFW 3 and use it in a Linux project

GLFW3 Last night I was working late trying to build the GLFW 3 packages for Linux from source. This process took me a very long time, about 3 hours in total, partly because I am unfamiliar with CMake, and partly because I am was unfamiliar with…
FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225
112
votes
4 answers

Set CFLAGS and CXXFLAGS options using CMake

I just want to debug some code running on Linux and I need a debug build (-O0 -ggdb). So I added these things to my CMakeLists.txt file: set(CMAKE_BUILD_TYPE DEBUG) set(CMAKE_C_FLAGS "-O0 -ggdb") set(CMAKE_C_FLAGS_DEBUG "-O0…
majie
  • 1,449
  • 2
  • 11
  • 10
110
votes
1 answer

How to properly link libraries with cmake?

I can't get the additional libraries I am working with to link into my project properly. I am using CLion, which uses cmake to build it's projects. I am trying to use several libraries in conjunction with OpenGL to texture some objects. I initially…
Cache Staheli
  • 3,510
  • 7
  • 32
  • 51
110
votes
3 answers

How to build x86 and/or x64 on Windows from command line with CMAKE?

One way to get cmake to build x86 on Windows with Visual Studio is like so: Start Visual Studio Command prompt for x86 Run cmake: cmake -G "NMake Makefiles" \path_to_source\ nmake One way to get cmake to build x64 on Windows with Visual Studio is…
101010
  • 14,866
  • 30
  • 95
  • 172
110
votes
3 answers

CMAKE_BUILD_TYPE is not being used in CMakeLists.txt

I'm having trouble setting my default build configuration to Release. In my CMakeLists.txt file, I set CMAKE_BUILD_TYPE at the top of the file with: #enable Release ALWAYS, configure vars set(CMAKE_BUILD_TYPE Release) set(EXECUTABLE_NAME…
Syntactic Fructose
  • 18,936
  • 23
  • 91
  • 177
109
votes
11 answers

CMake & CTest : make test doesn't build tests

I'm trying CTest in CMake in order to automatically run some of my tests using make test target. The problem is CMake does not "understand" that the test I'm willing to run has to be built since it is part of the project. So I'm looking for a way to…
claf
  • 9,043
  • 17
  • 62
  • 79