From 08935483cb22749b3c3774e9bcd5ef35b5a1a7b7 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 5 Oct 2022 12:26:54 -0700 Subject: [PATCH] Makes Clang compilations via Ninja on Windows define _DLL only for shared CRT builds, as one would already expect from MSVC builds. (Previously, static Clang/Ninja builds on Windows also implicitly defined _DLL, which was problematic.) PiperOrigin-RevId: 479113168 Change-Id: I252d9be90fd33df75dab922e62b197208830d124 --- googletest/cmake/internal_utils.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 6f7fdc2c..41405587 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.