From 89a01843ee090db671670dc22e1996a2bd625e3d Mon Sep 17 00:00:00 2001 From: Duncan Horn <40036384+dunhor@users.noreply.github.com> Date: Sat, 8 Jun 2024 12:41:04 -0700 Subject: [PATCH] Fix compilation when using Clang in "MSVC mode" (#2221) When using Clang in "MSVC mode" (i.e. clang-cl), command line arguments are interpreted as MSVC would interpret them, at least when there are conflicts. This means that `-Wall` - potentially among other switches - is interpreted _dramatically_ differently by clang-cl compared to "normal" Clang. In CMake, this can be detected by testing for `if (MSVC)` in addition to compiler id test, which is what I do here. Note: this is a partial cherry-pick from #2095, which I'm going to go through and break into smaller pieces in hopes of getting some things in while discussion of other things can continue. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 822056b91..51c8c0814 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,7 +107,7 @@ endif () # aggressive about diagnosing build problems; this can get # relaxed somewhat in final shipping versions. IF (CMAKE_C_COMPILER_ID MATCHES "^GNU$" OR - CMAKE_C_COMPILER_ID MATCHES "^Clang$") + CMAKE_C_COMPILER_ID MATCHES "^Clang$" AND NOT MSVC) SET(CMAKE_REQUIRED_FLAGS "-Wall -Wformat -Wformat-security") ################################################################# # Set compile flags for all build types. @@ -144,7 +144,7 @@ IF (CMAKE_C_COMPILER_ID MATCHES "^GNU$" OR SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip") ENDIF(NOT CMAKE_SYSTEM_NAME MATCHES "Darwin") ENDIF (CMAKE_C_COMPILER_ID MATCHES "^GNU$" OR - CMAKE_C_COMPILER_ID MATCHES "^Clang$") + CMAKE_C_COMPILER_ID MATCHES "^Clang$" AND NOT MSVC) IF (CMAKE_C_COMPILER_ID MATCHES "^XL$") SET(CMAKE_C_COMPILER "xlc_r") SET(CMAKE_REQUIRED_FLAGS "-qflag=e:e -qformat=sec") -- 2.47.2