mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 21:31:08 -06:00
add_custom_{command,target}: add genex support for COMMENT
Evaluate and expand generator expressions in the `COMMENT` argument of the `add_custom_command()` and `add_custom_target()` commands. This allows to include generator expressions, e.g. a targets location $<TARGET_...> or the current configuration $<CONFIG>, in the build-time messages. Fixes #22507
This commit is contained in:
@@ -140,6 +140,10 @@ The options are:
|
|||||||
Display the given message before the commands are executed at
|
Display the given message before the commands are executed at
|
||||||
build time.
|
build time.
|
||||||
|
|
||||||
|
.. versionadded:: 3.26
|
||||||
|
Arguments to ``COMMENT`` may use
|
||||||
|
:manual:`generator expressions <cmake-generator-expressions(7)>`.
|
||||||
|
|
||||||
``DEPENDS``
|
``DEPENDS``
|
||||||
Specify files on which the command depends. Each argument is converted
|
Specify files on which the command depends. Each argument is converted
|
||||||
to a dependency as follows:
|
to a dependency as follows:
|
||||||
|
|||||||
@@ -109,6 +109,10 @@ The options are:
|
|||||||
Display the given message before the commands are executed at
|
Display the given message before the commands are executed at
|
||||||
build time.
|
build time.
|
||||||
|
|
||||||
|
.. versionadded:: 3.26
|
||||||
|
Arguments to ``COMMENT`` may use
|
||||||
|
:manual:`generator expressions <cmake-generator-expressions(7)>`.
|
||||||
|
|
||||||
``DEPENDS``
|
``DEPENDS``
|
||||||
Reference files and outputs of custom commands created with
|
Reference files and outputs of custom commands created with
|
||||||
:command:`add_custom_command` command calls in the same directory
|
:command:`add_custom_command` command calls in the same directory
|
||||||
|
|||||||
6
Help/release/dev/custom-command-comment-genex.rst
Normal file
6
Help/release/dev/custom-command-comment-genex.rst
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
custom-command-comment-genex
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
* :command:`add_custom_command` and :command:`add_custom_target` now
|
||||||
|
support :manual:`generator expressions <cmake-generator-expressions(7)>`
|
||||||
|
in their ``COMMENT`` option.
|
||||||
@@ -148,6 +148,14 @@ std::string EvaluateDepfile(std::string const& path,
|
|||||||
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(path);
|
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(path);
|
||||||
return cge->Evaluate(lg, config);
|
return cge->Evaluate(lg, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string EvaluateComment(const char* comment,
|
||||||
|
cmGeneratorExpression const& ge,
|
||||||
|
cmLocalGenerator* lg, std::string const& config)
|
||||||
|
{
|
||||||
|
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(comment);
|
||||||
|
return cge->Evaluate(lg, config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmCustomCommandGenerator::cmCustomCommandGenerator(
|
cmCustomCommandGenerator::cmCustomCommandGenerator(
|
||||||
@@ -465,10 +473,17 @@ std::string cmCustomCommandGenerator::GetInternalDepfile() const
|
|||||||
|
|
||||||
cm::optional<std::string> cmCustomCommandGenerator::GetComment() const
|
cm::optional<std::string> cmCustomCommandGenerator::GetComment() const
|
||||||
{
|
{
|
||||||
if (const char* comment = this->CC->GetComment()) {
|
const char* comment = this->CC->GetComment();
|
||||||
return comment;
|
if (!comment) {
|
||||||
|
return cm::nullopt;
|
||||||
}
|
}
|
||||||
return cm::nullopt;
|
if (!*comment) {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
cmGeneratorExpression ge(*this->LG->GetCMakeInstance(),
|
||||||
|
this->CC->GetBacktrace());
|
||||||
|
return EvaluateComment(comment, ge, this->LG, this->OutputConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cmCustomCommandGenerator::GetWorkingDirectory() const
|
std::string cmCustomCommandGenerator::GetWorkingDirectory() const
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
lorem ipsum, 01
|
||||||
9
Tests/RunCMake/add_custom_command/CommentGenex.cmake
Normal file
9
Tests/RunCMake/add_custom_command/CommentGenex.cmake
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
add_custom_target(helper)
|
||||||
|
set_property(TARGET helper PROPERTY MY_TEXT "lorem ipsum")
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT out.txt
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E echo true
|
||||||
|
COMMENT "$<TARGET_PROPERTY:helper,MY_TEXT>$<COMMA> $<STREQUAL:foo,bar>$<EQUAL:42,42>"
|
||||||
|
)
|
||||||
|
set_property(SOURCE out.txt PROPERTY SYMBOLIC 1)
|
||||||
|
add_custom_target(main ALL DEPENDS out.txt)
|
||||||
@@ -60,3 +60,12 @@ function(test_genex name)
|
|||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
test_genex(TargetGenexEvent)
|
test_genex(TargetGenexEvent)
|
||||||
|
|
||||||
|
if(NOT RunCMake_GENERATOR STREQUAL "Xcode")
|
||||||
|
block()
|
||||||
|
run_cmake(CommentGenex)
|
||||||
|
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CommentGenex-build)
|
||||||
|
set(RunCMake_TEST_NO_CLEAN 1)
|
||||||
|
run_cmake_command(CommentGenex-build ${CMAKE_COMMAND} --build .)
|
||||||
|
endblock()
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
lorem ipsum, 01
|
||||||
6
Tests/RunCMake/add_custom_target/CommentGenex.cmake
Normal file
6
Tests/RunCMake/add_custom_target/CommentGenex.cmake
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
add_custom_target(helper)
|
||||||
|
set_property(TARGET helper PROPERTY MY_TEXT "lorem ipsum")
|
||||||
|
add_custom_target(main ALL
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E true
|
||||||
|
COMMENT "$<TARGET_PROPERTY:helper,MY_TEXT>$<COMMA> $<STREQUAL:foo,bar>$<EQUAL:42,42>"
|
||||||
|
)
|
||||||
@@ -23,3 +23,12 @@ function(run_TargetOrder)
|
|||||||
run_cmake_command(TargetOrder-build ${CMAKE_COMMAND} --build . -- ${build_flags})
|
run_cmake_command(TargetOrder-build ${CMAKE_COMMAND} --build . -- ${build_flags})
|
||||||
endfunction()
|
endfunction()
|
||||||
run_TargetOrder()
|
run_TargetOrder()
|
||||||
|
|
||||||
|
if(NOT RunCMake_GENERATOR STREQUAL "Xcode")
|
||||||
|
block()
|
||||||
|
run_cmake(CommentGenex)
|
||||||
|
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CommentGenex-build)
|
||||||
|
set(RunCMake_TEST_NO_CLEAN 1)
|
||||||
|
run_cmake_command(CommentGenex-build ${CMAKE_COMMAND} --build .)
|
||||||
|
endblock()
|
||||||
|
endif()
|
||||||
|
|||||||
Reference in New Issue
Block a user