From 5f8cc646950017dc16812d79d3bb78848fb24d24 Mon Sep 17 00:00:00 2001 From: Arha Gatram Date: Mon, 22 Jun 2026 09:35:58 -0700 Subject: [PATCH] ALIAS: Add support for add_dependencies for ALIAS targets The add_dependencies command currently accepts ALIAS targets for which resolve to the referenced target. This further relaxes the command to accept an ALIAS where the command will add the dependencies to the target which the alias references. --- Help/command/add_dependencies.rst | 4 ++++ Help/release/dev/alias-transparency.rst | 5 ++++- Source/cmAddDependenciesCommand.cxx | 6 ------ Tests/RunCMake/alias_targets/add_dependencies-result.txt | 1 - Tests/RunCMake/alias_targets/add_dependencies-stderr.txt | 5 ----- Tests/RunCMake/alias_targets/add_dependencies.cmake | 5 +++++ 6 files changed, 13 insertions(+), 13 deletions(-) delete mode 100644 Tests/RunCMake/alias_targets/add_dependencies-result.txt delete mode 100644 Tests/RunCMake/alias_targets/add_dependencies-stderr.txt diff --git a/Help/command/add_dependencies.rst b/Help/command/add_dependencies.rst index b0dd494b23..6d7f3c5bbd 100644 --- a/Help/command/add_dependencies.rst +++ b/Help/command/add_dependencies.rst @@ -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 ```` is an :ref:`Alias Target `, dependencies are + added to the target which the alias references. + See Also ^^^^^^^^ diff --git a/Help/release/dev/alias-transparency.rst b/Help/release/dev/alias-transparency.rst index 94e3a9d502..0588e30ae0 100644 --- a/Help/release/dev/alias-transparency.rst +++ b/Help/release/dev/alias-transparency.rst @@ -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. diff --git a/Source/cmAddDependenciesCommand.cxx b/Source/cmAddDependenciesCommand.cxx index ff85ed30b7..265140ab76 100644 --- a/Source/cmAddDependenciesCommand.cxx +++ b/Source/cmAddDependenciesCommand.cxx @@ -19,12 +19,6 @@ bool cmAddDependenciesCommand(std::vector 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 diff --git a/Tests/RunCMake/alias_targets/add_dependencies-result.txt b/Tests/RunCMake/alias_targets/add_dependencies-result.txt deleted file mode 100644 index d00491fd7e..0000000000 --- a/Tests/RunCMake/alias_targets/add_dependencies-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/alias_targets/add_dependencies-stderr.txt b/Tests/RunCMake/alias_targets/add_dependencies-stderr.txt deleted file mode 100644 index 0938edf49c..0000000000 --- a/Tests/RunCMake/alias_targets/add_dependencies-stderr.txt +++ /dev/null @@ -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\) diff --git a/Tests/RunCMake/alias_targets/add_dependencies.cmake b/Tests/RunCMake/alias_targets/add_dependencies.cmake index 7436371a22..88f592122f 100644 --- a/Tests/RunCMake/alias_targets/add_dependencies.cmake +++ b/Tests/RunCMake/alias_targets/add_dependencies.cmake @@ -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()