Files
cmake/Tests/RunCMake/GeneratorExpression/ListTransformApplyDependTarget.cmake
Mickaël Germain 0f6e8ded1d GenEx: add $<LIST:TRANSFORM,...,APPLY,body> action
Add an APPLY action to $<LIST:TRANSFORM> that evaluates an arbitrary <body>
once per selected element, with $<_0> bound to the element, so a list can be
mapped through any generator expression at generate time.  Unlike the
configure-time list(TRANSFORM ... APPLY <function>) command, the genex form has
no side effects and returns the body's value directly, and a list-valued result
expands into multiple elements.

The body evaluates in its own binding scope, so nested APPLY actions can shadow
$<_0>, and context-sensitive state it observes (such as target dependencies)
still propagates to the enclosing expression.  APPLY accepts the same
AT/FOR/REGEX selectors as the canned actions.

Issue: #27892
2026-06-21 18:05:53 -07:00

19 lines
819 B
CMake

enable_language(C)
# `provider` is EXCLUDE_FROM_ALL, so it builds only when another target declares
# a build-order dependency on it.
add_library(provider STATIC ListTransformApplyDependTarget.c)
set_property(TARGET provider PROPERTY EXCLUDE_FROM_ALL 1)
# `consumer`'s only reference to `provider` is the $<TARGET_FILE:$<_0>> in the
# APPLY body. CMake derives the build-order dependency from that reference only
# if APPLY propagates the target back out (DependTargets). If that regresses,
# `provider` is never built and the copy below fails for lack of the archive, so
# a green build of `consumer` alone is the regression guard.
add_custom_target(consumer
COMMAND "${CMAKE_COMMAND}" -E copy
"$<LIST:TRANSFORM,provider,APPLY,$<TARGET_FILE:$<_0>>>"
"${CMAKE_CURRENT_BINARY_DIR}/copied.out"
VERBATIM
)