From da2250cf6f896395aa7b029571586721235bd500 Mon Sep 17 00:00:00 2001 From: Zhirnokleev Konstantin Date: Thu, 14 Aug 2025 17:35:34 +0400 Subject: [PATCH] FIX: Clang and MSVC compile options duplicate for clang-cl Previously, clang-cl inherited both Clang-specific and MSVC-specific flags in `target_compile_options`, leading to duplicate flags and excessive warnings. After this change: - Clang-cl builds now only apply MSVC compile options (/W4, etc.). - Native Clang builds retain only Clang-specific flags. - -Wall/-Wextra for clang are avoided in clang-cl, preventing gigabytes of warnings and drastically improving build times. --- CMakeLists.txt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5feb49c0b..d29fe4bc0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -468,14 +468,17 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") message("Additional Clang compile options for release configurations: " ${DILIGENT_CLANG_RELEASE_COMPILE_OPTIONS}) endif() - target_compile_options(Diligent-BuildSettings INTERFACE - ${DILIGENT_CLANG_COMPILE_OPTIONS} - # Some extra warnings - -Wall -Wextra -Wuninitialized -Wconditional-uninitialized -Wextra-tokens -Wpointer-arith -Wloop-analysis -Wunused - # Disable few warnings - -Wno-overloaded-virtual -Wno-incompatible-pointer-types-discards-qualifiers -Wno-unknown-pragmas - -Wno-zero-as-null-pointer-constant -Wno-unused-parameter -Wno-invalid-offsetof - ) + target_compile_options(Diligent-BuildSettings INTERFACE ${DILIGENT_CLANG_COMPILE_OPTIONS}) + + if(NOT MSVC) + target_compile_options(Diligent-BuildSettings INTERFACE + # Some extra warnings + -Wall -Wextra -Wuninitialized -Wconditional-uninitialized -Wextra-tokens -Wpointer-arith -Wloop-analysis -Wunused + # Disable few warnings + -Wno-overloaded-virtual -Wno-incompatible-pointer-types-discards-qualifiers -Wno-unknown-pragmas + -Wno-zero-as-null-pointer-constant -Wno-unused-parameter -Wno-invalid-offsetof -Wno-c++98-compat -Wunsafe-buffer-usage + ) + endif() target_compile_options(Diligent-BuildSettings INTERFACE "$<$:${DILIGENT_CLANG_DEBUG_COMPILE_OPTIONS}>") set(CLANG_RELEASE_OPTIONS -Wno-unused-variable ${DILIGENT_CLANG_RELEASE_COMPILE_OPTIONS})