mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
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
18 lines
1.0 KiB
CMake
18 lines
1.0 KiB
CMake
add_library(libA INTERFACE)
|
|
target_include_directories(libA INTERFACE /a/one /a/two)
|
|
add_library(libB INTERFACE)
|
|
target_include_directories(libB INTERFACE /b/one)
|
|
|
|
# Nested APPLY: the outer APPLY runs over targets; its body is an APPLY over
|
|
# each target's include directories that uppercases them. The outer $<_0> (a
|
|
# target) feeds the inner list arg $<TARGET_PROPERTY:...>; the inner $<_0> (a
|
|
# directory) feeds $<UPPER_CASE> under the inner binding, while the outer
|
|
# binding stays intact.
|
|
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/nested.txt"
|
|
CONTENT "$<LIST:TRANSFORM,libA;libB,APPLY,$<LIST:TRANSFORM,$<TARGET_PROPERTY:$<_0>,INTERFACE_INCLUDE_DIRECTORIES>,APPLY,$<UPPER_CASE:$<_0>>>>\n")
|
|
|
|
# Exact reference: the same result without the inner APPLY (uppercase each
|
|
# target's include dirs directly). The nested APPLY must match it.
|
|
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/expected.txt"
|
|
CONTENT "$<UPPER_CASE:$<TARGET_PROPERTY:libA,INTERFACE_INCLUDE_DIRECTORIES>>;$<UPPER_CASE:$<TARGET_PROPERTY:libB,INTERFACE_INCLUDE_DIRECTORIES>>\n")
|