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
246
votes
3 answers

What is the difference between include_directories and target_include_directories in CMake?

I have a directory structure for my C++ code which goes like this : | |->include |->src I am writing a CMakeLists.txt file for my code. I want to understand the difference between include_directories and target_include_directories in CMake. What…
Ujjwal Aryan
  • 3,827
  • 3
  • 20
  • 31
242
votes
18 answers

CMake not able to find OpenSSL library

I am trying to install a software that uses cmake to install itself. When I run cmake .. on the command line, it gives me following error in the CMakeLists.txt on the line that says find_package(OpenSSL REQUIRED): -- Could NOT find Git (missing: …
Allan
  • 2,971
  • 4
  • 24
  • 28
234
votes
3 answers

How exactly does CMake work? Why are so many files generated?

What exactly was going on behind the scenes when for such a small CMakeLists.txt file, cmake_minimum_required (VERSION 2.6) project(Tutorial) add_executable(Tutorial tutorial.cpp) and such a small tutorial.cpp int main() { return 0; } there are so…
Nav
  • 19,885
  • 27
  • 92
  • 135
226
votes
5 answers

What use is find_package() when you need to specify CMAKE_MODULE_PATH?

I'm trying to get a cross-plattform build system working using CMake. Now the software has a few dependencies. I compiled them myself and installed them on my system. Some example files which got installed: -- Installing:…
MarcDefiant
  • 6,649
  • 6
  • 29
  • 49
219
votes
4 answers

How to create a shared library with cmake?

I have written a library that I used to compile using a self-written Makefile, but now I want to switch to cmake. The tree looks like this (I removed all the irrelevant files): . ├── include │   ├── animation.h │   ├── buffers.h │   ├── ... │   ├──…
Florian M
  • 2,815
  • 3
  • 17
  • 14
206
votes
2 answers

What is the idiomatic way in CMAKE to add the -fPIC compiler option?

I've come across at least 3 ways to do this and I'm wondering which is the idiomatic way. This needs to be done almost universally to any static library. I'm surprised that the Makefile generator in CMake doesn't automatically add this to static…
101010
  • 14,866
  • 30
  • 95
  • 172
206
votes
5 answers

Automatically add all files in a folder to a target using CMake?

I am considering switching a cross platform project from separate build management systems in Visual C++, XCode and makefiles to CMake. One essential feature I need is to add automatically all files in a directory to a target. While this is easy to…
martjno
  • 4,589
  • 5
  • 34
  • 31
203
votes
5 answers

In CMake, how can I test if the compiler is Clang?

We have a set of cross-platform CMake build scripts, and we support building with Visual C++ and GCC. We're trying out Clang, but I can't figure out how to test whether or not the compiler is Clang with our CMake script. What should I test to see if…
leedm777
  • 23,444
  • 10
  • 58
  • 87
199
votes
7 answers

Is it better to specify source files with GLOB or each file individually in CMake?

CMake offers several ways to specify the source files for a target. One is to use globbing (documentation), for example: FILE(GLOB MY_SRCS dir/*) Another method is to specify each file individually. Which way is preferred? Globbing seems easy, but…
Marenz
  • 2,722
  • 3
  • 20
  • 19
195
votes
3 answers

Creating a directory in CMake

In CMake, I want to create a directory if it doesn't already exist. How can I do this?
Jookia
  • 6,544
  • 13
  • 50
  • 60
187
votes
2 answers

CMake: Project structure with unit tests

I am trying to structure my project to include the production sources (in src subfolder) and tests (in test subfolder). I am using CMake to build this. As a minimal example I have the following files: CMakeLists.txt: cmake_minimum_required (VERSION…
Grzenio
  • 35,875
  • 47
  • 158
  • 240
179
votes
5 answers

Is it possible to get CMake to build both a static and shared library at the same time?

Same source, all that, just want a static and shared version both. Easy to do?
gct
  • 14,100
  • 15
  • 68
  • 107
177
votes
5 answers

CMake link to external library

How to get CMake to link an executable to an external shared library that is not build within the same CMake project? Just doing target_link_libraries(GLBall ${CMAKE_BINARY_DIR}/res/mylib.so) gives the error make[2]: *** No rule to make target…
Prime
  • 4,081
  • 9
  • 47
  • 64
177
votes
22 answers

CMake error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found

I'm trying make a Visual Studio solution with CMake to compile the latest version of aseprite and CMake keeps giving me the: No CMAKE_C_COMPILER could be found. No CMAKE_CXX_COMPILER could be found. I've already downloaded GCC, and I'm using…
Caio Fontes
  • 1,973
  • 2
  • 12
  • 12
176
votes
8 answers

Copy file from source directory to binary directory using CMake

I'm trying to create a simple project on CLion. It uses CMake to generate Makefiles to build project (or some sort of it) All I need to is transfer some non-project file (some sort of resource file) to binary directory each time when I run the my…
mongolrgata
  • 1,867
  • 2
  • 11
  • 9