From a121419908728facbaf8f31288ba76fd91ebe688 Mon Sep 17 00:00:00 2001 From: Arha Gatram Date: Wed, 24 Jun 2026 10:35:20 -0700 Subject: [PATCH 1/5] ALIAS: Add support for set_property and set_target_properties commands Currently, getting properties from an ALIAS target retrieves the property from the target which the alias references while setting properties results in an error. This relaxes set_property and set_target_properties to accept ALIAS targets and act on the referenced target, mirroring the get behavior. An error is raised when setting ALIAS_GLOBAL or ALIASED_TARGET on an ALIAS target. Closes: #19445 --- Help/command/add_executable.rst | 11 ++++++++--- Help/command/add_library.rst | 13 +++++++++---- Help/command/set_property.rst | 4 +++- Help/command/set_target_properties.rst | 4 +++- Help/manual/cmake-buildsystem.7.rst | 13 ++++++++++--- Help/release/dev/alias-transparency.rst | 6 ++++++ Source/cmSetPropertyCommand.cxx | 11 +++++++---- Source/cmSetTargetPropertiesCommand.cxx | 12 ++++++++---- Tests/RunCMake/alias_targets/RunCMakeTest.cmake | 2 ++ ...ult.txt => set_property-ALIAS_GLOBAL-result.txt} | 0 .../set_property-ALIAS_GLOBAL-stderr.txt | 2 ++ .../alias_targets/set_property-ALIAS_GLOBAL.cmake | 6 ++++++ .../RunCMake/alias_targets/set_property-stderr.txt | 4 ---- Tests/RunCMake/alias_targets/set_property.cmake | 5 +++++ ...> set_target_properties-ALIAS_GLOBAL-result.txt} | 0 .../set_target_properties-ALIAS_GLOBAL-stderr.txt | 3 +++ .../set_target_properties-ALIAS_GLOBAL.cmake | 6 ++++++ .../alias_targets/set_target_properties-stderr.txt | 4 ---- .../alias_targets/set_target_properties.cmake | 5 +++++ 19 files changed, 83 insertions(+), 28 deletions(-) create mode 100644 Help/release/dev/alias-transparency.rst rename Tests/RunCMake/alias_targets/{set_property-result.txt => set_property-ALIAS_GLOBAL-result.txt} (100%) create mode 100644 Tests/RunCMake/alias_targets/set_property-ALIAS_GLOBAL-stderr.txt create mode 100644 Tests/RunCMake/alias_targets/set_property-ALIAS_GLOBAL.cmake delete mode 100644 Tests/RunCMake/alias_targets/set_property-stderr.txt rename Tests/RunCMake/alias_targets/{set_target_properties-result.txt => set_target_properties-ALIAS_GLOBAL-result.txt} (100%) create mode 100644 Tests/RunCMake/alias_targets/set_target_properties-ALIAS_GLOBAL-stderr.txt create mode 100644 Tests/RunCMake/alias_targets/set_target_properties-ALIAS_GLOBAL.cmake delete mode 100644 Tests/RunCMake/alias_targets/set_target_properties-stderr.txt diff --git a/Help/command/add_executable.rst b/Help/command/add_executable.rst index bab371485b..ae6356334d 100644 --- a/Help/command/add_executable.rst +++ b/Help/command/add_executable.rst @@ -112,11 +112,16 @@ Alias Executables ``ALIAS`` targets can be used as targets to read properties from, executables for custom commands and custom targets. They can also be tested for existence with the regular :command:`if(TARGET)` subcommand. -The ```` may not be used to modify properties of ````, that -is, it may not be used as the operand of :command:`set_property`, -:command:`set_target_properties`, :command:`target_link_libraries` etc. An ``ALIAS`` target may not be installed or exported. +.. versionchanged:: 4.5 + The ```` may be used as the operand of :command:`set_property` and + :command:`set_target_properties` to modify properties of ````. It + may not be used with the commands :command:`target_link_libraries`, + :command:`target_compile_definitions` etc. CMake 4.4 and earlier did not + allow the ```` to modify properties of ```` with + :command:`set_property` and :command:`set_target_properties`. + See Also ^^^^^^^^ diff --git a/Help/command/add_library.rst b/Help/command/add_library.rst index 66ce32717f..9272f522e8 100644 --- a/Help/command/add_library.rst +++ b/Help/command/add_library.rst @@ -317,12 +317,17 @@ Alias Libraries ``ALIAS`` targets can be used as linkable targets and as targets to read properties from. They can also be tested for existence with the -regular :command:`if(TARGET)` subcommand. The ```` may not be used -to modify properties of ````, that is, it may not be used as the -operand of :command:`set_property`, :command:`set_target_properties`, -:command:`target_link_libraries` etc. An ``ALIAS`` target may not be +regular :command:`if(TARGET)` subcommand. An ``ALIAS`` target may not be installed or exported. +.. versionchanged:: 4.5 + The ```` may be used as the operand of :command:`set_property` and + :command:`set_target_properties` to modify properties of ````. It + may not be used with the commands :command:`target_link_libraries`, + :command:`target_compile_definitions` etc. CMake 4.4 and earlier did not + allow the ```` to modify properties of ```` with + :command:`set_property` and :command:`set_target_properties`. + See Also ^^^^^^^^ diff --git a/Help/command/set_property.rst b/Help/command/set_property.rst index e560f1843a..5fe7825460 100644 --- a/Help/command/set_property.rst +++ b/Help/command/set_property.rst @@ -40,7 +40,9 @@ It must be one of the following: Scope may name zero or more existing targets. See also the :command:`set_target_properties` command. - :ref:`Alias Targets` do not support setting target properties. + .. versionchanged:: 4.5 + If ```` is an :ref:`Alias Target `, properties are + set on the target which the alias references. ``FILE_SET`` .. versionadded:: 4.3 diff --git a/Help/command/set_target_properties.rst b/Help/command/set_target_properties.rst index 5357575ba2..d172eaabe4 100644 --- a/Help/command/set_target_properties.rst +++ b/Help/command/set_target_properties.rst @@ -15,7 +15,9 @@ set next. You can use any prop value pair you want and extract it later with the :command:`get_property` or :command:`get_target_property` command. -:ref:`Alias Targets` do not support setting target properties. +.. versionchanged:: 4.5 + If ```` contains :ref:`Alias Targets`, properties are set on the + corresponding target referenced by each alias. See Also ^^^^^^^^ diff --git a/Help/manual/cmake-buildsystem.7.rst b/Help/manual/cmake-buildsystem.7.rst index e9b90fb17c..b6849becb2 100644 --- a/Help/manual/cmake-buildsystem.7.rst +++ b/Help/manual/cmake-buildsystem.7.rst @@ -1429,9 +1429,16 @@ target, which may be an :prop_tgt:`IMPORTED` target from a package, or an target_link_libraries(exe1 Upstream::lib1) ``ALIAS`` targets are not mutable, installable or exportable. They are -entirely local to the buildsystem description. A name can be tested for -whether it is an ``ALIAS`` name by reading the :prop_tgt:`ALIASED_TARGET` -property from it: +entirely local to the buildsystem description. + +.. versionchanged:: 4.5 + ``ALIAS`` targets may be used as the operand for :command:`set_property` and + similar commands used to modify properties of targets. The commands operate + on the target which the alias references. CMake 4.4 and earlier did not + allow modifying targets via an ``ALIAS``. + +A name can be tested for whether it is an ``ALIAS`` name by reading the +:prop_tgt:`ALIASED_TARGET` property from it: .. code-block:: cmake diff --git a/Help/release/dev/alias-transparency.rst b/Help/release/dev/alias-transparency.rst new file mode 100644 index 0000000000..402e42fd71 --- /dev/null +++ b/Help/release/dev/alias-transparency.rst @@ -0,0 +1,6 @@ +alias-transparency +------------------ + +* The :command:`set_property` and :command:`set_target_properties` commands + now accept :ref:`Alias Targets`. Properties are set on the target which + the alias references. diff --git a/Source/cmSetPropertyCommand.cxx b/Source/cmSetPropertyCommand.cxx index 292a308b27..749b591d06 100644 --- a/Source/cmSetPropertyCommand.cxx +++ b/Source/cmSetPropertyCommand.cxx @@ -709,11 +709,14 @@ bool HandleTargetMode(cmExecutionStatus& status, bool appendMode, bool remove) { for (std::string const& name : names) { - if (status.GetMakefile().IsAlias(name)) { - status.SetError("can not be used on an ALIAS target."); - return false; + // Better error message for alias properties set on an alias target. + if (propertyName == "ALIASED_TARGET" || propertyName == "ALIAS_GLOBAL") { + if (status.GetMakefile().IsAlias(name)) { + status.SetError(cmStrCat("can not set property ", propertyName, + " on an ALIAS target: ", name)); + return false; + } } - if (cmTarget* target = status.GetMakefile().FindTargetToUse(name)) { if (target->IsSymbolic()) { status.SetError("can not be used on a SYMBOLIC target."); diff --git a/Source/cmSetTargetPropertiesCommand.cxx b/Source/cmSetTargetPropertiesCommand.cxx index 0009bd2d50..e3a7f93067 100644 --- a/Source/cmSetTargetPropertiesCommand.cxx +++ b/Source/cmSetTargetPropertiesCommand.cxx @@ -35,10 +35,6 @@ bool cmSetTargetPropertiesCommand(std::vector const& args, // loop over all the targets for (std::string const& tname : cmStringRange{ args.begin(), propsIter }) { - if (mf.IsAlias(tname)) { - status.SetError("can not be used on an ALIAS target."); - return false; - } if (cmTarget* target = mf.FindTargetToUse(tname)) { if (target->IsSymbolic()) { status.SetError("can not be used on a SYMBOLIC target."); @@ -46,6 +42,14 @@ bool cmSetTargetPropertiesCommand(std::vector const& args, } // loop through all the props and set them for (auto k = propsIter + 1; k != args.end(); k += 2) { + // Better error message for alias properties set on an alias target. + if (*k == "ALIASED_TARGET" || *k == "ALIAS_GLOBAL") { + if (mf.IsAlias(tname)) { + status.SetError(cmStrCat("can not set property ", *k, + " on an ALIAS target: ", tname)); + return false; + } + } target->SetProperty(*k, *(k + 1)); target->CheckProperty(*k, &mf); } diff --git a/Tests/RunCMake/alias_targets/RunCMakeTest.cmake b/Tests/RunCMake/alias_targets/RunCMakeTest.cmake index 4be1b9d8d4..c5bdd3ee72 100644 --- a/Tests/RunCMake/alias_targets/RunCMakeTest.cmake +++ b/Tests/RunCMake/alias_targets/RunCMakeTest.cmake @@ -12,8 +12,10 @@ run_cmake(imported-global-target) run_cmake(imported-target) run_cmake(alias-target) run_cmake(set_property) +run_cmake(set_property-ALIAS_GLOBAL) run_cmake(get_property) run_cmake(set_target_properties) +run_cmake(set_target_properties-ALIAS_GLOBAL) run_cmake(target_link_libraries) run_cmake(target_include_directories) run_cmake(export) diff --git a/Tests/RunCMake/alias_targets/set_property-result.txt b/Tests/RunCMake/alias_targets/set_property-ALIAS_GLOBAL-result.txt similarity index 100% rename from Tests/RunCMake/alias_targets/set_property-result.txt rename to Tests/RunCMake/alias_targets/set_property-ALIAS_GLOBAL-result.txt diff --git a/Tests/RunCMake/alias_targets/set_property-ALIAS_GLOBAL-stderr.txt b/Tests/RunCMake/alias_targets/set_property-ALIAS_GLOBAL-stderr.txt new file mode 100644 index 0000000000..02dc9d7c8a --- /dev/null +++ b/Tests/RunCMake/alias_targets/set_property-ALIAS_GLOBAL-stderr.txt @@ -0,0 +1,2 @@ +CMake Error at set_property-ALIAS_GLOBAL\.cmake:[0-9]+ \(set_property\): + set_property can not set property ALIAS_GLOBAL on an ALIAS target: alias diff --git a/Tests/RunCMake/alias_targets/set_property-ALIAS_GLOBAL.cmake b/Tests/RunCMake/alias_targets/set_property-ALIAS_GLOBAL.cmake new file mode 100644 index 0000000000..f4c3207822 --- /dev/null +++ b/Tests/RunCMake/alias_targets/set_property-ALIAS_GLOBAL.cmake @@ -0,0 +1,6 @@ +enable_language(CXX) + +add_library(foo empty.cpp) +add_library(alias ALIAS foo) + +set_property(TARGET alias PROPERTY ALIAS_GLOBAL something) diff --git a/Tests/RunCMake/alias_targets/set_property-stderr.txt b/Tests/RunCMake/alias_targets/set_property-stderr.txt deleted file mode 100644 index 67efae024b..0000000000 --- a/Tests/RunCMake/alias_targets/set_property-stderr.txt +++ /dev/null @@ -1,4 +0,0 @@ -CMake Error at set_property\.cmake:8 \(set_property\): - set_property can not be used on an ALIAS target\. -Call Stack \(most recent call first\): - CMakeLists\.txt:3 \(include\) diff --git a/Tests/RunCMake/alias_targets/set_property.cmake b/Tests/RunCMake/alias_targets/set_property.cmake index 1f5e475c4a..310bf87227 100644 --- a/Tests/RunCMake/alias_targets/set_property.cmake +++ b/Tests/RunCMake/alias_targets/set_property.cmake @@ -6,3 +6,8 @@ add_library(foo empty.cpp) add_library(alias ALIAS foo) set_property(TARGET alias PROPERTY ANYTHING 1) + +get_target_property(val foo ANYTHING) +if(NOT val STREQUAL "1") + message(SEND_ERROR "set_property(): Target property 'ANYTHING' set on ALIAS 'alias' has wrong value on aliased target 'foo': '${val}' instead of '1'.") +endif() diff --git a/Tests/RunCMake/alias_targets/set_target_properties-result.txt b/Tests/RunCMake/alias_targets/set_target_properties-ALIAS_GLOBAL-result.txt similarity index 100% rename from Tests/RunCMake/alias_targets/set_target_properties-result.txt rename to Tests/RunCMake/alias_targets/set_target_properties-ALIAS_GLOBAL-result.txt diff --git a/Tests/RunCMake/alias_targets/set_target_properties-ALIAS_GLOBAL-stderr.txt b/Tests/RunCMake/alias_targets/set_target_properties-ALIAS_GLOBAL-stderr.txt new file mode 100644 index 0000000000..449c969750 --- /dev/null +++ b/Tests/RunCMake/alias_targets/set_target_properties-ALIAS_GLOBAL-stderr.txt @@ -0,0 +1,3 @@ +CMake Error at set_target_properties-ALIAS_GLOBAL\.cmake:[0-9]+ \(set_target_properties\): + set_target_properties can not set property ALIAS_GLOBAL on an ALIAS target: + alias diff --git a/Tests/RunCMake/alias_targets/set_target_properties-ALIAS_GLOBAL.cmake b/Tests/RunCMake/alias_targets/set_target_properties-ALIAS_GLOBAL.cmake new file mode 100644 index 0000000000..2d25a5790d --- /dev/null +++ b/Tests/RunCMake/alias_targets/set_target_properties-ALIAS_GLOBAL.cmake @@ -0,0 +1,6 @@ +enable_language(CXX) + +add_library(foo empty.cpp) +add_library(alias ALIAS foo) + +set_target_properties(alias PROPERTIES ALIAS_GLOBAL something) diff --git a/Tests/RunCMake/alias_targets/set_target_properties-stderr.txt b/Tests/RunCMake/alias_targets/set_target_properties-stderr.txt deleted file mode 100644 index 5ca552b1cf..0000000000 --- a/Tests/RunCMake/alias_targets/set_target_properties-stderr.txt +++ /dev/null @@ -1,4 +0,0 @@ -CMake Error at set_target_properties\.cmake:8 \(set_target_properties\): - set_target_properties can not be used on an ALIAS target\. -Call Stack \(most recent call first\): - CMakeLists\.txt:3 \(include\) diff --git a/Tests/RunCMake/alias_targets/set_target_properties.cmake b/Tests/RunCMake/alias_targets/set_target_properties.cmake index ee44d4595a..9957a2c779 100644 --- a/Tests/RunCMake/alias_targets/set_target_properties.cmake +++ b/Tests/RunCMake/alias_targets/set_target_properties.cmake @@ -6,3 +6,8 @@ add_library(foo empty.cpp) add_library(alias ALIAS foo) set_target_properties(alias PROPERTIES ANYTHING 1) + +get_target_property(val foo ANYTHING) +if(NOT val STREQUAL "1") + message(SEND_ERROR "set_target_properties(): Target property 'ANYTHING' set on ALIAS 'alias' has wrong value on aliased target 'foo': '${val}' instead of '1'.") +endif() From 3b327695aaae5fa2a5ea6cca72038fb23cd906ed Mon Sep 17 00:00:00 2001 From: Arha Gatram Date: Wed, 24 Jun 2026 10:51:41 -0700 Subject: [PATCH 2/5] ALIASED_TARGET: Make property read-only The ALIAS_GLOBAL property is read-only, so ALIASED_TARGET should be as well. Even when set, there is no way to read the property value, so this change gives an explicit error for users. --- Help/prop_tgt/ALIASED_TARGET.rst | 5 ++++- Help/release/dev/alias-transparency.rst | 2 ++ Source/cmTarget.cxx | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Help/prop_tgt/ALIASED_TARGET.rst b/Help/prop_tgt/ALIASED_TARGET.rst index f9e60348db..85e8de2435 100644 --- a/Help/prop_tgt/ALIASED_TARGET.rst +++ b/Help/prop_tgt/ALIASED_TARGET.rst @@ -1,7 +1,10 @@ ALIASED_TARGET -------------- -Name of target aliased by this target. +Read-only property containing the name of target aliased by this target. + +.. versionchanged:: 4.5 + CMake 4.4 and earlier did not enforce the read-only nature of this property. If this is an :ref:`Alias Target `, this property contains the name of the target aliased. diff --git a/Help/release/dev/alias-transparency.rst b/Help/release/dev/alias-transparency.rst index 402e42fd71..c843d7a0eb 100644 --- a/Help/release/dev/alias-transparency.rst +++ b/Help/release/dev/alias-transparency.rst @@ -4,3 +4,5 @@ alias-transparency * The :command:`set_property` and :command:`set_target_properties` commands now accept :ref:`Alias Targets`. Properties are set on the target which the alias references. + +* The :prop_tgt:`ALIASED_TARGET` target property is now read-only. diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 7f8a29d2ff..4349defefc 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -2116,6 +2116,7 @@ bool IsSettableProperty(cmMakefile* context, cmTarget* target, { "SYMBOLIC", { ROC::All } }, { "TYPE", { ROC::All } }, { "ALIAS_GLOBAL", { ROC::All, cmPolicies::CMP0160 } }, + { "ALIASED_TARGET", { ROC::All } }, { "BINARY_DIR", { ROC::All, cmPolicies::CMP0160 } }, { "CXX_MODULE_SETS", { ROC::All, cmPolicies::CMP0160 } }, { "IMPORTED", { ROC::All, cmPolicies::CMP0160 } }, From 79e421b0536e217047200baea01ca5c1786cbba7 Mon Sep 17 00:00:00 2001 From: Arha Gatram Date: Mon, 15 Jun 2026 15:32:01 -0700 Subject: [PATCH 3/5] ALIAS: Add support for target_* commands Now that set_property and set_target_properties support ALIAS targets, we need to extend support to all the target_* type commands that modify target properties. Relaxes target_compile_definitions, target_compile_features, target_compile_options, target_include_directories, target_link_directories, target_link_libraries, target_link_options, target_precompile_headers, and target_sources to now accept ALIAS targets. These commands set properties on the target which the alias references. --- Help/command/add_executable.rst | 10 ++++------ Help/command/add_library.rst | 10 ++++------ Help/command/target_compile_definitions.rst | 7 +++++-- Help/command/target_compile_features.rst | 7 +++++-- Help/command/target_compile_options.rst | 6 +++++- Help/command/target_include_directories.rst | 7 +++++-- Help/command/target_link_directories.rst | 7 +++++-- Help/command/target_link_libraries.rst | 13 ++++++++----- Help/command/target_link_options.rst | 7 +++++-- Help/command/target_precompile_headers.rst | 7 +++++-- Help/command/target_sources.rst | 7 +++++-- Help/release/dev/alias-transparency.rst | 7 +++++++ Source/cmTargetLinkLibrariesCommand.cxx | 6 ------ Source/cmTargetPropCommandBase.cxx | 4 ---- Tests/RunCMake/alias_targets/RunCMakeTest.cmake | 7 +++++++ .../alias_targets/target_compile_definitions.cmake | 12 ++++++++++++ .../alias_targets/target_compile_features.cmake | 14 ++++++++++++++ .../alias_targets/target_compile_options.cmake | 12 ++++++++++++ .../target_include_directories-result.txt | 1 - .../target_include_directories-stderr.txt | 4 ---- .../alias_targets/target_include_directories.cmake | 4 ++++ .../alias_targets/target_link_directories.cmake | 12 ++++++++++++ .../alias_targets/target_link_libraries-result.txt | 1 - .../alias_targets/target_link_libraries-stderr.txt | 4 ---- .../alias_targets/target_link_libraries.cmake | 6 +++++- .../alias_targets/target_link_options.cmake | 12 ++++++++++++ .../alias_targets/target_precompile_headers.cmake | 12 ++++++++++++ Tests/RunCMake/alias_targets/target_sources.cmake | 12 ++++++++++++ .../alias_target-result.txt | 1 - .../alias_target-stderr.txt | 4 ---- .../target_compile_features/alias_target.cmake | 9 ++++++++- 31 files changed, 173 insertions(+), 59 deletions(-) create mode 100644 Tests/RunCMake/alias_targets/target_compile_definitions.cmake create mode 100644 Tests/RunCMake/alias_targets/target_compile_features.cmake create mode 100644 Tests/RunCMake/alias_targets/target_compile_options.cmake delete mode 100644 Tests/RunCMake/alias_targets/target_include_directories-result.txt delete mode 100644 Tests/RunCMake/alias_targets/target_include_directories-stderr.txt create mode 100644 Tests/RunCMake/alias_targets/target_link_directories.cmake delete mode 100644 Tests/RunCMake/alias_targets/target_link_libraries-result.txt delete mode 100644 Tests/RunCMake/alias_targets/target_link_libraries-stderr.txt create mode 100644 Tests/RunCMake/alias_targets/target_link_options.cmake create mode 100644 Tests/RunCMake/alias_targets/target_precompile_headers.cmake create mode 100644 Tests/RunCMake/alias_targets/target_sources.cmake delete mode 100644 Tests/RunCMake/target_compile_features/alias_target-result.txt delete mode 100644 Tests/RunCMake/target_compile_features/alias_target-stderr.txt diff --git a/Help/command/add_executable.rst b/Help/command/add_executable.rst index ae6356334d..b2eb25ae26 100644 --- a/Help/command/add_executable.rst +++ b/Help/command/add_executable.rst @@ -115,12 +115,10 @@ tested for existence with the regular :command:`if(TARGET)` subcommand. An ``ALIAS`` target may not be installed or exported. .. versionchanged:: 4.5 - The ```` may be used as the operand of :command:`set_property` and - :command:`set_target_properties` to modify properties of ````. It - may not be used with the commands :command:`target_link_libraries`, - :command:`target_compile_definitions` etc. CMake 4.4 and earlier did not - allow the ```` to modify properties of ```` with - :command:`set_property` and :command:`set_target_properties`. + The ```` may be used as the operand of :command:`set_property`, + :command:`set_target_properties`, :command:`target_link_libraries`, etc. to + modify properties of ````. CMake 4.4 and earlier did not allow the + ```` to modify properties of ````. See Also ^^^^^^^^ diff --git a/Help/command/add_library.rst b/Help/command/add_library.rst index 9272f522e8..e9f2dc9836 100644 --- a/Help/command/add_library.rst +++ b/Help/command/add_library.rst @@ -321,12 +321,10 @@ regular :command:`if(TARGET)` subcommand. An ``ALIAS`` target may not be installed or exported. .. versionchanged:: 4.5 - The ```` may be used as the operand of :command:`set_property` and - :command:`set_target_properties` to modify properties of ````. It - may not be used with the commands :command:`target_link_libraries`, - :command:`target_compile_definitions` etc. CMake 4.4 and earlier did not - allow the ```` to modify properties of ```` with - :command:`set_property` and :command:`set_target_properties`. + The ```` may be used as the operand of :command:`set_property`, + :command:`set_target_properties`, :command:`target_link_libraries`, etc. to + modify properties of ````. CMake 4.4 and earlier did not allow the + ```` to modify properties of ````. See Also ^^^^^^^^ diff --git a/Help/command/target_compile_definitions.rst b/Help/command/target_compile_definitions.rst index cb2629ee65..2690ed941f 100644 --- a/Help/command/target_compile_definitions.rst +++ b/Help/command/target_compile_definitions.rst @@ -11,8 +11,11 @@ Add compile definitions to a target. Specifies compile definitions to use when compiling a given ````. The named ```` must have been created by a command such as -:command:`add_executable` or :command:`add_library` and must not be an -:ref:`ALIAS target `. +:command:`add_executable` or :command:`add_library`. + +.. versionchanged:: 4.5 + If ```` is an :ref:`Alias Target `, the command + operates on the target which the alias references. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to specify the :ref:`scope ` of the following arguments. diff --git a/Help/command/target_compile_features.rst b/Help/command/target_compile_features.rst index f63a56c06f..3f1a1906e5 100644 --- a/Help/command/target_compile_features.rst +++ b/Help/command/target_compile_features.rst @@ -29,8 +29,11 @@ Repeated calls for the same ```` append items. Allow setting ``INTERFACE`` items on :ref:`IMPORTED targets `. The named ```` must have been created by a command such as -:command:`add_executable` or :command:`add_library` and must not be an -:ref:`ALIAS target `. +:command:`add_executable` or :command:`add_library`. + +.. versionchanged:: 4.5 + If ```` is an :ref:`Alias Target `, the command + operates on the target which the alias references. .. |command_name| replace:: ``target_compile_features`` .. |more_see_also| replace:: See the :manual:`cmake-compile-features(7)` diff --git a/Help/command/target_compile_options.rst b/Help/command/target_compile_options.rst index a16e55b460..afd46c44ee 100644 --- a/Help/command/target_compile_options.rst +++ b/Help/command/target_compile_options.rst @@ -13,7 +13,11 @@ Adds options to the :prop_tgt:`COMPILE_OPTIONS` or :prop_tgt:`INTERFACE_COMPILE_OPTIONS` target properties. These options are used when compiling the given ````, which must have been created by a command such as :command:`add_executable` or -:command:`add_library` and must not be an :ref:`ALIAS target `. +:command:`add_library`. + +.. versionchanged:: 4.5 + If ```` is an :ref:`Alias Target `, the command + operates on the target which the alias references. .. note:: diff --git a/Help/command/target_include_directories.rst b/Help/command/target_include_directories.rst index 59d0cd5350..653abb872c 100644 --- a/Help/command/target_include_directories.rst +++ b/Help/command/target_include_directories.rst @@ -11,8 +11,11 @@ Add include directories to a target. Specifies include directories to use when compiling a given target. The named ```` must have been created by a command such -as :command:`add_executable` or :command:`add_library` and must not be an -:ref:`ALIAS target `. +as :command:`add_executable` or :command:`add_library`. + +.. versionchanged:: 4.5 + If ```` is an :ref:`Alias Target `, the command + operates on the target which the alias references. By using ``AFTER`` or ``BEFORE`` explicitly, you can select between appending and prepending, independent of the default. diff --git a/Help/command/target_link_directories.rst b/Help/command/target_link_directories.rst index 91c1feb6cf..8258679666 100644 --- a/Help/command/target_link_directories.rst +++ b/Help/command/target_link_directories.rst @@ -17,8 +17,11 @@ with the latter being interpreted as relative to the current source directory. These items will be added to the link command. The named ```` must have been created by a command such as -:command:`add_executable` or :command:`add_library` and must not be an -:ref:`ALIAS target `. +:command:`add_executable` or :command:`add_library`. + +.. versionchanged:: 4.5 + If ```` is an :ref:`Alias Target `, the command + operates on the target which the alias references. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to specify the :ref:`scope ` of the items that follow diff --git a/Help/command/target_link_libraries.rst b/Help/command/target_link_libraries.rst index 4d964f4b00..b2b000d69b 100644 --- a/Help/command/target_link_libraries.rst +++ b/Help/command/target_link_libraries.rst @@ -21,16 +21,19 @@ All of them have the general form target_link_libraries( ... ... ...) The named ```` must have been created by a command such as -:command:`add_executable` or :command:`add_library` and must not be an -:ref:`ALIAS target `. If policy :policy:`CMP0079` is not -set to ``NEW`` then the target must have been created in the current -directory. Repeated calls for the same ```` append items in -the order called. +:command:`add_executable` or :command:`add_library`. If policy +:policy:`CMP0079` is not set to ``NEW``, then the target must have been +created in the current directory. Repeated calls for the same ```` +append items in the order called. .. versionadded:: 3.13 The ```` doesn't have to be defined in the same directory as the ``target_link_libraries`` call. +.. versionchanged:: 4.5 + If ```` is an :ref:`Alias Target `, the command + operates on the target which the alias references. + Each ```` may be: * **A library target name**: The generated link line will have the diff --git a/Help/command/target_link_options.rst b/Help/command/target_link_options.rst index 9e55e9d3c7..91132b3e43 100644 --- a/Help/command/target_link_options.rst +++ b/Help/command/target_link_options.rst @@ -13,8 +13,11 @@ library target. [{INTERFACE|PUBLIC|PRIVATE} ...]...) The named ```` must have been created by a command such as -:command:`add_executable` or :command:`add_library` and must not be an -:ref:`ALIAS target `. +:command:`add_executable` or :command:`add_library`. + +.. versionchanged:: 4.5 + If ```` is an :ref:`Alias Target `, the command + operates on the target which the alias references. This command can be used to add any link options, but alternative commands exist to add libraries (:command:`target_link_libraries` or diff --git a/Help/command/target_precompile_headers.rst b/Help/command/target_precompile_headers.rst index 7089582f4a..2ade01d889 100644 --- a/Help/command/target_precompile_headers.rst +++ b/Help/command/target_precompile_headers.rst @@ -21,8 +21,11 @@ Main Form The command adds header files to the :prop_tgt:`PRECOMPILE_HEADERS` and/or :prop_tgt:`INTERFACE_PRECOMPILE_HEADERS` target properties of ````. The named ```` must have been created by a command such as -:command:`add_executable` or :command:`add_library` and must not be an -:ref:`ALIAS target `. +:command:`add_executable` or :command:`add_library`. + +.. versionchanged:: 4.5 + If ```` is an :ref:`Alias Target `, the command + operates on the target which the alias references. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to specify the :ref:`scope ` of the following arguments. diff --git a/Help/command/target_sources.rst b/Help/command/target_sources.rst index b3c55390dd..6a789d5052 100644 --- a/Help/command/target_sources.rst +++ b/Help/command/target_sources.rst @@ -14,13 +14,16 @@ Add sources to a target. Specifies sources to use when building a target and/or its dependents. The named ```` must have been created by a command such as :command:`add_executable` or :command:`add_library` or -:command:`add_custom_target` and must not be an -:ref:`ALIAS target `. The ```` may use +:command:`add_custom_target`. The ```` may use :manual:`generator expressions `. .. versionadded:: 3.20 ```` can be a custom target. +.. versionchanged:: 4.5 + If ```` is an :ref:`Alias Target `, the command + operates on the target which the alias references. + The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to specify the :ref:`scope ` of the source file paths (````) that follow them. ``PRIVATE`` and ``PUBLIC`` items will diff --git a/Help/release/dev/alias-transparency.rst b/Help/release/dev/alias-transparency.rst index c843d7a0eb..94e3a9d502 100644 --- a/Help/release/dev/alias-transparency.rst +++ b/Help/release/dev/alias-transparency.rst @@ -5,4 +5,11 @@ alias-transparency now accept :ref:`Alias Targets`. Properties are set on the target which the alias references. +* The :command:`target_compile_definitions`, :command:`target_compile_features`, + :command:`target_compile_options`, :command:`target_include_directories`, + :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 :prop_tgt:`ALIASED_TARGET` target property is now read-only. diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index f6cc7bd481..34d03a0514 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -78,12 +78,6 @@ bool cmTargetLinkLibrariesCommand(std::vector const& args, cmMakefile& mf = status.GetMakefile(); - // Alias targets cannot be on the LHS of this command. - if (mf.IsAlias(args[0])) { - status.SetError("can not be used on an ALIAS target."); - return false; - } - // Lookup the target for which libraries are specified. cmTarget* target = mf.GetGlobalGenerator()->FindTarget(args[0]); if (!target) { diff --git a/Source/cmTargetPropCommandBase.cxx b/Source/cmTargetPropCommandBase.cxx index 960e36cf40..08d482dca3 100644 --- a/Source/cmTargetPropCommandBase.cxx +++ b/Source/cmTargetPropCommandBase.cxx @@ -29,10 +29,6 @@ bool cmTargetPropCommandBase::HandleArguments( return false; } - if (this->Makefile->IsAlias(args[0])) { - this->SetError("can not be used on an ALIAS target."); - return false; - } // Lookup the target for which property-values are specified. this->Target = this->Makefile->GetGlobalGenerator()->FindTarget(args[0]); if (!this->Target) { diff --git a/Tests/RunCMake/alias_targets/RunCMakeTest.cmake b/Tests/RunCMake/alias_targets/RunCMakeTest.cmake index c5bdd3ee72..4ce22bdd44 100644 --- a/Tests/RunCMake/alias_targets/RunCMakeTest.cmake +++ b/Tests/RunCMake/alias_targets/RunCMakeTest.cmake @@ -17,7 +17,14 @@ run_cmake(get_property) run_cmake(set_target_properties) run_cmake(set_target_properties-ALIAS_GLOBAL) run_cmake(target_link_libraries) +run_cmake(target_compile_definitions) +run_cmake(target_compile_features) +run_cmake(target_compile_options) run_cmake(target_include_directories) +run_cmake(target_link_directories) +run_cmake(target_link_options) +run_cmake(target_precompile_headers) +run_cmake(target_sources) run_cmake(export) run_cmake(install-export) run_cmake(name-conflict) diff --git a/Tests/RunCMake/alias_targets/target_compile_definitions.cmake b/Tests/RunCMake/alias_targets/target_compile_definitions.cmake new file mode 100644 index 0000000000..84e9cca3ee --- /dev/null +++ b/Tests/RunCMake/alias_targets/target_compile_definitions.cmake @@ -0,0 +1,12 @@ + +enable_language(CXX) + +add_library(foo empty.cpp) + +add_library(alias ALIAS foo) + +target_compile_definitions(alias PRIVATE MY_DEFINE) +get_target_property(val foo COMPILE_DEFINITIONS) +if(NOT "MY_DEFINE" STREQUAL "${val}") + message(SEND_ERROR "target_compile_definitions(): Target property 'COMPILE_DEFINITIONS' set on ALIAS 'alias' has wrong value on aliased target 'foo': '${val}' instead of 'MY_DEFINE'.") +endif() diff --git a/Tests/RunCMake/alias_targets/target_compile_features.cmake b/Tests/RunCMake/alias_targets/target_compile_features.cmake new file mode 100644 index 0000000000..34c792a113 --- /dev/null +++ b/Tests/RunCMake/alias_targets/target_compile_features.cmake @@ -0,0 +1,14 @@ + +enable_language(CXX) + +add_library(foo empty.cpp) + +add_library(alias ALIAS foo) + +if("cxx_std_11" IN_LIST CMAKE_CXX_COMPILE_FEATURES) + target_compile_features(alias PRIVATE cxx_std_11) + get_target_property(val foo COMPILE_FEATURES) + if(NOT "cxx_std_11" IN_LIST val) + message(SEND_ERROR "target_compile_features(): Target property 'COMPILE_FEATURES' set on ALIAS 'alias' has wrong value on aliased target 'foo': '${val}' instead of 'cxx_std_11'.") + endif() +endif() diff --git a/Tests/RunCMake/alias_targets/target_compile_options.cmake b/Tests/RunCMake/alias_targets/target_compile_options.cmake new file mode 100644 index 0000000000..efacc4f6d8 --- /dev/null +++ b/Tests/RunCMake/alias_targets/target_compile_options.cmake @@ -0,0 +1,12 @@ + +enable_language(CXX) + +add_library(foo empty.cpp) + +add_library(alias ALIAS foo) + +target_compile_options(alias PRIVATE -Wall) +get_target_property(val foo COMPILE_OPTIONS) +if(NOT "-Wall" STREQUAL "${val}") + message(SEND_ERROR "target_compile_options(): Target property 'COMPILE_OPTIONS' set on ALIAS 'alias' has wrong value on aliased target 'foo': '${val}' instead of '-Wall'.") +endif() diff --git a/Tests/RunCMake/alias_targets/target_include_directories-result.txt b/Tests/RunCMake/alias_targets/target_include_directories-result.txt deleted file mode 100644 index d00491fd7e..0000000000 --- a/Tests/RunCMake/alias_targets/target_include_directories-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/alias_targets/target_include_directories-stderr.txt b/Tests/RunCMake/alias_targets/target_include_directories-stderr.txt deleted file mode 100644 index bee54bb0f6..0000000000 --- a/Tests/RunCMake/alias_targets/target_include_directories-stderr.txt +++ /dev/null @@ -1,4 +0,0 @@ -CMake Error at target_include_directories\.cmake:8 \(target_include_directories\): - target_include_directories can not be used on an ALIAS target\. -Call Stack \(most recent call first\): - CMakeLists\.txt:3 \(include\) diff --git a/Tests/RunCMake/alias_targets/target_include_directories.cmake b/Tests/RunCMake/alias_targets/target_include_directories.cmake index c26830e119..fcf4025315 100644 --- a/Tests/RunCMake/alias_targets/target_include_directories.cmake +++ b/Tests/RunCMake/alias_targets/target_include_directories.cmake @@ -6,3 +6,7 @@ add_library(foo empty.cpp) add_library(alias ALIAS foo) target_include_directories(alias PRIVATE $) +get_target_property(val foo INCLUDE_DIRECTORIES) +if(NOT "$" STREQUAL "${val}") + message(SEND_ERROR "target_include_directories(): Target property 'INCLUDE_DIRECTORIES' set on ALIAS 'alias' has wrong value on aliased target 'foo': '${val}' instead of '$'.") +endif() diff --git a/Tests/RunCMake/alias_targets/target_link_directories.cmake b/Tests/RunCMake/alias_targets/target_link_directories.cmake new file mode 100644 index 0000000000..0e759ad47c --- /dev/null +++ b/Tests/RunCMake/alias_targets/target_link_directories.cmake @@ -0,0 +1,12 @@ + +enable_language(CXX) + +add_library(foo empty.cpp) + +add_library(alias ALIAS foo) + +target_link_directories(alias PRIVATE /usr/local/lib) +get_target_property(val foo LINK_DIRECTORIES) +if(NOT "/usr/local/lib" STREQUAL "${val}") + message(SEND_ERROR "target_link_directories(): Target property 'LINK_DIRECTORIES' set on ALIAS 'alias' has wrong value on aliased target 'foo': '${val}' instead of '/usr/local/lib'.") +endif() diff --git a/Tests/RunCMake/alias_targets/target_link_libraries-result.txt b/Tests/RunCMake/alias_targets/target_link_libraries-result.txt deleted file mode 100644 index d00491fd7e..0000000000 --- a/Tests/RunCMake/alias_targets/target_link_libraries-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/alias_targets/target_link_libraries-stderr.txt b/Tests/RunCMake/alias_targets/target_link_libraries-stderr.txt deleted file mode 100644 index 982c48334b..0000000000 --- a/Tests/RunCMake/alias_targets/target_link_libraries-stderr.txt +++ /dev/null @@ -1,4 +0,0 @@ -CMake Error at target_link_libraries\.cmake:9 \(target_link_libraries\): - target_link_libraries can not be used on an ALIAS target\. -Call Stack \(most recent call first\): - CMakeLists\.txt:3 \(include\) diff --git a/Tests/RunCMake/alias_targets/target_link_libraries.cmake b/Tests/RunCMake/alias_targets/target_link_libraries.cmake index b7b9e60185..8bc35cb02b 100644 --- a/Tests/RunCMake/alias_targets/target_link_libraries.cmake +++ b/Tests/RunCMake/alias_targets/target_link_libraries.cmake @@ -6,4 +6,8 @@ add_library(bar empty.cpp) add_library(alias ALIAS foo) -target_link_libraries(alias bar) +target_link_libraries(alias PRIVATE bar) +get_target_property(val foo LINK_LIBRARIES) +if(NOT "bar" IN_LIST val) + message(SEND_ERROR "target_link_libraries(): Target property 'LINK_LIBRARIES' is missing value added to ALIAS 'alias' on aliased target 'foo': 'bar' not in '${val}'.") +endif() diff --git a/Tests/RunCMake/alias_targets/target_link_options.cmake b/Tests/RunCMake/alias_targets/target_link_options.cmake new file mode 100644 index 0000000000..a27c86711b --- /dev/null +++ b/Tests/RunCMake/alias_targets/target_link_options.cmake @@ -0,0 +1,12 @@ + +enable_language(CXX) + +add_library(foo empty.cpp) + +add_library(alias ALIAS foo) + +target_link_options(alias PRIVATE LINKER:--test) +get_target_property(val foo LINK_OPTIONS) +if(NOT "LINKER:--test" STREQUAL "${val}") + message(SEND_ERROR "target_link_options(): Target property 'LINK_OPTIONS' set on ALIAS 'alias' has wrong value on aliased target 'foo': '${val}' instead of 'LINKER:--test'.") +endif() diff --git a/Tests/RunCMake/alias_targets/target_precompile_headers.cmake b/Tests/RunCMake/alias_targets/target_precompile_headers.cmake new file mode 100644 index 0000000000..74b9a94be2 --- /dev/null +++ b/Tests/RunCMake/alias_targets/target_precompile_headers.cmake @@ -0,0 +1,12 @@ + +enable_language(CXX) + +add_library(foo empty.cpp) + +add_library(alias ALIAS foo) + +target_precompile_headers(alias PRIVATE ) +get_target_property(val foo PRECOMPILE_HEADERS) +if(NOT "" IN_LIST val) + message(SEND_ERROR "target_precompile_headers(): Target property 'PRECOMPILE_HEADERS' is missing value added to ALIAS 'alias' on aliased target 'foo': '' not in '${val}'.") +endif() diff --git a/Tests/RunCMake/alias_targets/target_sources.cmake b/Tests/RunCMake/alias_targets/target_sources.cmake new file mode 100644 index 0000000000..4005007909 --- /dev/null +++ b/Tests/RunCMake/alias_targets/target_sources.cmake @@ -0,0 +1,12 @@ + +enable_language(CXX) + +add_library(foo) + +add_library(alias ALIAS foo) + +target_sources(alias PRIVATE empty.cpp) +get_target_property(val foo SOURCES) +if(NOT "empty.cpp" IN_LIST val) + message(SEND_ERROR "target_sources(): Target property 'SOURCES' is missing value added to ALIAS 'alias' on aliased target 'foo': 'empty.cpp' not in '${val}'.") +endif() diff --git a/Tests/RunCMake/target_compile_features/alias_target-result.txt b/Tests/RunCMake/target_compile_features/alias_target-result.txt deleted file mode 100644 index d00491fd7e..0000000000 --- a/Tests/RunCMake/target_compile_features/alias_target-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/target_compile_features/alias_target-stderr.txt b/Tests/RunCMake/target_compile_features/alias_target-stderr.txt deleted file mode 100644 index 6375d8d36d..0000000000 --- a/Tests/RunCMake/target_compile_features/alias_target-stderr.txt +++ /dev/null @@ -1,4 +0,0 @@ -CMake Error at alias_target\.cmake:[0-9]+ \(target_compile_features\): - target_compile_features can not be used on an ALIAS target\. -Call Stack \(most recent call first\): - CMakeLists\.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/target_compile_features/alias_target.cmake b/Tests/RunCMake/target_compile_features/alias_target.cmake index 6fcdadaa59..1aaecec4ac 100644 --- a/Tests/RunCMake/target_compile_features/alias_target.cmake +++ b/Tests/RunCMake/target_compile_features/alias_target.cmake @@ -2,4 +2,11 @@ enable_language(CXX) add_executable(main empty.cpp) add_executable(Alias::Main ALIAS main) -target_compile_features(Alias::Main PRIVATE cxx_delegating_constructors) + +if("cxx_delegating_constructors" IN_LIST CMAKE_CXX_COMPILE_FEATURES) + target_compile_features(Alias::Main PRIVATE cxx_delegating_constructors) + get_target_property(val main COMPILE_FEATURES) + if(NOT "cxx_delegating_constructors" IN_LIST val) + message(SEND_ERROR "target_compile_features(): Target property 'COMPILE_FEATURES' is missing value added to ALIAS 'Alias::Main' on aliased target 'main': 'cxx_delegating_constructors' not in '${val}'.") + endif() +endif() From 5f8cc646950017dc16812d79d3bb78848fb24d24 Mon Sep 17 00:00:00 2001 From: Arha Gatram Date: Mon, 22 Jun 2026 09:35:58 -0700 Subject: [PATCH 4/5] 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() From 17094eb57207b18597f6029560cdd41e6c773a61 Mon Sep 17 00:00:00 2001 From: Arha Gatram Date: Tue, 16 Jun 2026 10:55:50 -0700 Subject: [PATCH 5/5] ALIAS: Add test for generator expressions with ALIAS targets Generator expressions already correctly get properties of an ALIAS from the referenced target. Adds a test to verify a more complicated case that a generator expression set on an ALIAS target to a transitive property that gets a property from the ALIAS evaluates correctly. --- Tests/RunCMake/alias_targets/RunCMakeTest.cmake | 1 + .../alias_targets/generator-expression-check.cmake | 5 +++++ .../RunCMake/alias_targets/generator-expression.cmake | 10 ++++++++++ 3 files changed, 16 insertions(+) create mode 100644 Tests/RunCMake/alias_targets/generator-expression-check.cmake create mode 100644 Tests/RunCMake/alias_targets/generator-expression.cmake diff --git a/Tests/RunCMake/alias_targets/RunCMakeTest.cmake b/Tests/RunCMake/alias_targets/RunCMakeTest.cmake index 4ce22bdd44..4ceb9f5972 100644 --- a/Tests/RunCMake/alias_targets/RunCMakeTest.cmake +++ b/Tests/RunCMake/alias_targets/RunCMakeTest.cmake @@ -14,6 +14,7 @@ run_cmake(alias-target) run_cmake(set_property) run_cmake(set_property-ALIAS_GLOBAL) run_cmake(get_property) +run_cmake(generator-expression) run_cmake(set_target_properties) run_cmake(set_target_properties-ALIAS_GLOBAL) run_cmake(target_link_libraries) diff --git a/Tests/RunCMake/alias_targets/generator-expression-check.cmake b/Tests/RunCMake/alias_targets/generator-expression-check.cmake new file mode 100644 index 0000000000..396db7cc6b --- /dev/null +++ b/Tests/RunCMake/alias_targets/generator-expression-check.cmake @@ -0,0 +1,5 @@ +file(READ "${RunCMake_TEST_BINARY_DIR}/generator-expression-generated.txt" content) + +if(NOT content STREQUAL "value") + set(RunCMake_TEST_FAILED "set_property(): Target property 'COMPILE_DEFINITIONS' set on ALIAS 'alias::lib' has wrong value on aliased target 'lib': '${content}' instead of 'value'.") +endif() diff --git a/Tests/RunCMake/alias_targets/generator-expression.cmake b/Tests/RunCMake/alias_targets/generator-expression.cmake new file mode 100644 index 0000000000..6bb9ba55e3 --- /dev/null +++ b/Tests/RunCMake/alias_targets/generator-expression.cmake @@ -0,0 +1,10 @@ + +enable_language(CXX) + +add_library(lib empty.cpp) + +add_library(alias::lib ALIAS lib) +set_property(TARGET alias::lib PROPERTY COMPILE_DEFINITIONS $) +set_property(TARGET lib PROPERTY FOO value) + +file(GENERATE OUTPUT "generator-expression-generated.txt" CONTENT "$")