summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2024-02-01 13:32:11 (GMT)
committerKitware Robot <kwrobot@kitware.com>2024-02-01 13:32:20 (GMT)
commit58d424bca1d4e4cfc755e2fba95fdf55f6e9f215 (patch)
tree75d40faa60701761f0448ceee655241f90c0d738
parent3cabf45a99b8221d4402bf538d3e3b2d1869e003 (diff)
parent3b07ec631db67e2e44d9f39fb7727a2dafd07b6a (diff)
downloadCMake-58d424bca1d4e4cfc755e2fba95fdf55f6e9f215.zip
CMake-58d424bca1d4e4cfc755e2fba95fdf55f6e9f215.tar.gz
CMake-58d424bca1d4e4cfc755e2fba95fdf55f6e9f215.tar.bz2
Merge topic 'add_custom_command-target-alias'
3b07ec631d add_custom_command: Allow adding build event via ALIAS target Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !9201
-rw-r--r--Help/command/add_custom_command.rst3
-rw-r--r--Help/release/dev/add_custom_command-target-alias.rst5
-rw-r--r--Source/cmMakefile.cxx10
-rw-r--r--Tests/CustomCommand/CMakeLists.txt4
4 files changed, 19 insertions, 3 deletions
diff --git a/Help/command/add_custom_command.rst b/Help/command/add_custom_command.rst
index 2bb1390..5996d64 100644
--- a/Help/command/add_custom_command.rst
+++ b/Help/command/add_custom_command.rst
@@ -554,6 +554,9 @@ one of the keywords to make clear the behavior they expect.
.. versionadded:: 3.21
Support for target-dependent generator expressions.
+.. versionadded:: 3.29
+ The ``<target>`` may be an :ref:`ALIAS target <Alias Targets>`.
+
Examples: Build Events
^^^^^^^^^^^^^^^^^^^^^^
diff --git a/Help/release/dev/add_custom_command-target-alias.rst b/Help/release/dev/add_custom_command-target-alias.rst
new file mode 100644
index 0000000..7646a53
--- /dev/null
+++ b/Help/release/dev/add_custom_command-target-alias.rst
@@ -0,0 +1,5 @@
+add_custom_command-target-alias
+-------------------------------
+
+* The :ref:`add_custom_command(TARGET) <add_custom_command(TARGET)>`
+ signature now supports adding build events through :ref:`Alias Targets`.
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 2687afa..509f28b 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -1144,9 +1144,15 @@ cmTarget* cmMakefile::GetCustomCommandTarget(
const std::string& target, cmObjectLibraryCommands objLibCommands,
const cmListFileBacktrace& lfbt) const
{
- // Find the target to which to add the custom command.
- auto ti = this->Targets.find(target);
+ auto realTarget = target;
+ auto ai = this->AliasTargets.find(target);
+ if (ai != this->AliasTargets.end()) {
+ realTarget = ai->second;
+ }
+
+ // Find the target to which to add the custom command.
+ auto ti = this->Targets.find(realTarget);
if (ti == this->Targets.end()) {
MessageType messageType = MessageType::AUTHOR_WARNING;
bool issueMessage = false;
diff --git a/Tests/CustomCommand/CMakeLists.txt b/Tests/CustomCommand/CMakeLists.txt
index 25df300..d46ee08 100644
--- a/Tests/CustomCommand/CMakeLists.txt
+++ b/Tests/CustomCommand/CMakeLists.txt
@@ -214,11 +214,13 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated_extern.cxx
add_executable(CustomCommandUsingTargetTest main.cxx ${CMAKE_CURRENT_BINARY_DIR}/generated_extern.cxx )
+add_executable(CustomCommandUsingTargetTestAlias ALIAS CustomCommandUsingTargetTest )
+
add_custom_target(RunTarget
COMMAND generator_extern ${CMAKE_CURRENT_BINARY_DIR}/run_target.cxx
)
-add_custom_command(TARGET CustomCommandUsingTargetTest POST_BUILD
+add_custom_command(TARGET CustomCommandUsingTargetTestAlias POST_BUILD
COMMAND dummy_generator ${CMAKE_CURRENT_BINARY_DIR}/generated_dummy.cxx)
add_subdirectory(GeneratorInExtraDir)