From 7ec05f657d70a78922f84b57a0d645ee38ce6120 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 24 Jul 2026 06:24:45 -0700 Subject: [PATCH] Handle both -F and /F formats in GoogleTest CMake command lines as MSVC accepts both This is the legacy fix for https://github.com/google/googletest/issues/4731, and to prevent similar breakages in the future with other flags. The modern fix will be handled separately. PiperOrigin-RevId: 953333662 Change-Id: I7c58b0123170878f0fe6909cabd5decc922b38f1 --- googletest/cmake/internal_utils.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index da1923f3b..e7f33ffb6 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -35,21 +35,21 @@ macro(fix_default_compiler_settings_) # preferable to use CRT as static libraries, as we don't have to rely # on CRT DLLs being available. CMake always defaults to using shared # CRT libraries, so we override that default here. - string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}") + string(REGEX REPLACE "([/-])MD" "\\1MT" ${flag_var} "${${flag_var}}") # When using Ninja with Clang, static builds pass -D_DLL on Windows. # This is incorrect and should not happen, so we fix that here. - string(REPLACE "-D_DLL" "" ${flag_var} "${${flag_var}}") + string(REGEX REPLACE "([/-])D_DLL" "" ${flag_var} "${${flag_var}}") endif() # We prefer more strict warning checking for building Google Test. # Replaces /W3 with /W4 in defaults. - string(REPLACE "/W3" "/W4" ${flag_var} "${${flag_var}}") + string(REGEX REPLACE "([/-])W3" "\\1W4" ${flag_var} "${${flag_var}}") # Prevent D9025 warning for targets that have exception handling # turned off (/EHs-c- flag). Where required, exceptions are explicitly # re-enabled using the cxx_exception_flags variable. - string(REPLACE "/EHsc" "" ${flag_var} "${${flag_var}}") + string(REGEX REPLACE "([/-])EHsc" "" ${flag_var} "${${flag_var}}") endforeach() endif() endmacro()