diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 6f7fdc2ca..41405587f 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -21,8 +21,9 @@ endif (POLICY CMP0054) # This must be a macro(), as inside a function string() can only # update variables in the function scope. macro(fix_default_compiler_settings_) - if (MSVC) - # For MSVC, CMake sets certain flags to defaults we want to override. + if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC|Clang") + # For MSVC and Clang, CMake sets certain flags to defaults we want to + # override. # This replacement code is taken from sample in the CMake Wiki at # https://gitlab.kitware.com/cmake/community/wikis/FAQ#dynamic-replace. foreach (flag_var @@ -39,6 +40,10 @@ macro(fix_default_compiler_settings_) # 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}}") + + # 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}}") endif() # We prefer more strict warning checking for building Google Test.