Files
CMake/Tests/RunCMake/ToolchainWrappers/InterfaceGenex.cmake
T
Tyler YankeeandJoseph Snyder c355bd02e4 Ninja, Makefile: Add compile and link wrapper usage requirements
Introduce new properties which allow target-specific wrapping of
compile and link commands with arbitrary command lines. This is similar
to the existing compiler and linker launchers, except the new
`INTERFACE` compile and link wrappers allows expression as usage
requirements.

Wrappers are more flexible than launchers with regard to having
multiple belonging to a given target, either from the target itself or
dependent(s). In such cases, wrappers precede launchers on the
resulting command line (so as to not interfere with tools like
`ccache`), and are sorted lexicographically by the name of the
corresponding CMake global property containing their value.

Co-authored-by: Joseph Snyder <joseph.snyder@kitware.com>
Issue: #27402, #28110
Fixes: #27598
2026-09-30 07:51:22 -04:00

28 lines
1.1 KiB
CMake

enable_language(C)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT}")
string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT}")
string(REPLACE "${CMAKE_START_TEMP_FILE}" "" CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE}")
string(REPLACE "${CMAKE_END_TEMP_FILE}" "" CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE}")
# INTERFACE_{COMPILE,LINK}_WRAPPERS values may themselves use
# $<COMPILE_LANGUAGE:...>/$<LINK_LANGUAGE:...> generator expressions.
set_property(GLOBAL PROPERTY
CMAKE_COMPILE_WRAPPER_IFACE_GENEX
"${CMAKE_COMMAND};-E;env;CW_IFACE_GENEX=1"
)
set_property(GLOBAL PROPERTY
CMAKE_LINK_WRAPPER_IFACE_GENEX
"${CMAKE_COMMAND};-E;env;LW_IFACE_GENEX=1"
)
add_library(iface_genex INTERFACE)
set_target_properties(iface_genex PROPERTIES
INTERFACE_COMPILE_WRAPPERS "$<$<COMPILE_LANGUAGE:C>:IFACE_GENEX>"
INTERFACE_LINK_WRAPPERS "$<$<LINK_LANGUAGE:C>:IFACE_GENEX>"
)
add_executable(main main.c)
target_link_libraries(main PRIVATE iface_genex)