From 2363df3195db6b66caef78d6157d2216dec48b18 Mon Sep 17 00:00:00 2001 From: Nicholas Frechette Date: Mon, 18 Sep 2023 21:06:01 -0400 Subject: [PATCH] feat: enable /Wall with MSVC --- cmake/CMakeCompiler.cmake | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/cmake/CMakeCompiler.cmake b/cmake/CMakeCompiler.cmake index d1ea3212..60a67036 100644 --- a/cmake/CMakeCompiler.cmake +++ b/cmake/CMakeCompiler.cmake @@ -4,7 +4,16 @@ macro(setup_default_compiler_flags _project_name) if(MSVC) # That's also clang-cl # Replace some default compiler switches and add new ones STRING(REPLACE "/GR" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # Disable RTTI - STRING(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # Bump warnings to W4 + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + STRING(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # Enable level 4 warnings + else() + if(MSVC_VERSION GREATER 1920) + # VS2019 and above + STRING(REPLACE "/W3" "/Wall" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # Enable all warnings + else() + STRING(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # Enable level 4 warnings + endif() + endif() target_compile_options(${_project_name} PRIVATE /Zi) # Add debug info target_compile_options(${_project_name} PRIVATE /Oi) # Generate intrinsic functions target_compile_options(${_project_name} PRIVATE /WX) # Treat warnings as errors @@ -27,6 +36,20 @@ macro(setup_default_compiler_flags _project_name) add_definitions(-DRTM_NO_INTRINSICS) endif() + # Disable various warnings that are harmless + target_compile_options(${_project_name} PRIVATE /wd4514) # Unreferenced inline function removed + target_compile_options(${_project_name} PRIVATE /wd4619) # No warning with specified number + target_compile_options(${_project_name} PRIVATE /wd4820) # Padding added after data member + target_compile_options(${_project_name} PRIVATE /wd4710) # Function not inlined + target_compile_options(${_project_name} PRIVATE /wd4711) # Function selected for automatic inlining + target_compile_options(${_project_name} PRIVATE /wd4738) # Storing 32-bit float in memory leads to rounding (x86) + target_compile_options(${_project_name} PRIVATE /wd5045) # Spectre mitigation for memory load + + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + target_compile_options(${_project_name} PRIVATE -Wno-c++98-compat) # No need to support C++98 + target_compile_options(${_project_name} PRIVATE -Wno-c++98-compat-pedantic) # No need to support C++98 + endif() + # Add linker flags set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG") else() @@ -65,6 +88,9 @@ macro(setup_default_compiler_flags _project_name) target_compile_options(${_project_name} PRIVATE -Wshadow) # Enable shadowing warnings target_compile_options(${_project_name} PRIVATE -Werror) # Treat warnings as errors + # Disable various warnings that are harmless + target_compile_options(${_project_name} PRIVATE -Wno-c++98-compat) # No need to support C++98 + target_compile_options(${_project_name} PRIVATE -g) # Enable debug symbols endif() endmacro()