Skip to content

Commit efebaa9

Browse files
authored
Fix clang-cl warning flags: use /W4 instead of /Wall
This PR fixes the warning flags when building with **clang-cl**. Previously, the CMake configuration unconditionally added `-Wall -Wextra` for Clang. However, according to the [clang-cl documentation](https://clang.llvm.org/docs/UsersManual.html#clang-cl), `/Wall` in clang-cl is mapped to `-Weverything`, which enables **all possible warnings**, far more than MSVC’s `/Wall`. This results in a flood of warnings that are not intended. The original intent was to match MSVC `/W4` (≈ `-Wall -Wextra` in GCC/Clang).
1 parent 7406782 commit efebaa9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
122122
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3.0)
123123
message(FATAL_ERROR "llvm/clang 3.3 or higher required!")
124124
endif()
125-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
125+
if ("${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "GNU")
126+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
127+
elseif("${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC")
128+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
129+
add_definitions(-DUNICODE -DNOMINMAX)
130+
set(CMAKE_DEBUG_POSTFIX _d)
131+
endif()
126132
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
127133
if(MSVC_VERSION LESS 1900)
128134
message(FATAL_ERROR "msvc 2015 or higher required!")

0 commit comments

Comments
 (0)