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
31 lines
1.3 KiB
CMake
31 lines
1.3 KiB
CMake
enable_language(C)
|
|
|
|
# Evaluate LINK_LIBRARIES transitively (CMP0189, CMake 4.1+); the test dir's
|
|
# cmake_minimum_required would otherwise leave this OLD.
|
|
cmake_policy(SET CMP0189 NEW)
|
|
|
|
# A dependency tree, linked PUBLIC so each library's dependencies propagate
|
|
# through INTERFACE_LINK_LIBRARIES:
|
|
# app -> { net, audio }; net -> { ssl, zlib }; audio -> codec
|
|
add_library(ssl STATIC empty.c)
|
|
add_library(zlib STATIC empty.c)
|
|
add_library(codec STATIC empty.c)
|
|
|
|
add_library(net STATIC empty.c)
|
|
target_link_libraries(net PUBLIC ssl zlib)
|
|
add_library(audio STATIC empty.c)
|
|
target_link_libraries(audio PUBLIC codec)
|
|
|
|
add_library(app STATIC empty.c)
|
|
target_link_libraries(app PRIVATE net audio)
|
|
|
|
# app's LINK_LIBRARIES now evaluates to the transitive closure
|
|
# (net;audio;ssl;zlib;codec); map each linked library to its on-disk file name.
|
|
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ll.txt"
|
|
CONTENT "$<LIST:TRANSFORM,$<TARGET_PROPERTY:app,LINK_LIBRARIES>,APPLY,$<TARGET_FILE_NAME:$<_0>>>\n")
|
|
|
|
# Exact, platform-independent reference: the explicit per-library expansion in
|
|
# the transitive-closure order. The APPLY output must be byte-identical.
|
|
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/expected.txt"
|
|
CONTENT "$<TARGET_FILE_NAME:net>;$<TARGET_FILE_NAME:audio>;$<TARGET_FILE_NAME:ssl>;$<TARGET_FILE_NAME:zlib>;$<TARGET_FILE_NAME:codec>\n")
|