From f4059c5923dfac29650d8158ab3c29105125ffbf Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Fri, 5 Sep 2025 16:51:22 +1000 Subject: [PATCH] GoogleTest: Prevent spurious CMP0178 warning for EXTRA_ARGS Fixes: #27190 --- Modules/GoogleTest.cmake | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Modules/GoogleTest.cmake b/Modules/GoogleTest.cmake index bf4c501986..4d5878bee8 100644 --- a/Modules/GoogleTest.cmake +++ b/Modules/GoogleTest.cmake @@ -643,11 +643,21 @@ function(gtest_discover_tests target) PARENT_SCOPE # undocumented, do not use outside of CMake ) if(NOT cmp0178 STREQUAL "NEW") - # Preserve old behavior where empty list items are silently discarded + # Preserve old behavior where empty list items are silently discarded. + # Before CMP0178 was added, we used the old cmake_parse_arguments() form + # rather than cmake_parse_arguments(PARSE_ARGV). The latter escapes + # embedded semicolons if a value is quoted and there are semicolons + # within the quoted value. We can't just unescape them to get the old + # value, we have to reparse the arguments with the old form. + cmake_parse_arguments(old_arg + "${options}" "${oneValueArgs}" "${multiValueArgs}" + ${ARGN} + ) + set(new_arg_EXTRA_ARGS "${arg_EXTRA_ARGS}") + set(arg_EXTRA_ARGS "${old_arg_EXTRA_ARGS}") + set(test_executor_orig "${test_executor}") set(test_executor ${test_executor}) - set(arg_EXTRA_ARGS_orig "${arg_EXTRA_ARGS}") - set(arg_EXTRA_ARGS ${arg_EXTRA_ARGS}) if(NOT cmp0178 STREQUAL "OLD") if(NOT "${test_executor}" STREQUAL "${test_executor_orig}") cmake_policy(GET_WARNING CMP0178 cmp0178_warning) @@ -659,7 +669,9 @@ function(gtest_discover_tests target) "${cmp0178_warning}" ) endif() - if(NOT "${arg_EXTRA_ARGS}" STREQUAL "${arg_EXTRA_ARGS_orig}") + # Unescape semicolons from the PARSE_ARGV form's value before comparing + string(REPLACE [[\;]] ";" new_arg_EXTRA_ARGS "${new_arg_EXTRA_ARGS}") + if(NOT "${old_arg_EXTRA_ARGS}" STREQUAL "${new_arg_EXTRA_ARGS}") cmake_policy(GET_WARNING CMP0178 cmp0178_warning) message(AUTHOR_WARNING "The EXTRA_ARGS value contains one or more empty values. "