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.

Filter by
Sorted by
Tagged with
628 votes
28 answers
758k views

Looking for a 'cmake clean' command to clear up CMake output

Just as make clean deletes all the files that a makefile has produced, I would like to do the same with CMake. All too often I find myself manually going through directories removing files like ...
Bill Cheatham's user avatar
581 votes
6 answers
760k views

Debug vs Release in CMake

In a GCC compiled project, How do I run CMake for each target type (debug/release)? How do I specify debug and release C/C++ flags using CMake? How do I express that the main executable will be ...
Cartesius00's user avatar
535 votes
3 answers
278k views

What is the difference between using a Makefile and CMake to compile the code?

I code in C/C++ and use a (GNU) Makefile to compile the code. I can do the same with CMake and get a Makefile. However, what is the difference between using a Makefile and CMake to compile the code?
rish's user avatar
  • 5,845
461 votes
9 answers
272k views

What is CMake equivalent of 'configure --prefix=DIR && make all install '?

I do cmake . && make all install. This works, but installs to /usr/local. I need to install to a different prefix (for example, to /usr). What is the cmake and make command line to install ...
Andrei's user avatar
  • 8,774
428 votes
6 answers
407k views

Define a preprocessor macro through CMake

How do I define a preprocessor variable through CMake? The equivalent code would be #define foo.
Mythli's user avatar
  • 6,205
424 votes
17 answers
556k views

How do I activate C++ 11 in CMake?

When I try to run a CMake generated makefile to compile my program, I get the error that range based for loops are not supported in C++ 98 mode. I tried adding add_definitions(-std=c++0x) to my ...
Subhamoy S.'s user avatar
  • 6,686
418 votes
11 answers
908k views

How to properly add include directories with CMake

About a year ago I asked about header dependencies in CMake. I realized recently that the issue seemed to be that CMake considered those header files to be external to the project. At least, when ...
Matthieu M.'s user avatar
362 votes
8 answers
252k views

Using CMake with GNU Make: How can I see the exact commands?

I use CMake with GNU Make and would like to see all commands exactly (for example how the compiler is executed, all the flags etc.). GNU make has --debug, but it does not seem to be that helpful are ...
Nils's user avatar
  • 13.6k
341 votes
12 answers
372k views

Switching between GCC and Clang/LLVM using CMake

I have a number of projects built using CMake and I'd like to be able to easily switch between using GCC or Clang/LLVM to compile them. I believe (please correct me if I'm mistaken!) that to use Clang ...
Rezzie's user avatar
  • 4,883
308 votes
7 answers
225k views

CMake: Print out all accessible variables in a script

I'm wondering if there is a way to print out all accessible variables in CMake. I'm not interested in the CMake variables - as in the --help-variables option. I'm talking about my variables that I ...
Michael's user avatar
  • 3,694
302 votes
8 answers
788k views

How do I add a linker or compile flag in a CMake file?

I am using the arm-linux-androideabi-g++ compiler. When I try to compile a simple "Hello, World!" program it compiles fine. When I test it by adding a simple exception handling in that code it works ...
solti's user avatar
  • 4,459
294 votes
5 answers
118k views

What are the differences between Autotools, Cmake and Scons?

What are the differences between Autotools, Cmake and Scons?
Wazery's user avatar
  • 15.7k
283 votes
10 answers
324k views

How do I make CMake output into a 'bin' dir?

I'm currently constructing a project with a plugin structure. I'm using CMake to compile the project. The plugins are compiled in separate directories. My problem is that CMake compiles and saves the ...
Martin Kristiansen's user avatar
272 votes
3 answers
310k views

What's the CMake syntax to set and use variables?

I'm asking this as a reminder to myself the next time I use CMake. It never sticks, and Google results aren't great. What's the syntax to set and use variables in CMake?
CivFan's user avatar
  • 14.3k
263 votes
4 answers
249k views

cmake and libpthread

I'm running RHEL 5.1 and use gcc. How I tell cmake to add -pthread to compilation and linking?
dimba's user avatar
  • 27.2k
258 votes
3 answers
174k views

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 ...
Ujjwal Aryan's user avatar
  • 3,977
251 votes
19 answers
458k views

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(...
Allan's user avatar
  • 3,071
242 votes
3 answers
107k views

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 ...
Nav's user avatar
  • 20.3k
239 votes
5 answers
322k views

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 ...
MarcDefiant's user avatar
  • 6,789
226 votes
4 answers
343k views

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 │   ├── ...
Florian M's user avatar
  • 2,905
217 votes
2 answers
128k views

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 ...
101010's user avatar
  • 15.3k
214 votes
5 answers
121k views

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 ...
leedm777's user avatar
  • 23.8k
211 votes
5 answers
264k views

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 ...
martjno's user avatar
  • 4,679
207 votes
4 answers
145k views

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's user avatar
  • 6,734
205 votes
8 answers
129k views

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. ...
Marenz's user avatar
  • 2,802
191 votes
2 answers
136k views

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: ...
Grzenio's user avatar
  • 36.3k
189 votes
10 answers
224k views

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) ...
mongolrgata's user avatar
  • 1,997
185 votes
5 answers
412k views

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 ...
Prime's user avatar
  • 4,163
184 votes
5 answers
110k views

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's user avatar
  • 14.3k
182 votes
23 answers
592k views

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. ...
Caio Fontes's user avatar
  • 2,023
181 votes
10 answers
207k views

OS specific instructions in CMAKE: How to?

I am a beginner to CMAKE. Below is a simple cmake file which works well in mingw environment windows. The problem is clearly with target_link_libraries() function of CMAKE where I am linking ...
Prasad's user avatar
  • 1,961
181 votes
1 answer
132k views

Cause CMAKE to generate an error

How can I get CMAKE to generate an error on a particular condition. That is, I want something like this: if( SOME_COND ) error( "You can't do that" ) endif()
edA-qa mort-ora-y's user avatar
178 votes
2 answers
122k views

Difference between CMAKE_CURRENT_SOURCE_DIR and CMAKE_CURRENT_LIST_DIR

From the Wiki: CMAKE_CURRENT_SOURCE_DIR this is the directory where the currently processed CMakeLists.txt is located in CMAKE_CURRENT_LIST_DIR (since 2.8.3) this is the directory of the listfile ...
William Payne's user avatar
173 votes
8 answers
227k views

How do you add Boost libraries in CMakeLists.txt?

I need to add Boost libraries into my CMakeLists.txt. How do you do it or how do you add it?
laksh's user avatar
  • 2,299
172 votes
7 answers
163k views

How to set warning level in CMake?

How to set the warning level for a project (not the whole solution) using CMake? Should work on Visual Studio and GCC. I found various options but most seem either not to work or are not consistent ...
Wernight's user avatar
  • 37k
171 votes
8 answers
328k views

How to specify new GCC path for CMake

My OS is centos which has a default gcc in path /usr/bin/gcc. But it is old, I need a new version of gcc. So I install a new version in a new path /usr/local/bin/gcc. But when I run cmake, it still ...
tidy's user avatar
  • 4,877
168 votes
12 answers
111k views

Using CMake, how do I get verbose output from CTest?

I'm using CMake to build my project. I have added a unit test binary which is using the Boost unit testing framework. This one binary contains all of the unit tests. I've added that binary to be run ...
Skrymsli's user avatar
  • 5,273
165 votes
6 answers
411k views

CMake how to set the build directory to be different than source directory

I'm pretty new to CMake, and read a few tutorials on how to use it, and wrote some complicated 50 lines of CMake script in order to make a program for 3 different compilers. This probably concludes ...
The Quantum Physicist's user avatar
160 votes
12 answers
194k views

How to start working with GTest and CMake

I have recently been sold on using CMake for compiling my C++ projects, and would now like to start writing some unit tests for my code. I have decided to use the Google Test utility to help with this,...
Chris's user avatar
  • 8,130
159 votes
5 answers
55k views

CMake target_link_libraries Interface Dependencies

I am new to CMake and a bit confused with the PUBLIC, PRIVATE and INTERFACE keywords related to target_link_libraries(). Documentation mentions that they can be used to specify both the link ...
Sirish Kumar Bethala's user avatar
158 votes
3 answers
240k views

How to set a CMake option() at command line

I created a CMakeLists.txt that contains the following project(P4V) cmake_minimum_required(VERSION 2.6) option(BUILD_STATIC_LIBS "Build the static library" ON) option(BUILD_SHARED_LIBS "Build the ...
Denilson Amorim's user avatar
152 votes
2 answers
53k views

CMake target_include_directories meaning of scope

What is the meaning of the keyword PUBLIC, PRIVATE, and INTERFACE related to CMake's target_include_directories?
Sirish Kumar Bethala's user avatar
146 votes
4 answers
112k views

Override compile flags for single files

I would like to use a global set of flags for compiling a project, meaning that at my top-level CMakeLists.txt file I have specified: ADD_DEFINITIONS ( -Wall -Weffc++ -pedantic -std=c++0x ) However, ...
J.B. Brown's user avatar
  • 1,793
145 votes
10 answers
254k views

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 -- ...
Chris Covert's user avatar
  • 2,764
145 votes
4 answers
335k views

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 ...
David Z's user avatar
  • 130k
145 votes
7 answers
184k views

CMake: How to build external projects and include their targets

I have a Project A that exports a static library as a target: install(TARGETS alib DESTINATION lib EXPORT project_a-targets) install(EXPORT project_a-targets DESTINATION lib/alib) Now I want to use ...
mirkokiefer's user avatar
  • 3,427
142 votes
7 answers
215k views

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 `boost::...
Szymon Lipiński's user avatar
142 votes
31 answers
278k views

CMake does not find Visual C++ compiler

After installing Visual Studio 2015 and running CMake on a previous project, CMake errors stating that it could not find the C compiler. The C compiler identification is unknown The CXX compiler ...
Asher's user avatar
  • 2,901
141 votes
3 answers
130k views

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 ...
Arne's user avatar
  • 8,187
140 votes
4 answers
49k views

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 ...
rozzy's user avatar
  • 2,908

1
2 3 4 5
571