mirror of
https://github.com/transmission/transmission
synced 2025-01-30 19:03:04 +00:00
Don't test warning flags inherently unsupported by compiler
MSVC does not support GNU-style compiler flags, and vice versa. Not only does it make no sense to test for those flags, with MSVC it also takes considerably longer to do so. The only flag that MSVC does support is -Wall (/Wall), but since it's equivalent to Clang's -Weverything and thus issues lots of warnings nobody usually cares about, including from system header files, it's preferred to use /W4.
This commit is contained in:
parent
4e5ad7937a
commit
5125feca5d
1 changed files with 93 additions and 85 deletions
178
CMakeLists.txt
178
CMakeLists.txt
|
@ -404,97 +404,105 @@ set(CXX_WARNING_FLAGS)
|
|||
include(CheckCCompilerFlag)
|
||||
include(CheckCXXCompilerFlag)
|
||||
|
||||
set(WARNING_CANDIDATES
|
||||
-W
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wcast-align
|
||||
-Wduplicated-cond
|
||||
-Wexit-time-destructors
|
||||
-Wextra-semi
|
||||
-Wextra-semi-stmt
|
||||
-Wextra-tokens
|
||||
-Wfloat-equal
|
||||
-Wgnu
|
||||
-Winit-self
|
||||
-Wint-in-bool-context
|
||||
-Wlogical-op
|
||||
-Wmissing-format-attribute
|
||||
-Wnested-externs
|
||||
-Wnull-dereference
|
||||
-Wpointer-arith
|
||||
-Wredundant-decls
|
||||
-Wredundant-move
|
||||
-Wreorder-ctor
|
||||
-Wrestrict
|
||||
-Wreturn-std-move
|
||||
-Wself-assign
|
||||
-Wself-move
|
||||
-Wsemicolon-before-method-body
|
||||
-Wsentinel
|
||||
-Wshadow
|
||||
-Wsign-compare
|
||||
-Wsometimes-uninitialized
|
||||
-Wstrict-prototypes
|
||||
-Wstring-conversion
|
||||
-Wsuggest-destructor-override
|
||||
-Wsuggest-override
|
||||
-Wuninitialized
|
||||
-Wunreachable-code
|
||||
-Wunused
|
||||
-Wunused-const-variable
|
||||
-Wunused-parameter
|
||||
-Wunused-result
|
||||
-Wwrite-strings
|
||||
)
|
||||
if(MSVC)
|
||||
set(WARNING_CANDIDATES
|
||||
/W4)
|
||||
|
||||
if(MINGW)
|
||||
# Disable excessive warnings since we're using __USE_MINGW_ANSI_STDIO
|
||||
# Hopefully, any potential issues will be spotted on other platforms
|
||||
list(APPEND WARNING_CANDIDATES -Wno-format)
|
||||
else()
|
||||
list(APPEND WARNING_CANDIDATES -Wformat-security)
|
||||
endif()
|
||||
|
||||
set(CMAKE_REQUIRED_FLAGS)
|
||||
|
||||
foreach(FLAG -Werror /WX)
|
||||
tr_make_id("${FLAG}" FLAG_ID)
|
||||
set(CACHE_ID "${CMAKE_C_COMPILER_ID}_C_HAS${FLAG_ID}")
|
||||
string(TOLOWER "${CACHE_ID}" CACHE_ID)
|
||||
check_c_compiler_flag(${FLAG} ${CACHE_ID})
|
||||
if (${CACHE_ID})
|
||||
# Make sure the next loop only adds flags that are relevant for a particular language
|
||||
set(CMAKE_REQUIRED_FLAGS ${FLAG})
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
foreach(FLAG ${WARNING_CANDIDATES})
|
||||
tr_make_id("${FLAG}" FLAG_ID)
|
||||
|
||||
# if available, add to C warnings
|
||||
set(CACHE_ID "${CMAKE_C_COMPILER_ID}_C_HAS${FLAG_ID}")
|
||||
string(TOLOWER "${CACHE_ID}" CACHE_ID)
|
||||
check_c_compiler_flag(${FLAG} ${CACHE_ID})
|
||||
if (${CACHE_ID})
|
||||
foreach(FLAG ${WARNING_CANDIDATES})
|
||||
list(APPEND C_WARNING_FLAGS ${FLAG})
|
||||
endif()
|
||||
|
||||
# if available, add to CXX warnings
|
||||
set(CACHE_ID "${CMAKE_CXX_COMPILER_ID}_CXX_HAS${FLAG_ID}")
|
||||
string(TOLOWER "${CACHE_ID}" CACHE_ID)
|
||||
check_cxx_compiler_flag(${FLAG} ${CACHE_ID})
|
||||
if (${CACHE_ID})
|
||||
list(APPEND CXX_WARNING_FLAGS ${FLAG})
|
||||
endforeach()
|
||||
else()
|
||||
set(WARNING_CANDIDATES
|
||||
-W
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wcast-align
|
||||
-Wduplicated-cond
|
||||
-Wexit-time-destructors
|
||||
-Wextra-semi
|
||||
-Wextra-semi-stmt
|
||||
-Wextra-tokens
|
||||
-Wfloat-equal
|
||||
-Wgnu
|
||||
-Winit-self
|
||||
-Wint-in-bool-context
|
||||
-Wlogical-op
|
||||
-Wmissing-format-attribute
|
||||
-Wnested-externs
|
||||
-Wnull-dereference
|
||||
-Wpointer-arith
|
||||
-Wredundant-decls
|
||||
-Wredundant-move
|
||||
-Wreorder-ctor
|
||||
-Wrestrict
|
||||
-Wreturn-std-move
|
||||
-Wself-assign
|
||||
-Wself-move
|
||||
-Wsemicolon-before-method-body
|
||||
-Wsentinel
|
||||
-Wshadow
|
||||
-Wsign-compare
|
||||
-Wsometimes-uninitialized
|
||||
-Wstrict-prototypes
|
||||
-Wstring-conversion
|
||||
-Wsuggest-destructor-override
|
||||
-Wsuggest-override
|
||||
-Wuninitialized
|
||||
-Wunreachable-code
|
||||
-Wunused
|
||||
-Wunused-const-variable
|
||||
-Wunused-parameter
|
||||
-Wunused-result
|
||||
-Wwrite-strings)
|
||||
|
||||
if(MINGW)
|
||||
# Disable excessive warnings since we're using __USE_MINGW_ANSI_STDIO
|
||||
# Hopefully, any potential issues will be spotted on other platforms
|
||||
list(APPEND WARNING_CANDIDATES -Wno-format)
|
||||
else()
|
||||
list(APPEND WARNING_CANDIDATES -Wformat-security)
|
||||
endif()
|
||||
|
||||
unset(CACHE_ID)
|
||||
unset(FLAG_ID)
|
||||
endforeach()
|
||||
set(CMAKE_REQUIRED_FLAGS)
|
||||
|
||||
unset(CMAKE_REQUIRED_FLAGS)
|
||||
unset(WARNING_CANDIDATES)
|
||||
foreach(FLAG -Werror /WX)
|
||||
tr_make_id("${FLAG}" FLAG_ID)
|
||||
set(CACHE_ID "${CMAKE_C_COMPILER_ID}_C_HAS${FLAG_ID}")
|
||||
string(TOLOWER "${CACHE_ID}" CACHE_ID)
|
||||
check_c_compiler_flag(${FLAG} ${CACHE_ID})
|
||||
if (${CACHE_ID})
|
||||
# Make sure the next loop only adds flags that are relevant for a particular language
|
||||
set(CMAKE_REQUIRED_FLAGS ${FLAG})
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
foreach(FLAG ${WARNING_CANDIDATES})
|
||||
tr_make_id("${FLAG}" FLAG_ID)
|
||||
|
||||
# if available, add to C warnings
|
||||
set(CACHE_ID "${CMAKE_C_COMPILER_ID}_C_HAS${FLAG_ID}")
|
||||
string(TOLOWER "${CACHE_ID}" CACHE_ID)
|
||||
check_c_compiler_flag(${FLAG} ${CACHE_ID})
|
||||
if (${CACHE_ID})
|
||||
list(APPEND C_WARNING_FLAGS ${FLAG})
|
||||
endif()
|
||||
|
||||
# if available, add to CXX warnings
|
||||
set(CACHE_ID "${CMAKE_CXX_COMPILER_ID}_CXX_HAS${FLAG_ID}")
|
||||
string(TOLOWER "${CACHE_ID}" CACHE_ID)
|
||||
check_cxx_compiler_flag(${FLAG} ${CACHE_ID})
|
||||
if (${CACHE_ID})
|
||||
list(APPEND CXX_WARNING_FLAGS ${FLAG})
|
||||
endif()
|
||||
|
||||
unset(CACHE_ID)
|
||||
unset(FLAG_ID)
|
||||
endforeach()
|
||||
|
||||
unset(CMAKE_REQUIRED_FLAGS)
|
||||
endif()
|
||||
|
||||
###
|
||||
|
||||
|
|
Loading…
Reference in a new issue