Merge topic 'alias-transparency'

17094eb572 ALIAS: Add test for generator expressions with ALIAS targets
5f8cc64695 ALIAS: Add support for add_dependencies for ALIAS targets
79e421b053 ALIAS: Add support for target_* commands
3b327695aa ALIASED_TARGET: Make property read-only
a121419908 ALIAS: Add support for set_property and set_target_properties commands

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12207
This commit is contained in:
Brad King
2026-07-09 14:05:51 +00:00
committed by Kitware Robot
55 changed files with 279 additions and 88 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

@@ -112,11 +112,14 @@ 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 ``<name>`` may not be used to modify properties of ``<target>``, 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 ``<name>`` may be used as the operand of :command:`set_property`,
:command:`set_target_properties`, :command:`target_link_libraries`, etc. to
modify properties of ``<target>``. CMake 4.4 and earlier did not allow the
``<name>`` to modify properties of ``<target>``.
See Also
^^^^^^^^

View File

@@ -317,12 +317,15 @@ 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 ``<name>`` may not be used
to modify properties of ``<target>``, 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 ``<name>`` may be used as the operand of :command:`set_property`,
:command:`set_target_properties`, :command:`target_link_libraries`, etc. to
modify properties of ``<target>``. CMake 4.4 and earlier did not allow the
``<name>`` to modify properties of ``<target>``.
See Also
^^^^^^^^

View File

@@ -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 ``<target>`` is an :ref:`Alias Target <Alias Targets>`, properties are
set on the target which the alias references.
``FILE_SET``
.. versionadded:: 4.3

View File

@@ -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 ``<targets>`` contains :ref:`Alias Targets`, properties are set on the
corresponding target referenced by each alias.
See Also
^^^^^^^^

View File

@@ -11,8 +11,11 @@ Add compile definitions to a target.
Specifies compile definitions to use when compiling a given ``<target>``. The
named ``<target>`` must have been created by a command such as
:command:`add_executable` or :command:`add_library` and must not be an
:ref:`ALIAS target <Alias Targets>`.
:command:`add_executable` or :command:`add_library`.
.. versionchanged:: 4.5
If ``<target>`` is an :ref:`Alias Target <Alias Targets>`, the command
operates on the target which the alias references.
The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
specify the :ref:`scope <Target Command Scope>` of the following arguments.

View File

@@ -29,8 +29,11 @@ Repeated calls for the same ``<target>`` append items.
Allow setting ``INTERFACE`` items on :ref:`IMPORTED targets <Imported Targets>`.
The named ``<target>`` must have been created by a command such as
:command:`add_executable` or :command:`add_library` and must not be an
:ref:`ALIAS target <Alias Targets>`.
:command:`add_executable` or :command:`add_library`.
.. versionchanged:: 4.5
If ``<target>`` is an :ref:`Alias Target <Alias Targets>`, 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)`

View File

@@ -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 ``<target>``, 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 <Alias Targets>`.
:command:`add_library`.
.. versionchanged:: 4.5
If ``<target>`` is an :ref:`Alias Target <Alias Targets>`, the command
operates on the target which the alias references.
.. note::

View File

@@ -11,8 +11,11 @@ Add include directories to a target.
Specifies include directories to use when compiling a given target.
The named ``<target>`` must have been created by a command such
as :command:`add_executable` or :command:`add_library` and must not be an
:ref:`ALIAS target <Alias Targets>`.
as :command:`add_executable` or :command:`add_library`.
.. versionchanged:: 4.5
If ``<target>`` is an :ref:`Alias Target <Alias Targets>`, 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.

View File

@@ -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 ``<target>`` must have been created by a command such as
:command:`add_executable` or :command:`add_library` and must not be an
:ref:`ALIAS target <Alias Targets>`.
:command:`add_executable` or :command:`add_library`.
.. versionchanged:: 4.5
If ``<target>`` is an :ref:`Alias Target <Alias Targets>`, the command
operates on the target which the alias references.
The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
specify the :ref:`scope <Target Command Scope>` of the items that follow

View File

@@ -21,16 +21,19 @@ All of them have the general form
target_link_libraries(<target> ... <item>... ...)
The named ``<target>`` must have been created by a command such as
:command:`add_executable` or :command:`add_library` and must not be an
:ref:`ALIAS target <Alias Targets>`. 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 ``<target>`` 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 ``<target>``
append items in the order called.
.. versionadded:: 3.13
The ``<target>`` doesn't have to be defined in the same directory as the
``target_link_libraries`` call.
.. versionchanged:: 4.5
If ``<target>`` is an :ref:`Alias Target <Alias Targets>`, the command
operates on the target which the alias references.
Each ``<item>`` may be:
* **A library target name**: The generated link line will have the

View File

@@ -13,8 +13,11 @@ library target.
[{INTERFACE|PUBLIC|PRIVATE} <item>...]...)
The named ``<target>`` must have been created by a command such as
:command:`add_executable` or :command:`add_library` and must not be an
:ref:`ALIAS target <Alias Targets>`.
:command:`add_executable` or :command:`add_library`.
.. versionchanged:: 4.5
If ``<target>`` is an :ref:`Alias Target <Alias Targets>`, 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

View File

@@ -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 ``<target>``.
The named ``<target>`` must have been created by a command such as
:command:`add_executable` or :command:`add_library` and must not be an
:ref:`ALIAS target <Alias Targets>`.
:command:`add_executable` or :command:`add_library`.
.. versionchanged:: 4.5
If ``<target>`` is an :ref:`Alias Target <Alias Targets>`, the command
operates on the target which the alias references.
The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
specify the :ref:`scope <Target Command Scope>` of the following arguments.

View File

@@ -14,13 +14,16 @@ Add sources to a target.
Specifies sources to use when building a target and/or its dependents.
The named ``<target>`` 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 <Alias Targets>`. The ``<items>`` may use
:command:`add_custom_target`. The ``<items>`` may use
:manual:`generator expressions <cmake-generator-expressions(7)>`.
.. versionadded:: 3.20
``<target>`` can be a custom target.
.. versionchanged:: 4.5
If ``<target>`` is an :ref:`Alias Target <Alias Targets>`, the command
operates on the target which the alias references.
The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
specify the :ref:`scope <Target Command Scope>` of the source file paths
(``<items>``) that follow them. ``PRIVATE`` and ``PUBLIC`` items will

View File

@@ -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

View File

@@ -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 <Alias Targets>`, this property contains
the name of the target aliased.

View File

@@ -0,0 +1,18 @@
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 :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 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

@@ -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.");

View File

@@ -35,10 +35,6 @@ bool cmSetTargetPropertiesCommand(std::vector<std::string> 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<std::string> 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);
}

View File

@@ -2126,6 +2126,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 } },

View File

@@ -78,12 +78,6 @@ bool cmTargetLinkLibrariesCommand(std::vector<std::string> 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) {

View File

@@ -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) {

View File

@@ -12,10 +12,20 @@ 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(generator-expression)
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)

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()

View File

@@ -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()

View File

@@ -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 $<TARGET_PROPERTY:alias::lib,FOO>)
set_property(TARGET lib PROPERTY FOO value)
file(GENERATE OUTPUT "generator-expression-generated.txt" CONTENT "$<TARGET_PROPERTY:lib,COMPILE_DEFINITIONS>")

View File

@@ -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

View File

@@ -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)

View File

@@ -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\)

View File

@@ -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()

View File

@@ -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

View File

@@ -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)

View File

@@ -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\)

View File

@@ -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()

View File

@@ -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()

View File

@@ -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()

View File

@@ -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()

View File

@@ -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\)

View File

@@ -6,3 +6,7 @@ add_library(foo empty.cpp)
add_library(alias ALIAS foo)
target_include_directories(alias PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
get_target_property(val foo INCLUDE_DIRECTORIES)
if(NOT "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>" 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 '$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>'.")
endif()

View File

@@ -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()

View File

@@ -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\)

View File

@@ -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()

View File

@@ -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()

View File

@@ -0,0 +1,12 @@
enable_language(CXX)
add_library(foo empty.cpp)
add_library(alias ALIAS foo)
target_precompile_headers(alias PRIVATE <vector>)
get_target_property(val foo PRECOMPILE_HEADERS)
if(NOT "<vector>" IN_LIST val)
message(SEND_ERROR "target_precompile_headers(): Target property 'PRECOMPILE_HEADERS' is missing value added to ALIAS 'alias' on aliased target 'foo': '<vector>' not in '${val}'.")
endif()

View File

@@ -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()

View File

@@ -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\)

View File

@@ -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()