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

What is the CMake equivalent to "gcc -fvisibility=hidden" when controlling the exported symbol of a shared library?

I developed cross platform software in c++. As I know, Linux .so exported all the symbols by default, well through "gcc -fvisibility=hidden" I can set all the exported symbols as hidden, then set __attribute__(visibility("default")) for the class…
sailing
  • 670
  • 1
  • 5
  • 11
67
votes
8 answers

How to detect target architecture using CMake?

I've done a lot of research and been unable to find an answer to this... how can I reliably find the target architecture I'm compiling for, using CMake? Basically, the equivalent to QMAKE_TARGET.arch in qmake. Most sources seem to suggest…
Jake Petroules
  • 23,472
  • 35
  • 144
  • 225
67
votes
6 answers

CMake: how create a single shared library from all static libraries of subprojects?

I have the following layout: top_project + subproject1 + subproject2 Each of subproject1 and subproject2 creates a static library. I would like to link these static libraries in a single shared library at the top_project level. The…
Deimos
  • 1,835
  • 1
  • 16
  • 15
66
votes
6 answers

CMake - linking to library downloaded from ExternalProject_add()

I am trying to use ExternalProject_add() to download/install dependencies. It installs fine, but I can't figure out how to actually link the libraries after they are downloaded. I want to call target_link_libraries() on the library that was just…
Brett Thomas
  • 1,694
  • 3
  • 15
  • 21
66
votes
3 answers

Path to target output file

I have a .so library target created by add_library, and need to pass an absolute path to this library to an external script. Now I have ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}LangShared${CMAKE_SHARED_LIBRARY_SUFFIX} for that…
Dmitry Risenberg
  • 2,321
  • 2
  • 18
  • 22
66
votes
4 answers

How to set linker flags for OpenMP in CMake's try_compile function

I would like to verify that the current compiler can build with openmp support. The application has do deploy across a wide variety of unix systems, some of which might have old versions of OpenMP, and I would like to test for important OpenMP…
dusktreader
  • 3,845
  • 7
  • 30
  • 40
65
votes
4 answers

How to 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 but it's neither defined when I compile nor can I find the…
Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
65
votes
4 answers

How do I force cmake to include "-pthread" option during compilation?

I know there is something like find_package(Threads) but it doesn't seem to make a difference (at least by itself). For now I'm using SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-pthread"), but it doesn't look like a correct solution to me.
Tomasz Grobelny
  • 2,666
  • 3
  • 33
  • 43
65
votes
4 answers

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 following text: add_executable(test…
Karnivaurus
  • 22,823
  • 57
  • 147
  • 247
64
votes
6 answers

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 project to build 32-bit binaries because I have to…
devrobf
  • 6,973
  • 2
  • 32
  • 46
64
votes
3 answers

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 2016). Perhaps there are similar issues with…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
64
votes
4 answers

Listing header files in Visual Studio C++ project generated by cmake

I'm building a cmake based build system for our product. The problem is that Visual Studio project, generated by cmake, doesn't display header files in solution browser. What I need to add in CMakeList.txt to list header files? The preferred…
dimba
  • 26,717
  • 34
  • 141
  • 196
63
votes
2 answers

Is it possible to build Boost with CMake?

Rather than include static libraries in my source tree in a cross-compiled project I'd like to add boost directly into cmake and build it. Is this available?
dzada
  • 5,344
  • 5
  • 29
  • 37
62
votes
4 answers

Detailed guide on using gcov with CMake/CDash?

I'm using CMake with my project and set up a cdash server for continuous/nightly building. Everything works well and by setting up a crontab, we have hourly/nightly build/test results uploaded to our cdash server automatically. My next step is to…
Ralph Zhang
  • 5,015
  • 5
  • 30
  • 40
62
votes
4 answers

In CMake, how can I find the directory of an included file?

Suppose my project's CMakeLists.txt includes foo.cmake: include(foo) In foo.cmake, i want to know the path of foo.cmake. How can I do that? Note that CMAKE_CURRENT_LIST_DIR gives the directory of the including CMakeLists.txt, not that of the…
user1387866
  • 2,834
  • 3
  • 22
  • 28