Files
cmake/Tests/RunCMake/CMP0219/MixedChain-OLD-NEWMiddle.cmake
Alex Reinking 9d2e85373a macro: Add policy to preserve backslashes in arguments
Preserve backslashes in arguments passed to macros by re-escaping
them before substituting in the macro body, where they will be
parsed again.

Fixes: #19281, #22157, #23641, #25803, #27645, #20891
2026-05-31 14:36:15 -04:00

49 lines
1.5 KiB
CMake

include("${CMAKE_CURRENT_LIST_DIR}/CMP0219-helpers.cmake")
# Build progressively escaped variants to model callers that added extra
# backslashes to make an OLD-only macro chain work.
string(REPLACE "\\" "\\\\" cmp0219_path_2 "${cmp0219_path_native}")
string(REPLACE "\\" "\\\\" cmp0219_path_4 "${cmp0219_path_2}")
string(REPLACE "\\" "\\\\" cmp0219_path_8 "${cmp0219_path_4}")
cmake_policy(SET CMP0219 OLD)
macro(cmp0219_leaf var_name)
set(${var_name} "${ARGN}")
endmacro()
macro(cmp0219_middle_old)
cmp0219_leaf(cmp0219_old_chain_capture ${ARGN})
endmacro()
macro(cmp0219_middle_new)
# Simulate a dependency update opting this middle forwarding layer into NEW.
cmake_policy(PUSH)
cmake_policy(SET CMP0219 NEW)
cmp0219_leaf(cmp0219_mixed_chain_capture ${ARGN})
cmake_policy(POP)
endmacro()
macro(cmp0219_outer_to_old)
cmp0219_middle_old(${ARGN})
endmacro()
macro(cmp0219_outer_to_new_middle)
cmp0219_middle_new(${ARGN})
endmacro()
# OLD->OLD->OLD requires heavily escaped input and produces a native path.
cmp0219_outer_to_old(HINTS "${cmp0219_path_8}")
cmp0219_assert_equal(
"${cmp0219_old_chain_capture}" "HINTS;${cmp0219_path_native}")
# OLD->NEW->OLD with the same input preserves one extra layer.
cmp0219_outer_to_new_middle(HINTS "${cmp0219_path_8}")
cmp0219_assert_equal(
"${cmp0219_mixed_chain_capture}" "HINTS;${cmp0219_path_2}")
# OLD->NEW->OLD needs fewer escape layers to reach a native path.
cmp0219_outer_to_new_middle(HINTS "${cmp0219_path_4}")
cmp0219_assert_equal(
"${cmp0219_mixed_chain_capture}" "HINTS;${cmp0219_path_native}")