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