The `ALL` target does not behave like a user-defined target
I have a use case where I need to customize what's being executed by the default target, i.e. ALL
. Furthermore, I can't use the usual approach to do this, which is something like add_custom_target(target ALL ...)
, since the target I want to add to ALL
already exists and I can't modify it (in my actual use case, that target is install
). Unfortunately, ALL
is not recognized as a target, and hence it can't be interacted with. For example, given this:
add_custom_target(cant_modify)
cmake_minimum_required(VERSION 3.8.0)
project(foo)
add_dependencies(ALL cant_modify)
I get the following error:
% (mkdir build && cd build && cmake ..)
-- The C compiler identification is ...
-- The CXX compiler identification is ...
-- Check for working C compiler: ...
-- Check for working C compiler: ...
-- 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: ...
-- Check for working CXX compiler: ...
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:5 (add_dependencies):
Cannot add target-level dependencies to non-existent target "ALL".
The add_dependencies works for top-level logical targets created by the
add_executable, add_library, or add_custom_target commands. If you want to
add file-level dependencies see the DEPENDS option of the add_custom_target
and add_custom_command commands.
-- Configuring incomplete, errors occurred!
This is a feature request for having a way of interacting with the default target (i.e. the target run when no target is specified) as if it were a normal target. The current state of things appears to be both inconsistent (why would ALL
behave differently from any other target?) and inflexible. In general, it would also be great if other builtin targets (such as test
) behaved more like user-defined targets, but this is probably out of scope for this issue.