All Questions

Tagged with
Filter by
Sorted by
Tagged with
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
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
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
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
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
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
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
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
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
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
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
138 votes
6 answers
234k views

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 ...
lital maatuk's user avatar
  • 6,101
136 votes
9 answers
206k views

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: # https://cmake.org/cmake/help/...
MiP's user avatar
  • 6,226
129 votes
10 answers
78k views

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++"...
amit kumar's user avatar
  • 20.7k
127 votes
3 answers
384k views

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's user avatar
  • 2,964
121 votes
12 answers
97k views

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 ...
Glutinous's user avatar
  • 1,211
115 votes
1 answer
240k views

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 ...
Cache Staheli's user avatar
110 votes
5 answers
105k views

How to copy contents of a directory into build directory after make with CMake?

I've got some config files (xml, ini, ...) in the config directory next to the source files. How can I copy all the files in the config directory into the build directory (next to the executable file) ...
B Faley's user avatar
  • 17.7k
109 votes
7 answers
172k views

Using CMake to generate Visual Studio C++ project files

I am working on an open source C++ project, for code that compiles on Linux and Windows. I use CMake to build the code on Linux. For ease of development setup and political reasons, I must stick to ...
amit kumar's user avatar
  • 20.7k
102 votes
2 answers
40k views

What are ALL_BUILD and ZERO_CHECK and do I need them?

I've created a simple CMakeLists.txt: cmake_minimum_required(VERSION 2.8) project (HelloWorld) add_executable (HelloWorld main.cpp) When I generate a VS2012 or VS2010 project from CMake, however, I ...
sashoalm's user avatar
  • 77.3k
97 votes
5 answers
131k views

In CLion, header only library: file "does not belong to any project target, code insight features might not work properly"

I have a header-only library project set up with the cmake command: add_library(my_library INTERFACE) and I also added target_sources(my_library INTERFACE ${MY_LIRBARY_HEADER_FILES}) but when I ...
xaxxon's user avatar
  • 19.5k
95 votes
3 answers
103k views

Adding multiple executables in CMake

My code in a C++ project is organised as follows I have several .cpp and .h files which contains my classes I have several .cxx files which have to be compiled against the .cpp files and some ...
ssb's user avatar
  • 7,442
91 votes
6 answers
95k views

What's the proper way to enable AddressSanitizer in CMake that works in Xcode

I've added AddressSanitizer flag as follow: set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") Everything builds and runs fine when using Unix Makefiles. The problem comes when ...
ObjSal's user avatar
  • 1,614
88 votes
7 answers
60k views

How to detect C++11 support of a compiler with CMake

Is there a way to let CMake detect automatically if a compiler supports C++11 or not? As it would be nice to inform the users during the CMake run that the code will not compile as the compiler does ...
tune2fs's user avatar
  • 7,675
85 votes
5 answers
125k views

How can I make CMake use GCC instead of Clang on Mac OS X?

I can't find any info on it, but only the other way around (e.g., how to set CMake to use clang). I've installed gcc-4.8 using brew, setup all dependencies, headers, etc, and now CMake refuses to use ...
Ælex's user avatar
  • 14.6k
84 votes
5 answers
111k views

How to use CMAKE_EXPORT_COMPILE_COMMANDS?

I've been trying to use clang-modernize with CMAKE_EXPORT_COMPILE_COMMANDS as recommended in the help of this tool. With this option cmake generates a JSON file containing compile info like include ...
dzada's user avatar
  • 5,614
83 votes
3 answers
56k views

Overriding a default option(...) value in CMake from a parent CMakeLists.txt

I am trying to include several third-party libraries in my source tree with minimal changes to their build system for ease of upgrading. They all use CMake, as do I, so in my own CMakeLists.txt I can ...
user avatar
80 votes
3 answers
160k views

CMake with include and source paths - basic setup

I'm trying to set up a test project looking like my own project just to get things working first and it looks like this: /MainProject/inc/main.h /MainProject/src/main.cpp /LibProject/inc/test.h /...
bitgregor's user avatar
  • 1,125
80 votes
13 answers
49k views

rc.exe no longer found in VS 2015 Command Prompt

I just installed Windows 10 Creators Update (version 10.0.15063). I have multiple versions of Visual Studio installed (2012, 2013, 2015 and 2017). I installed VS 2017 only a couple weeks ago. ...
François Beaune's user avatar
78 votes
4 answers
33k views

How can I use the tool 'Include What You Use' together with CMake to detect unused headers?

The tool Include What You Use can be used to detect unneeded headers. I am using CMake for my C++ software project. How can I instruct CMake to run Include What You Use automatically on the source ...
Erik Sjölund's user avatar
76 votes
6 answers
78k views

Linking different libraries for Debug and Release builds in Cmake on windows?

So I've got a library I'm compiling and I need to link different third party things in depending on if it's the debug or release build (specifically the release or debug versions of those libraries). ...
gct's user avatar
  • 14.3k
74 votes
8 answers
127k views

How to generate CMakeLists.txt?

I need some pointers/advice on how to automatically generate CMakeLists.txt files for CMake. Does anyone know of any existing generators? I've checked the ones listed in the CMake Wiki but ...
celavek's user avatar
  • 5,635
72 votes
1 answer
52k views

CMake: target_include_directories() prints an error when I try to add the source directory itself, or one of its subdirectories

I am writing a C++ library (header-only) and am using CMake to generate my (Visual Studio) project and solution files. I'm also writing a test suite, which is part of the same CMake project. My ...
JPNotADragon's user avatar
  • 2,120
72 votes
6 answers
196k views

cmake - find_library - custom library location

I'm currently trying to get CMake running for my project (on windows). I want to use a custom location where all libraries are installed. To inform CMake about that path I tried to do that: set(...
Daniel's user avatar
  • 3,053
71 votes
2 answers
69k views

Does set_target_properties in CMake override CMAKE_CXX_FLAGS?

At the beginning of my CMake project, I'm setting general compilation flags in the variable CMAKE_CXX_FLAGS, like set(CMAKE_CXX_FLAGS "-W -Wall ${CMAKE_CXX_FLAGS}") Later on, I need to append ...
Milan Hanus's user avatar
71 votes
3 answers
79k views

How can I build a C++ project with multiple interdependent subdirectories?

I have a C++ project where I've used directories as more of an organizational element -- the way one might use packages in Java or directories in PHP. Directories are not intended to be self-...
Daniel Bingham's user avatar
69 votes
3 answers
87k views

How to get CMake to pass either std=c++14/c++1y or c++17/c++1z based on GCC version?

GCC 4.x doesn't accept the --std=c++14 switch for C++14 code - it takes --std=c++1y instead. Later versions take --std=c++1z but (probably) not --std=c++17 which has not been set yet (writing this in ...
einpoklum's user avatar
  • 124k
69 votes
8 answers
167k views

CMake is not able to find BOOST libraries

I tried everything like: Configure environment variable Make fresh build Re-install BOOST from source sudo apt-get install libboost-all-dev But still getting following Errors: CMake Error at /usr/...
Amit Pal's user avatar
  • 10.8k
68 votes
5 answers
77k views

How can I define a C++ preprocessor macro through the command line with CMake?

I try to set a preprocessor macro in the command line of CMake. I've tried: set generator="Visual Studio 8 2005" set params=-D MY_MACRO=1 cmake.exe -G %generator% %params% ..\some_project ...
Yakov Galka's user avatar
  • 71.6k
67 votes
4 answers
122k views

Cmake cannot find library using "link_directories"

I Ubuntu, I am learning about cmake and make, and just trying a simple example. I have two directories: src and build. In src, I have two files: main.cpp, and CMakeLists.txt, which has (only) the ...
Karnivaurus's user avatar
  • 23.5k
66 votes
3 answers
143k views

Optimize in CMake by default

I have a C++ project which uses CMake as its build system. I'd like the following behavior: If cmake is invoked as cmake .., then CMAKE_CXX_FLAGS is -O3 -Wall -Wextra If cmake is invoked as cmake .. ...
marmistrz's user avatar
  • 6,204
66 votes
6 answers
109k views

The proper way of forcing a 32-bit compile using CMake

Sorry that there are many similar questions, but I do find that Googling for CMake queries always yields similar-but-not-the-same scenarios, conflicting CMake commands and so on! I need to force my ...
devrobf's user avatar
  • 7,133

1
2 3 4 5
246