How to make cmake output to the "build" directory? - c++

I'm using cmake to compile a C++ project, and I want cmake to generate all the output files(metafiles like Makefile used to create binaries) in the build folder. I've checked all the answers in How do I make cmake output into a 'bin' dir?, none of them worked for me(suprisingly!). Files are generated in the root folder instead of in the build folder, what's wrong here? I guess I must have missed something.
Code Structure
➜ cmake-test tree .
.
├── CMakeLists.txt
└── hello.cpp
0 directories, 2 files
CMakeLists.txt
# Specify the minimum version for CMake
cmake_minimum_required(VERSION 3.11)
# Project's name
project(hello)
# Set the output folder where your program will be created
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# The following folder will be included
include_directories("${PROJECT_SOURCE_DIR}")
add_executable(hello ${PROJECT_SOURCE_DIR}/hello.cpp)
Build Commands and Outputs
➜ cmake-test cmake .
-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 8.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/searene/CLionProjects/cmake-test
➜ cmake-test ls
bin CMakeCache.txt CMakeFiles cmake_install.cmake CMakeLists.txt hello.cpp Makefile
cmake version
➜ cmake-test cmake --version
cmake version 3.11.4
CMake suite maintained and supported by Kitware (kitware.com/cmake).
OS
Linux

The usual way to do this, rather than changing variables to set the path, is simply to create the output directory, change to it, and run cmake from there. So instead of cmake . you usually have cmake .. or similar.
I understand the initial impulse to say "But I expect my build system to write output somewhere else." But CMake is not usually used in the way you were initially expecting, and other people who run your CMake build won't expect what you were expecting, so it's probably best to just use the built-in, default behavior, which is to put the output wherever cmake was run.
Put another way: You are fighting against the tool. Don't do that.

Disclaimer: I recommend going with #john-zwinck's answer.
By default, cmake uses the current working directory as build directory and whatever path you provide as source directory. So the normal way of achieving your goal is
create the build directory (mkdir build)
go there (cd build)
call cmake with the source dir as argument (cmake path/to/source)
BUT there is another way, as far as I know not documented in the cmake docs and only kept for compatibility reasons or internal usage, that some people are using. The -B and -H flags
cmake -Hpath/to/source -Bpath/to/build
or even from the source dir
cmake . -Bbuild
Important: no space after -B.

CMake 3.19.1 (not sure how about older ones) has following option (from docs):
cmake [<options>] -S <path-to-source> -B <path-to-build>
Uses as the build tree and as the
source tree. The specified paths may be absolute or relative to the
current working directory. The source tree must contain a
CMakeLists.txt file. The build tree will be created automatically if
it does not already exist. For example:
cmake -S src -B build

Related

Debian, cmake, connot compile c++ program, missing config cmake file

Trying to compile dot11decrypt on debian, installed apt-get install libtins4.0 and apt-get install libtins-dev, but cmake .. can't find package libtins, heres the error:
CMake Error at CMakeLists.txt:4 (FIND_PACKAGE):
By not providing "Findlibtins.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "libtins", but
CMake did not find one.
Could not find a package configuration file provided by "libtins" with any
of the following names:
libtinsConfig.cmake
libtins-config.cmake
Add the installation prefix of "libtins" to CMAKE_PREFIX_PATH or set
"libtins_DIR" to a directory containing one of the above files. If
"libtins" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
See also "/home/user/dot11decrypt/build/CMakeFiles/CMakeOutput.log".
cat:dot11decrypt/CMakeLists.txt
1. CMAKE_MINIMUM_REQUIRED(VERSION 2.8.1)
2. PROJECT(dot11decrypt)
3.
4. FIND_PACKAGE(libtins REQUIRED)
5.
6. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
7.
8. ADD_EXECUTABLE(dot11decrypt dot11decrypt.cpp)
9. TARGET_LINK_LIBRARIES(dot11decrypt ${LIBTINS_LIBRARIES} pthread)
find / -name Findlibtins.cmake or libtinsConfig.cmake brings no result.
I found those files on internet but still no success, i think i have to install something but don't know what.
I went with Tsyvarev solution.
# installing missing dependencies for libtins
apt-get install libpcap-dev libssl-dev cmake
# installing libtins
git clone https://github.com/mfontanini/libtins.git
cd libtins
mkdir build
cd build
cmake ../
make
checkinstall
Now cmake will reach dot11decrypt missing files.
# installing dot11decrypt
git clone https://github.com/mfontanini/dot11decrypt.git
cd dot11decrypt/
mkdir build
cd build/
cmake ../
make
Now you should have dot11decrypt executable.
If i would have to do it again i would try Alex Reinking solution first.
You don't need to compile from source... find_package is a very flexible configuration point! You'll just need to provide your own find module that is sufficient for the build. Fortunately, this is very simple. Here's what I did:
$ https://github.com/mfontanini/dot11decrypt
$ cd dot11decrypt
$ mkdir _patches
$ vim _patches/Findlibtins.cmake
$ cat _patches/Findlibtins.cmake
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBTINS REQUIRED libtins)
$ cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_MODULE_PATH=$PWD/_patches
CMake Deprecation Warning at CMakeLists.txt:1 (CMAKE_MINIMUM_REQUIRED):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'libtins'
-- Found libtins, version 4.0
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alex/test/dot11decrypt/build
$ cmake --build build/
[ 50%] Building CXX object CMakeFiles/dot11decrypt.dir/dot11decrypt.cpp.o
/home/alex/test/dot11decrypt/dot11decrypt.cpp: In function ‘void decrypt_traffic(unique_fd, const string&, decrypter_tuple)’:
/home/alex/test/dot11decrypt/dot11decrypt.cpp:333:39: warning: ‘Tins::Sniffer::Sniffer(const string&, unsigned int, bool, const string&, bool)’ is deprecated [-Wdeprecated-declarations]
333 | Sniffer sniffer(iface, 2500, false);
| ^
In file included from /usr/include/tins/dns.h:38,
from /usr/include/tins/tins.h:33,
from /home/alex/test/dot11decrypt/dot11decrypt.cpp:25:
/usr/include/tins/sniffer.h:369:5: note: declared here
369 | TINS_DEPRECATED(Sniffer(const std::string& device, unsigned max_packet_size,
| ^~~~~~~~~~~~~~~
[100%] Linking CXX executable dot11decrypt
[100%] Built target dot11decrypt
The key here is to create a minimal Find module. This is just two lines on my system since it isn't meant to be reusable...
# _patches/Findlibtins.cmake
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBTINS REQUIRED libtins)
This just delegates the responsibility of setting the LIBTINS_LIBRARIES to pkg-config. To connect this find module to the build, I just set -DCMAKE_MODULE_PATH=$PWD/_patches at the CMake configure command line.
Also, you should definitely open a bug report with the dot11decrypt author about their broken and outdated build. Notice the strongly worded deprecation warning in the logs I posted.

How to compile RealSense examples?

I have cloned the RealSense official source code from their Github page. There was a problem when I was compiling the example align-advanced. The following is my terminal situation:
$ cd ~/librealsense/examples/align-advanced
$ mkdir build
$ cd build
~/librealsense/examples/align-advanced/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/automation/librealsense/examples/align-advanced/build
~/librealsense/examples/align-advanced/build$ make
~/librealsense/examples/align-advanced/build$
As you can see, nothing happens after typing make, and no executable files appear in the build folder.
The contents of offical CMakeList.txt are as follows:
# License: Apache 2.0. See LICENSE file in root directory.
# Copyright(c) 2019 Intel Corporation. All Rights Reserved.
# minimum required cmake version: 3.1.0
cmake_minimum_required(VERSION 3.1.0)
project(RealsenseExamplesAlignAdvanced)
if(BUILD_GRAPHICAL_EXAMPLES)
add_executable(rs-align-advanced rs-align-advanced.cpp ../../third-party/imgui/imgui.cpp ../../third-party/imgui/imgui_draw.cpp ../../third-party/imgui/imgui_impl_glfw.cpp)
set_property(TARGET rs-align-advanced PROPERTY CXX_STANDARD 11)
target_link_libraries(rs-align-advanced ${DEPENDENCIES})
include_directories(rs-align-advanced ../../common ../../third-party/imgui)
set_target_properties (rs-align-advanced PROPERTIES FOLDER Examples)
install(TARGETS rs-align-advanced RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
What is the problem?
CMake was intended to be run from the top-level directory of the entire project. This is a general CMake rule-of-thumb; it typically applies to any CMake-based project, not only RealSense.
If you want to enable the compilation of the RealSense examples, you can control it via CMake with the BUILD_EXAMPLES variable, as seen the Build Configuration documentation. This only builds a small subset of the examples, however. To build the align-advanced examples, you also need to set BUILD_GRAPHICAL_EXAMPLES:
cd ~/librealsense
mkdir build; cd build
cmake -DBUILD_EXAMPLES=true -DBUILD_GRAPHICAL_EXAMPLES=true ..
make

How do I get CMake to find my test in my C library project?

I have a project here:
https://github.com/edhartnett/ncglm
It is a small C library for reading netCDF data files from the Geostationary Lightning Mapper. I have an autotools build which works fine, and I'm trying to add a CMake build.
The directory structure is simple, there is a main directory, a src directory, and a test directory.
In the main directory I have:
# This is the main cmake file for ncglm, a library to help read the
# netCDF data files from the Global Lightning Mapper (GLM) instrument
# on GOES-16 and GOES-17.
#
# Ed Hartnett 11/10/19
# This will use any cmake between 3.1 and 3.15, preferint later
# versions with updated policies.
cmake_minimum_required(VERSION 3.1...3.15)
if (${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()
# set the project name
project(ncglm VERSION 1.0)
#Add custom CMake Module
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/"
CACHE INTERNAL "Location of our custom CMake modules.")
# Find netCDF.
include(FindNetCDF)
include_directories("${NETCDF_INCLUDES}")
# Create a config.h.
configure_file(config.h.cmake.in config.h)
# Turn on testing.
enable_testing()
include(CTest)
# Build in this subdirectory.
add_subdirectory(src test)
In the src subdirectory I have:
# This is the cmake file for the src directory of the ncglm library.
# Ed Hartnett 11/10/19
# Build the ncglm library.
add_library(ncglm glm_read.c goes_glm.h glm_data.h)
In the test directory I have:
# This is the cmake build file for the test directory of the ncglm library.
#
# Ed Hartnett 11/10/19
enable_testing()
add_test(NAME tst_glm_read COMMAND tst_glm_read)
build_test(tst_glm_read)
add_sh_test(nc_test4 run_glm_tests)
When I build, I get:
ed#mikado:~/ncglm/build$ cmake -DNETCDF_INCLUDES=/usr/local/netcdf-c-4.7.2_hdf5-1.10.5/include -DNETCDF_LIBRARIES=/usr/local/netcdf-c-4.7.2_hdf5-1.10.5/lib .. && make test
-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found NetCDF: /usr/local/netcdf-c-4.7.2_hdf5-1.10.5/lib
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ed/ncglm/build
Running tests...
Test project /home/ed/ncglm/build
No tests were found!!!
How come cmake is not trying to build or run my test?
add_subdirectory(src test)
This is invalid / it doesn't do what you think it does. What you want to do is:
add_subdirectory(src)
add_subdirectory(test)
The cmake website is down right now, I can't link to it. From memory the add_subdirectory(src test) reads CMakeLists.txt in the src source directory, but builds the sources in the test build directory, the test is created inside the build directory inside CMAKE_CURRENT_BUILD_DIR. To add two source directories, you have to use two add_subdirectory().

How to 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 files of my software project?
CMake 3.3 introduced the new target property CXX_INCLUDE_WHAT_YOU_USE that can be set to the path of the program include-what-you-use. For instance this CMakeLists.txt
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
add_executable(hello main.cc)
find_program(iwyu_path NAMES include-what-you-use iwyu REQUIRED)
# If using CGAL<3.18, you remove REQUIRED and use
# if(NOT iwyu_path)
# message(FATAL_ERROR "Could not find the program include-what-you-use")
# endif()
set_property(TARGET hello PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
is able to build the file main.cc
#include <iostream>
#include <vector>
int main() {
std::cout << "Hello World!" << std::endl;
return 0;
}
and at the same time have include-what-you-use give out a warning that
the included header vector is not needed.
user#ubuntu:/tmp$ ls ~/hello
CMakeLists.txt main.cc
user#ubuntu:/tmp$ mkdir /tmp/build
user#ubuntu:/tmp$ cd /tmp/build
user#ubuntu:/tmp/build$ ~/cmake-3.3.0-rc2-Linux-x86_64/bin/cmake ~/hello
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/build
user#ubuntu:/tmp/build$ make
Scanning dependencies of target hello
[ 50%] Building CXX object CMakeFiles/hello.dir/main.cc.o
Warning: include-what-you-use reported diagnostics:
/home/user/hello/main.cc should add these lines:
/home/user/hello/main.cc should remove these lines:
- #include <vector> // lines 2-2
The full include-list for /home/user/hello/main.cc:
#include <iostream> // for operator<<, basic_ostream, cout, endl, ostream
---
[100%] Linking CXX executable hello
[100%] Built target hello
user#ubuntu:/tmp/build$ ./hello
Hello World!
user#ubuntu:/tmp/build$
If you want to pass custom options to include-what-you-use, like for instance --mapping_file you can do it via
set(iwyu_path_and_options
${iwyu_path}
-Xiwyu
--mapping_file=${my_mapping})
set_property(TARGET hello
PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path_and_options})
If you don't have access to CMake 3.3, include-what-you-use comes with a python tool called iwyu_tool.py which can do what you want.
It works by parsing a JSON compilation database, which is easily produced with CMake (see below).
Running the tool manually
Assuming you already have a CMake build dir for your project, you first need to tell CMake to produce the compilation database:
$ cd build
$ cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
This generates a file, compile_commands.json containing compiler invocations for every object file in your project. You don't need to rebuild the project.
You can now run include-what-you-use on your project by running the python tool on your build directory:
$ python /path/to/iwyu_tool.py -p .
Adding a custom target to your cmake project
The following snippet can be used to add an iwyu target to a cmake project.
# Generate clang compilation database
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(PythonInterp)
find_program(iwyu_tool_path NAMES iwyu_tool.py)
if (iwyu_tool_path AND PYTHONINTERP_FOUND)
add_custom_target(iwyu
ALL # Remove ALL if you don't iwyu to be run by default.
COMMAND "${PYTHON_EXECUTABLE}" "${iwyu_tool_path}" -p "${CMAKE_BINARY_DIR}"
COMMENT "Running include-what-you-use tool"
VERBATIM
)
endif()
Notes
The include-what-you-use binary needs to be in your path for any of the above to work properly.
By default, iwyu_tool.py is single-threaded, which can be slow for large projects. You can use the --jobs argument to increase the number of source files that will be processed in parallel.
You can also enable it globally outside the cmake script by setting the cmake variable:
cmake -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="iwyu" <builddir>
It will then call it on each CXX target.
I extended the source code from Alastair Harrison, in order to create a reusable solution. I've came up with the following that should work with all CMake versions:
File iwyu.cmake:
#.rst:
# include-what-you-use (iwyu)
# ----------------------------
#
# Allows to run the static code analyzer `include-what-you-use (iwyu)
# <http://include-what-you-use.org>`_ as a custom target with the build system
# `CMake <http://cmake.org>`_.
#
# .. topic:: Dependencies
#
# This module requires the following *CMake* modules:
#
# * ``FindPythonInterp``
#
# .. topic:: Contributors
#
# * Florian Wolters <wolters.fl#gmail.com>
#===============================================================================
# Copyright 2015 Florian Wolters
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#===============================================================================
# ------------------------------------------------------------------------------
# Include guard for this file.
# ------------------------------------------------------------------------------
if(iwyu_included)
return()
endif()
set(iwyu_included TRUE)
option(BUILD_IWYU
"Run the include-what-you-use static analyzer on the source code of the project."
OFF)
function(iwyu_enable)
set(iwyu_EXECUTABLE_NAME include-what-you-use)
find_program(iwyu_EXECUTABLE ${iwyu_EXECUTABLE_NAME})
if(iwyu_EXECUTABLE)
# This is not exactly the same behavior as with CMake v3.3, since here all
# compiled targets are analyzed.
set(iwyu_tool_EXECUTABLE_NAME iwyu_tool.py)
find_package(PythonInterp)
find_program(iwyu_tool_EXECUTABLE ${iwyu_tool_EXECUTABLE_NAME})
if(PYTHONINTERP_FOUND AND iwyu_tool_EXECUTABLE)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON PARENT_SCOPE)
add_custom_target(iwyu
ALL
COMMAND "${PYTHON_EXECUTABLE}" "${iwyu_tool_EXECUTABLE}" -p "${CMAKE_BINARY_DIR}"
COMMENT "Running the ${iwyu_tool_EXECUTABLE_NAME} compilation database driver"
VERBATIM)
else()
message(STATUS
"Unable to find the Python interpreter and/or the ${iwyu_tool_EXECUTABLE_NAME} script")
endif()
else()
message(STATUS "Unable to find the ${iwyu_EXECUTABLE_NAME} executable")
endif()
endfunction()
File CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
include(iwyu.cmake)
project(hello_world)
add_executable(${PROJECT_NAME} main.cc)
if(BUILD_IWYU)
iwyu_enable()
endif()
Invoke CMake as follows to run include-what-you-use when the all target is invoked:
cmake -DBUILD_IWYU=ON <path-to-source>
cmake --build . --target all
The output should be as follows:
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wolters/workspace/include-what-you-use_example/build
[ 66%] Built target hello_world
[100%] Running the iwyu_tool.py compilation database driver
/home/wolters/workspace/include-what-you-use_example/develop/main.cc should add these lines:
/home/wolters/workspace/include-what-you-use_example/develop/main.cc should remove these lines:
- #include <vector> // lines 1-1
The full include-list for /home/wolters/workspace/include-what-you-use_example/develop/main.cc:
#include <iostream> // for operator<<, basic_ostream, cout, endl, ostream
---
[100%] Built target iwyu
Edit 2015-08-19: The approach with the CMake property <LANG>_INCLUDE_WHAT_YOU_USE did not work for me with CMake version 3.3.1. Therefore I updated the solution.
Edit 2015-09-30: The output was wrong, since my include-what-you-use installation was broken. The include-what-you-use and iwyu_tool.py files have to be in the same directory as clang, clang++, etc.

Using CMake + Ninja to download dependencies using GIT

I have an ExternalProject dependency that gets cloned (using git) in the build process. This all works great with CMake + Make.
mkdir build && cd build;
cmake ..
make
It correctly clones and builds the library using git when I type make.
However, when I use the Ninja Generator:
mkdir build && cd build;
cmake -GNinja ..
ninja
I get the following error:
$ cmake -GNinja .. -- The C compiler identification is AppleClang 6.0.0.6000054
-- The CXX compiler identification is AppleClang 6.0.0.6000054
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Ninja
-- Check for working CXX compiler using: Ninja -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Boost version: 1.56.0
-- Found the following Boost libraries:
-- unit_test_framework
-- Found Git: /usr/local/bin/git (found version "2.1.2")
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/carneiro/src/gamgee/build
$ ninja
ninja: error: 'contrib/htslib-prefix/src/htslib/libhts.a', needed by 'test/gamgee_test', missing and no known rule to make it
Is git downloading of external projects not supported by the cmake+ninja combo?
Turns out if you do a clean before building, it all works and ninja does download my dependencies correctly.
So the workflow looks like this:
mkdir build && cd build
cmake -G Ninja ..
ninja clean # if you don't do this, it will not download Externalproject dependencies
ninja
Must be some kind of bug in the Ninja generator, but I'm happy with this workflow for now.