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
55
votes
2 answers

CMake with subdirectories

I'm trying to set up my project to compile correctly using CMake. My directory looks like this: root |- bin | |- // Where I want to build CMake from - using 'cmake ..' |- build | |- |- include | |- database | | |- database.h |-…
Van-Sama
  • 1,154
  • 4
  • 14
  • 21
55
votes
4 answers

How can I check in CMake whether a list contains a specific entry?

I want to check whether a lists contains a specific entry like in the following code snippet: macro(foo) if ($(ARGN} contains "bar") ... endif endmacro() CMake does not offer a contains. What is best / easiest way to get the desired result? In…
usr1234567
  • 21,601
  • 16
  • 108
  • 128
55
votes
4 answers

CMake... ccmake or cmake?

What is the difference between cmake and ccmake? I have the Ubuntu package cmake installed, and on my Windows computer, I have the installer from the website, but neither have the command ccmake available. Yet, the tutorials, seem to reference it…
Nick Bolton
  • 38,276
  • 70
  • 174
  • 242
55
votes
5 answers

cmake: Selecting a generator within CMakeLists.txt

I would like to force CMake to use the "Unix Makefiles" generator from within CMakeLists.txt. This is the command I use now. cmake -G "Unix Makefiles" . I would like it to be this. cmake . When running on windows with VC installed and a custom…
Ted
  • 14,465
  • 6
  • 28
  • 28
54
votes
2 answers

CMake: How to pass preprocessor macros

How can I pass a macro to the preprocessor? For example, if I want to compile some part of my code because a user wants to compile unit test, I would do this: #ifdef _COMPILE_UNIT_TESTS_ BLA BLA #endif //_COMPILE_UNIT_TESTS_ Now I need to pass…
Killrazor
  • 6,856
  • 15
  • 53
  • 69
54
votes
4 answers

How to compile GLUT + OpenGL project with CMake and Kdevelop in linux?

As the titles says I can't seem to build the project with OpenGL and Glut. I get Undefined reference errors for OpenGL functions. I tried doing : project(testas) find_package(OpenGL) find_package(GLUT) add_executable(testas main.cpp) But that…
Ren
  • 801
  • 1
  • 8
  • 12
54
votes
3 answers

For the cmake "include" command, what is the difference between a file and a module?

I use some libraries that I don't want built as part of every project that uses them. A very understandable example is LLVM, which has 78 static libraries. Even having the cmake code to find and import these in every cmakefile is excessive. The…
user180247
54
votes
2 answers

How can I build Rust code with a C++/Qt/CMake project?

I have an existing C++/Qt project built with CMake. I'd like to start adding Rust code which I can invoke from inside the main C++ codebase. What's the right way to structure the project? Current project…
Daenyth
  • 35,856
  • 13
  • 85
  • 124
54
votes
4 answers

How to make colorized message() with CMake?

I want to have message function in CMakeLists.txt which output colorized text. Maybe an escape sequence. For example: message("\x1b[31m;This text must be in red") It don't work. I got: Syntax error in cmake code…
Ivan Romanov
  • 1,138
  • 1
  • 9
  • 24
53
votes
3 answers

How to include external library (boost) into CLion C++ project with CMake?

I have the following setup for C++ development: OS X Yosemite CLion 140.2310.6 (a cross-plattform C/C++-IDE by JetBrains using CMake as build system) installed boost via brew install boost into /usr/local/Cellar/boost/ Now, my goal is to setup a…
nburk
  • 22,409
  • 18
  • 87
  • 132
53
votes
2 answers

cmake : Set environment variables from a script

I have a script that sets all variables needed for the cross-compilation. Here is just part of it : export CONFIG_SITE=~/workspace/eldk-5.4/powerpc/site-config-powerpc-linux export CC="powerpc-linux-gcc -m32 -mhard-float…
BЈовић
  • 62,405
  • 41
  • 173
  • 273
53
votes
5 answers

why "make" before "make install"

I know the process of installing from source are. ./configure make make install But why "make" before /etc/cups/cupsd.conf, why not just do "make install"? My understanding so far is "make" only compile the source into executable file, and "make…
aggressionexp
  • 690
  • 1
  • 5
  • 10
53
votes
11 answers

Changing CMAKE_CXX_FLAGS in project

I have the following content in my CMakeLists.txt: project( Matfile ) SET ( CMAKE_CXX_FLAGS "-std=c++0x" ) set ( SOURCES "foo.cpp" "bar.cpp" ) add_library( Matfile ${SOURCES} ) As you may imagine, what I want to…
Spiros
  • 2,156
  • 2
  • 23
  • 42
52
votes
3 answers

Extending setuptools extension to use CMake in setup.py?

I'm writing a Python extension that links a C++ library and I'm using cmake to help with the build process. This means that right now, the only way I know how to bundle it, I have to first compile them with cmake before I can run setup.py…
loneraver
  • 1,282
  • 2
  • 15
  • 22
52
votes
2 answers

Why add header files into the add_library/add_executable commands in CMake?

I had a project which uses CMake as build tool and made a simple template for me and my colleagues to use. As I searched for best and easy to use practices online, I've came across different approaches to make a library. In this template, I've…
Ahmet Ipkin
  • 882
  • 1
  • 10
  • 20