Skip to content

Commit

Permalink
feat: enable /Wall with MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrechette committed Sep 19, 2023
1 parent 23a9b20 commit 2363df3
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion cmake/CMakeCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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()

0 comments on commit 2363df3

Please sign in to comment.