Circular dependency between the `ALL` and the `install` targets
I have a use case where running the empty target needs to build and install a project, i.e. running make
should build and install the project. To do that, I have the following solution (something more straightforward would be in order, but this is the subject of another issue):
cmake_minimum_required(VERSION 3.8.0)
project(foo)
install(FILES "foo.h" DESTINATION include)
add_custom_target(default ALL DEPENDS install)
Unfortunately, this does not work since there seems to be a circular dependency between the ALL
target and the install
target, both of which are builtins created by CMake. It's unclear to me why the install
target should depend on the ALL
target.
Exact steps to reproduce
I have the following setup:
% tree
.
├── CMakeLists.txt
└── foo.h
The CMakeLists.txt
file contains this:
cmake_minimum_required(VERSION 3.8.0)
project(foo)
install(FILES "foo.h" DESTINATION include)
add_custom_target(default ALL DEPENDS install)
Then, when I do the following:
mkdir build && cd build && cmake .. -GNinja && ninja
I get the following error:
ninja: error: dependency cycle: all -> default -> CMakeFiles/default -> install -> CMakeFiles/install.util -> all
Note that I also get an error with the Makefile generator, but the error is less readable. So this is not a problem specific to the Ninja generator.