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

When you run make, add VERBOSE=1 to see the full command output. For example: cmake . make VERBOSE=1 Or you can add -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON to the cmake command for permanent verbose command output from the generated Makefiles. cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON . make To reduce some possibly less-interesting output you might like to use the following options. The … Read more

What is the proper way to use `pkg-config` from `cmake`?

First of, the call: include(FindPkgConfig) should be replaced with: find_package(PkgConfig) The find_package() call is more flexible and allows options such as REQUIRED, that do things automatically that one would have to do manually with include(). Secondly, manually calling pkg-config should be avoid when possible. CMake comes with a rich set of package definitions, found in … Read more

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

Those error messages CMake Error at … (project): No CMAKE_C_COMPILER could be found. — Configuring incomplete, errors occurred! See also “…/CMakeFiles/CMakeOutput.log”. See also “…/CMakeFiles/CMakeError.log”. or CMake Error: your CXX compiler: “CMAKE_CXX_COMPILER-NOTFOUND” was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name. … — Configuring incomplete, errors occurred! just mean that CMake was … Read more

How do I activate C++ 11 in CMake?

CMake 3.1 introduced the CMAKE_CXX_STANDARD variable that you can use. If you know that you will always have CMake 3.1 or later available, you can just write this in your top-level CMakeLists.txt file, or put it right before any new target is defined: set (CMAKE_CXX_STANDARD 11) If you need to support older versions of CMake, … Read more

How to properly add include directories with CMake

Two things must be done. First add the directory to be included: target_include_directories(test PRIVATE ${YOUR_DIRECTORY}) In case you are stuck with a very old CMake version (2.8.10 or older) without support for target_include_directories, you can also use the legacy include_directories instead: include_directories(${YOUR_DIRECTORY}) Then you also must add the header files to the list of your … Read more

cmake and libpthread

@Manuel was part way there. You can add the compiler option as well, like this: If you have CMake 3.1.0+, this becomes even easier: set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) target_link_libraries(my_app PRIVATE Threads::Threads) If you are using CMake 2.8.12+, you can simplify this to: find_package(Threads REQUIRED) if(THREADS_HAVE_PTHREAD_ARG) target_compile_options(my_app PUBLIC “-pthread”) endif() if(CMAKE_THREAD_LIBS_INIT) target_link_libraries(my_app “${CMAKE_THREAD_LIBS_INIT}”) endif() Older CMake … Read more

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

When writing CMake scripts there is a lot you need to know about the syntax and how to use variables in CMake. The Syntax Strings using set(): set(MyString “Some Text”) set(MyStringWithVar “Some other Text: ${MyString}”) set(MyStringWithQuot “Some quote: \”${MyStringWithVar}\””) Or with string(): string(APPEND MyStringWithContent ” ${MyString}”) Lists using set(): set(MyList “a” “b” “c”) set(MyList ${MyList} … Read more

Hinting Find.cmake Files with a custom directory

Setting CMAKE_PREFIX_PATH variable serves exactly these purposes: hinting find_* function about location of searched item. While description of this variable doesn’t note about find_package function, the variable affects it indirectly: the most of Find<name>.cmake scripts use find_library and find_path functions. Note, that all find_* functions have precise algorithm for search items, and paths constructed with … Read more