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

How to link C++ program with Boost using CMake

What should my CMake file look like for linking my program with the Boost library under Ubuntu? The errors shown during running make: main.cpp:(.text+0x3b): undefined reference to…
Szymon Lipiński
  • 27,098
  • 17
  • 75
  • 77
138
votes
4 answers

How do I tell CMake to link in a static library in the source directory?

I have a small project with a Makefile which I'm trying to convert to CMake, mostly just to get experience with CMake. For purposes of this example, the project contains a source file (C++, though I don't think the language is particularly relevant)…
David Z
  • 128,184
  • 27
  • 255
  • 279
138
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,828
  • 6
  • 25
  • 35
138
votes
10 answers

CMake unable to determine linker language with C++

I'm attempting to run a cmake hello world program on Windows 7 x64 with both Visual Studio 2010 and Cygwin, but can't seem to get either to work. My directory structure is as follows: HelloWorld -- CMakeLists.txt -- src/ -- -- CMakeLists.txt -- --…
Chris Covert
  • 2,684
  • 3
  • 24
  • 31
133
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 understanding 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…
Arne
  • 7,921
  • 9
  • 48
  • 66
133
votes
7 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,975
  • 3
  • 14
  • 15
132
votes
6 answers

How to properly set CMAKE_INSTALL_PREFIX from the command-line

I want to generate a Makefile with an install target, making installation to /usr instead of default /usr/local. Assuming that the build directory is a subdirectory of the source directory, I execute: cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr…
Alex F
  • 42,307
  • 41
  • 144
  • 212
131
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
  • 2,157
  • 2
  • 17
  • 23
130
votes
6 answers

How do I use CMake?

I am trying to use CMake in order to compile opencv. I am reading the tutorial but can't understand what is CMakeLists files and how is it connected to the gui of CMake? Also couldn't understand what are makefiles, are they the same is CMakeLists? …
lital maatuk
  • 5,921
  • 20
  • 57
  • 79
130
votes
6 answers

What is the proper way to use `pkg-config` from `cmake`?

Looking around on the net I have seen a lot of code like this: include(FindPkgConfig) pkg_search_module(SDL2 REQUIRED sdl2) target_include_directories(app SYSTEM PUBLIC ${SDL2_INCLUDE_DIRS}) target_link_libraries(app ${SDL2_LIBRARIES}) However…
Grumbel
  • 6,585
  • 6
  • 39
  • 50
128
votes
2 answers

Adding command line options to CMake

I'm building a large library using CMake, and I would like users to be able to selectively enable/disable certain parts of my build process. How can I add command-line options to my CMake build, e.g. so that users may type something like cmake…
rcv
  • 6,078
  • 9
  • 43
  • 63
128
votes
8 answers

How to enable C++17 in CMake

I'm using VS 15.3, which supports integrated CMake 3.8. How can I target C++17 without writing flags for each specific compilers? My current global settings don't work: #…
MiP
  • 5,846
  • 3
  • 26
  • 41
126
votes
12 answers

How to copy DLL files into the same folder as the executable using CMake?

We use CMake for generating the Visual Studio files of our sources in our SVN. Now my tool requires some DLL files to be in the same folder as the executable. The DLL files are in a folder alongside the source. How can I change my CMakeLists.txt…
Mat
  • 4,281
  • 9
  • 44
  • 66
123
votes
16 answers

Cmake doesn't find Boost

I'm trying to configure a project using CMake, but it fails to find Boost libraries even though they are in the specified folder. I have specified Boost_INCLUDE_DIR, Boost_LIBRARYDIR and BOOST_ROOT , but I still get an error saying that CMake is not…
Ivan Gromov
  • 4,195
  • 9
  • 41
  • 57
123
votes
3 answers

How do I add a library path in cmake?

I have 2 folders "inc" and "lib" in my project which have headers and static libs respectively. How do I tell cmake to use those 2 directories for include and linking respectively?
grasevski
  • 2,894
  • 2
  • 21
  • 22