ALIAS: Add support for add_dependencies for ALIAS targets

The add_dependencies command currently accepts ALIAS targets for
<target-dependencies> which resolve to the referenced target. This further
relaxes the command to accept an ALIAS <target> where the command will
add the dependencies to the target which the alias references.
This commit is contained in:
Arha Gatram
2026-06-22 09:35:58 -07:00
committed by Brad King
parent 79e421b053
commit 5f8cc64695
6 changed files with 13 additions and 13 deletions

View File

@@ -35,6 +35,10 @@ transitively in its place since the target itself does not build.
The command may be called with no dependencies.
Previously, at least one dependency was required.
.. versionchanged:: 4.5
If ``<target>`` is an :ref:`Alias Target <Alias Targets>`, dependencies are
added to the target which the alias references.
See Also
^^^^^^^^

View File

@@ -10,6 +10,9 @@ alias-transparency
:command:`target_link_directories`, :command:`target_link_libraries`,
:command:`target_link_options`, :command:`target_precompile_headers`,
and :command:`target_sources` commands now accept :ref:`Alias Targets`.
The commands operate on the target which the alias references.
The command operates on the target which the alias references.
* The :command:`add_dependencies` command now accepts :ref:`Alias Targets`.
Dependencies are added to the target which the alias references.
* The :prop_tgt:`ALIASED_TARGET` target property is now read-only.

View File

@@ -19,12 +19,6 @@ bool cmAddDependenciesCommand(std::vector<std::string> const& args,
cmMakefile& mf = status.GetMakefile();
std::string const& target_name = args[0];
if (mf.IsAlias(target_name)) {
mf.IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("Cannot add target-level dependencies to alias target \"",
target_name, "\".\n"));
}
if (cmTarget* target = mf.FindTargetToUse(target_name)) {
// skip over target_name

View File

@@ -1,5 +0,0 @@
CMake Error at add_dependencies\.cmake:9 \(add_dependencies\):
Cannot add target-level dependencies to alias target "alias"\.
Call Stack \(most recent call first\):
CMakeLists\.txt:3 \(include\)

View File

@@ -7,3 +7,8 @@ add_library(bar empty.cpp)
add_library(alias ALIAS foo)
add_dependencies(alias bar)
get_property(DEPS TARGET foo PROPERTY MANUALLY_ADDED_DEPENDENCIES)
if(NOT DEPS STREQUAL "bar")
message(SEND_ERROR "add_dependencies(): Expected 'bar' as dependency of 'foo' but got: '${DEPS}' instead of 'bar'.")
endif()