Skip to content

Commit

Permalink
Move MSVC warning disables from Compiler.h to cmake
Browse files Browse the repository at this point in the history
Like GCC warnings, warnings will now be controlled by the build
system instead of disabled by including a file. This lets warnings for
Daemon and Unvanquished be controlled more independently.

Some of the warning disable flags will need to be duplicated in
Unvanquished's CMakeLists.txt since the build was relying on Compiler.h
to disable them.
  • Loading branch information
slipher committed May 26, 2024
1 parent f40d5c2 commit a7cb2b2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
24 changes: 14 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,6 @@ set(NACL_VM_INHERITED_OPTIONS "${DEFAULT_NACL_VM_INHERITED_OPTIONS}" CACHE STRIN
"Semicolon-separated list of options for which NaCl game VMs should use the same value as the other binaries")
mark_as_advanced(NACL_VM_INHERITED_OPTIONS)

if (BE_VERBOSE)
set(WARNMODE "no-error=")
else()
set(WARNMODE "no-")
endif()
if (DAEMON_PARENT_SCOPE_DIR)
set(WARNMODE ${WARNMODE} PARENT_SCOPE)
endif()

################################################################################
# Directories
################################################################################
Expand Down Expand Up @@ -287,7 +278,12 @@ endif()

include(DaemonFlags)

# Warning options
# Warning options (for Daemon only)
# Note the different scopes used for warning options:
# * set_c_cxx_flag(xxx) or try_c_cxx_flag(xxx) sets it for all code including dependencies
# * try_flag(WARNINGS xxx) in DaemonFlags.cmake sets it for Daemon and Unvanquished but not deps
# * try_flag(WARNINGS xxx) below sets it for Daemon only

try_flag(WARNINGS "-Wshadow=local")
try_flag(WARNINGS "-Wno-pragmas")
try_flag(WARNINGS "-Wno-unknown-pragmas")
Expand All @@ -296,6 +292,14 @@ try_flag(WARNINGS "-Woverloaded-virtual")
try_flag(WARNINGS "-Wstrict-null-sentinel")
try_flag(WARNINGS "-W${WARNMODE}sign-compare")

# MSVC /wd = warning disable
try_flag(WARNINGS "/wd4127") # conditional expression is constant
try_flag(WARNINGS "/wd4324") # 'XXX': structure was padded due to alignment specifier
try_flag(WARNINGS "/wd4458") # declaration of 'XXX' hides class member
try_flag(WARNINGS "/wd4459") # declaration of 'XXX' hides global declaration
try_flag(WARNINGS "/wd4701") # potentially uninitialized local variable 'XXX' used
try_flag(WARNINGS "/wd26495") # Variable 'XXX' is uninitialized. Always initialize a member variable.

################################################################################
# Group the sources by folder to have folder show in Visual Studio
################################################################################
Expand Down
14 changes: 14 additions & 0 deletions cmake/DaemonFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ macro(try_linker_flag PROP FLAG)
endif()
endmacro()

if (BE_VERBOSE)
set(WARNMODE "no-error=")
else()
set(WARNMODE "no-")
endif()

option(USE_CPU_RECOMMENDED_FEATURES "Use some common hardware features like SSE2, NEON, VFP, MCX16, etc." ON)

if(MINGW AND USE_BREAKPAD)
Expand Down Expand Up @@ -159,6 +165,14 @@ if (MSVC)
endif()
set_linker_flag("/LARGEADDRESSAWARE")

# These warnings need to be disabled for both Daemon and Unvanquished since they are triggered in shared headers
try_flag(WARNINGS "/wd4201") # nonstandard extension used: nameless struct / union
try_flag(WARNINGS "/wd4244") # 'XXX': conversion from 'YYY' to 'ZZZ', possible loss of data
try_flag(WARNINGS "/wd4267") # 'initializing' : conversion from 'size_t' to 'int', possible loss of data

# This warning is garbage because it doesn't go away if you parenthesize the expression
try_flag(WARNINGS "/wd4706") # assignment within conditional expression

# Turn off warning C4996:, e.g:
# warning C4996: 'open': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _open. See online help for details. set_c_cxx_flag("/wd4996")
# open seems far more popular than _open not to mention nicer. There doesn't seem to be any reason or will to change to _open.
Expand Down
17 changes: 0 additions & 17 deletions src/common/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,6 @@ inline int CountTrailingZeroes(unsigned long long x) { return __builtin_ctzll(x)
// Microsoft Visual C++
#elif defined( _MSC_VER )

// Disable some warnings
#pragma warning(disable : 4127) // conditional expression is constant

#pragma warning(disable : 4201) // nonstandard extension used: nameless struct / union
#pragma warning(disable : 4244) // 'XXX': conversion from 'YYY' to 'ZZZ', possible loss of data
#pragma warning(disable : 4267) // 'initializing' : conversion from 'size_t' to 'int', possible loss of data

#pragma warning(disable : 4324) // 'refBone_t': structure was padded due to alignment specifier

#pragma warning(disable : 4458) // declaration of 'XXX' hides class member
#pragma warning(disable : 4459) // declaration of 'XXX' hides global declaration

#pragma warning(disable : 4701) // potentially uninitialized local variable 'XXX' used
#pragma warning(disable : 4706) // assignment within conditional expression

#pragma warning(disable : 26495) // Variable 'XXX' is uninitialized. Always initialize a member variable.

// See descriptions above
#define DEPRECATED __declspec(deprecated)
#define WARN_UNUSED_RESULT _Check_return_
Expand Down

0 comments on commit a7cb2b2

Please sign in to comment.