GoogleTest: Prevent spurious CMP0178 warning for EXTRA_ARGS

Fixes: #27190
This commit is contained in:
Craig Scott
2025-09-05 16:51:22 +10:00
parent 2870bab401
commit f4059c5923
+16 -4
View File
@@ -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. "