cmake: tidy up picky warning initialization
- use CMake 3.12 syntax when available, in clang-cl branch. Follow-up toe89491e1f0#15337 - rename internal variables to underscore-lowercase. Follow-up tod8de4806e1#14571 - update comment. Closes #15404
This commit is contained in:
parent
fff6afb0f8
commit
1da1fcc43d
@ -23,24 +23,24 @@
|
|||||||
###########################################################################
|
###########################################################################
|
||||||
include(CheckCCompilerFlag)
|
include(CheckCCompilerFlag)
|
||||||
|
|
||||||
unset(WPICKY)
|
unset(_picky)
|
||||||
|
|
||||||
if(CURL_WERROR AND
|
if(CURL_WERROR AND
|
||||||
((CMAKE_COMPILER_IS_GNUCC AND
|
((CMAKE_COMPILER_IS_GNUCC AND
|
||||||
NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0 AND
|
NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0 AND
|
||||||
NOT CMAKE_VERSION VERSION_LESS 3.23.0) OR # to avoid check_symbol_exists() conflicting with GCC -pedantic-errors
|
NOT CMAKE_VERSION VERSION_LESS 3.23.0) OR # to avoid check_symbol_exists() conflicting with GCC -pedantic-errors
|
||||||
CMAKE_C_COMPILER_ID MATCHES "Clang"))
|
CMAKE_C_COMPILER_ID MATCHES "Clang"))
|
||||||
list(APPEND WPICKY "-pedantic-errors")
|
list(APPEND _picky "-pedantic-errors")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(APPLE AND
|
if(APPLE AND
|
||||||
(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.6) OR
|
(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.6) OR
|
||||||
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.3))
|
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.3))
|
||||||
list(APPEND WPICKY "-Werror=partial-availability") # clang 3.6 appleclang 6.3
|
list(APPEND _picky "-Werror=partial-availability") # clang 3.6 appleclang 6.3
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
|
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||||
list(APPEND WPICKY "-Werror-implicit-function-declaration") # clang 1.0 gcc 2.95
|
list(APPEND _picky "-Werror-implicit-function-declaration") # clang 1.0 gcc 2.95
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(PICKY_COMPILER)
|
if(PICKY_COMPILER)
|
||||||
@ -49,29 +49,29 @@ if(PICKY_COMPILER)
|
|||||||
# https://clang.llvm.org/docs/DiagnosticsReference.html
|
# https://clang.llvm.org/docs/DiagnosticsReference.html
|
||||||
# https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
|
# https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
|
||||||
|
|
||||||
# WPICKY_ENABLE = Options we want to enable as-is.
|
# _picky_enable = Options we want to enable as-is.
|
||||||
# WPICKY_DETECT = Options we want to test first and enable if available.
|
# _picky_detect = Options we want to test first and enable if available.
|
||||||
|
|
||||||
# Prefer the -Wextra alias with clang.
|
# Prefer the -Wextra alias with clang.
|
||||||
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
|
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||||
set(WPICKY_ENABLE "-Wextra")
|
set(_picky_enable "-Wextra")
|
||||||
else()
|
else()
|
||||||
set(WPICKY_ENABLE "-W")
|
set(_picky_enable "-W")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
list(APPEND WPICKY_ENABLE
|
list(APPEND _picky_enable
|
||||||
-Wall -pedantic
|
-Wall -pedantic
|
||||||
)
|
)
|
||||||
|
|
||||||
# ----------------------------------
|
# ----------------------------------
|
||||||
# Add new options here, if in doubt:
|
# Add new options here, if in doubt:
|
||||||
# ----------------------------------
|
# ----------------------------------
|
||||||
set(WPICKY_DETECT
|
set(_picky_detect
|
||||||
)
|
)
|
||||||
|
|
||||||
# Assume these options always exist with both clang and gcc.
|
# Assume these options always exist with both clang and gcc.
|
||||||
# Require clang 3.0 / gcc 2.95 or later.
|
# Require clang 3.0 / gcc 2.95 or later.
|
||||||
list(APPEND WPICKY_ENABLE
|
list(APPEND _picky_enable
|
||||||
-Wbad-function-cast # clang 2.7 gcc 2.95
|
-Wbad-function-cast # clang 2.7 gcc 2.95
|
||||||
-Wconversion # clang 2.7 gcc 2.95
|
-Wconversion # clang 2.7 gcc 2.95
|
||||||
-Winline # clang 1.0 gcc 1.0
|
-Winline # clang 1.0 gcc 1.0
|
||||||
@ -89,7 +89,7 @@ if(PICKY_COMPILER)
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Always enable with clang, version dependent with gcc
|
# Always enable with clang, version dependent with gcc
|
||||||
set(WPICKY_COMMON_OLD
|
set(_picky_common_old
|
||||||
-Waddress # clang 2.7 gcc 4.3
|
-Waddress # clang 2.7 gcc 4.3
|
||||||
-Wattributes # clang 2.7 gcc 4.1
|
-Wattributes # clang 2.7 gcc 4.1
|
||||||
-Wcast-align # clang 1.0 gcc 4.2
|
-Wcast-align # clang 1.0 gcc 4.2
|
||||||
@ -118,7 +118,7 @@ if(PICKY_COMPILER)
|
|||||||
-Wvla # clang 2.8 gcc 4.3
|
-Wvla # clang 2.8 gcc 4.3
|
||||||
)
|
)
|
||||||
|
|
||||||
set(WPICKY_COMMON
|
set(_picky_common
|
||||||
-Wdouble-promotion # clang 3.6 gcc 4.6 appleclang 6.3
|
-Wdouble-promotion # clang 3.6 gcc 4.6 appleclang 6.3
|
||||||
-Wenum-conversion # clang 3.2 gcc 10.0 appleclang 4.6 g++ 11.0
|
-Wenum-conversion # clang 3.2 gcc 10.0 appleclang 4.6 g++ 11.0
|
||||||
-Wpragmas # clang 3.5 gcc 4.1 appleclang 6.0
|
-Wpragmas # clang 3.5 gcc 4.1 appleclang 6.0
|
||||||
@ -126,8 +126,8 @@ if(PICKY_COMPILER)
|
|||||||
)
|
)
|
||||||
|
|
||||||
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
|
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||||
list(APPEND WPICKY_ENABLE
|
list(APPEND _picky_enable
|
||||||
${WPICKY_COMMON_OLD}
|
${_picky_common_old}
|
||||||
-Wshift-sign-overflow # clang 2.9
|
-Wshift-sign-overflow # clang 2.9
|
||||||
-Wshorten-64-to-32 # clang 1.0
|
-Wshorten-64-to-32 # clang 1.0
|
||||||
-Wlanguage-extension-token # clang 3.0
|
-Wlanguage-extension-token # clang 3.0
|
||||||
@ -136,8 +136,8 @@ if(PICKY_COMPILER)
|
|||||||
# Enable based on compiler version
|
# Enable based on compiler version
|
||||||
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.6) OR
|
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.6) OR
|
||||||
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.3))
|
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.3))
|
||||||
list(APPEND WPICKY_ENABLE
|
list(APPEND _picky_enable
|
||||||
${WPICKY_COMMON}
|
${_picky_common}
|
||||||
-Wunreachable-code-break # clang 3.5 appleclang 6.0
|
-Wunreachable-code-break # clang 3.5 appleclang 6.0
|
||||||
-Wheader-guard # clang 3.4 appleclang 5.1
|
-Wheader-guard # clang 3.4 appleclang 5.1
|
||||||
-Wsometimes-uninitialized # clang 3.2 appleclang 4.6
|
-Wsometimes-uninitialized # clang 3.2 appleclang 4.6
|
||||||
@ -145,32 +145,32 @@ if(PICKY_COMPILER)
|
|||||||
endif()
|
endif()
|
||||||
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.9) OR
|
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.9) OR
|
||||||
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.3))
|
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.3))
|
||||||
list(APPEND WPICKY_ENABLE
|
list(APPEND _picky_enable
|
||||||
-Wcomma # clang 3.9 appleclang 8.3
|
-Wcomma # clang 3.9 appleclang 8.3
|
||||||
-Wmissing-variable-declarations # clang 3.2 appleclang 4.6
|
-Wmissing-variable-declarations # clang 3.2 appleclang 4.6
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0) OR
|
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0) OR
|
||||||
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.3))
|
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.3))
|
||||||
list(APPEND WPICKY_ENABLE
|
list(APPEND _picky_enable
|
||||||
-Wassign-enum # clang 7.0 appleclang 10.3
|
-Wassign-enum # clang 7.0 appleclang 10.3
|
||||||
-Wextra-semi-stmt # clang 7.0 appleclang 10.3
|
-Wextra-semi-stmt # clang 7.0 appleclang 10.3
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0) OR
|
if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0) OR
|
||||||
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 12.4))
|
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 12.4))
|
||||||
list(APPEND WPICKY_ENABLE
|
list(APPEND _picky_enable
|
||||||
-Wimplicit-fallthrough # clang 4.0 gcc 7.0 appleclang 12.4 # We do silencing for clang 10.0 and above only
|
-Wimplicit-fallthrough # clang 4.0 gcc 7.0 appleclang 12.4 # We do silencing for clang 10.0 and above only
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
else() # gcc
|
else() # gcc
|
||||||
list(APPEND WPICKY_DETECT
|
list(APPEND _picky_detect
|
||||||
${WPICKY_COMMON}
|
${_picky_common}
|
||||||
)
|
)
|
||||||
# Enable based on compiler version
|
# Enable based on compiler version
|
||||||
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.3)
|
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.3)
|
||||||
list(APPEND WPICKY_ENABLE
|
list(APPEND _picky_enable
|
||||||
${WPICKY_COMMON_OLD}
|
${_picky_common_old}
|
||||||
-Wclobbered # gcc 4.3
|
-Wclobbered # gcc 4.3
|
||||||
-Wmissing-parameter-type # gcc 4.3
|
-Wmissing-parameter-type # gcc 4.3
|
||||||
-Wold-style-declaration # gcc 4.3
|
-Wold-style-declaration # gcc 4.3
|
||||||
@ -179,22 +179,22 @@ if(PICKY_COMPILER)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.5 AND MINGW)
|
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.5 AND MINGW)
|
||||||
list(APPEND WPICKY_ENABLE
|
list(APPEND _picky_enable
|
||||||
-Wno-pedantic-ms-format # gcc 4.5 (MinGW-only)
|
-Wno-pedantic-ms-format # gcc 4.5 (MinGW-only)
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8)
|
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8)
|
||||||
list(APPEND WPICKY_ENABLE
|
list(APPEND _picky_enable
|
||||||
-Wformat=2 # clang 3.0 gcc 4.8
|
-Wformat=2 # clang 3.0 gcc 4.8
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0)
|
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0)
|
||||||
list(APPEND WPICKY_ENABLE
|
list(APPEND _picky_enable
|
||||||
-Warray-bounds=2 -ftree-vrp # clang 3.0 gcc 5.0 (clang default: -Warray-bounds)
|
-Warray-bounds=2 -ftree-vrp # clang 3.0 gcc 5.0 (clang default: -Warray-bounds)
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.0)
|
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.0)
|
||||||
list(APPEND WPICKY_ENABLE
|
list(APPEND _picky_enable
|
||||||
-Wduplicated-cond # gcc 6.0
|
-Wduplicated-cond # gcc 6.0
|
||||||
-Wnull-dereference # clang 3.0 gcc 6.0 (clang default)
|
-Wnull-dereference # clang 3.0 gcc 6.0 (clang default)
|
||||||
-fdelete-null-pointer-checks
|
-fdelete-null-pointer-checks
|
||||||
@ -203,7 +203,7 @@ if(PICKY_COMPILER)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0)
|
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0)
|
||||||
list(APPEND WPICKY_ENABLE
|
list(APPEND _picky_enable
|
||||||
-Walloc-zero # gcc 7.0
|
-Walloc-zero # gcc 7.0
|
||||||
-Wduplicated-branches # gcc 7.0
|
-Wduplicated-branches # gcc 7.0
|
||||||
-Wformat-truncation=2 # gcc 7.0
|
-Wformat-truncation=2 # gcc 7.0
|
||||||
@ -212,7 +212,7 @@ if(PICKY_COMPILER)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0)
|
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0)
|
||||||
list(APPEND WPICKY_ENABLE
|
list(APPEND _picky_enable
|
||||||
-Warith-conversion # gcc 10.0
|
-Warith-conversion # gcc 10.0
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
@ -220,20 +220,19 @@ if(PICKY_COMPILER)
|
|||||||
|
|
||||||
#
|
#
|
||||||
|
|
||||||
foreach(_ccopt IN LISTS WPICKY_ENABLE)
|
foreach(_ccopt IN LISTS _picky_enable)
|
||||||
list(APPEND WPICKY "${_ccopt}")
|
list(APPEND _picky "${_ccopt}")
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
foreach(_ccopt IN LISTS WPICKY_DETECT)
|
foreach(_ccopt IN LISTS _picky_detect)
|
||||||
# surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new
|
# Use a unique variable name 1. for meaningful log output 2. to have a fresh, undefined variable for each detection
|
||||||
# test result in.
|
|
||||||
string(MAKE_C_IDENTIFIER "OPT${_ccopt}" _optvarname)
|
string(MAKE_C_IDENTIFIER "OPT${_ccopt}" _optvarname)
|
||||||
# GCC only warns about unknown -Wno- options if there are also other diagnostic messages,
|
# GCC only warns about unknown -Wno- options if there are also other diagnostic messages,
|
||||||
# so test for the positive form instead
|
# so test for the positive form instead
|
||||||
string(REPLACE "-Wno-" "-W" _ccopt_on "${_ccopt}")
|
string(REPLACE "-Wno-" "-W" _ccopt_on "${_ccopt}")
|
||||||
check_c_compiler_flag(${_ccopt_on} ${_optvarname})
|
check_c_compiler_flag(${_ccopt_on} ${_optvarname})
|
||||||
if(${_optvarname})
|
if(${_optvarname})
|
||||||
list(APPEND WPICKY "${_ccopt}")
|
list(APPEND _picky "${_ccopt}")
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
@ -241,16 +240,19 @@ endif()
|
|||||||
|
|
||||||
# clang-cl
|
# clang-cl
|
||||||
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND MSVC)
|
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND MSVC)
|
||||||
# list(TRANSFORM WPICKY PREPEND "/clang:") # since CMake 3.12
|
if(CMAKE_VERSION VERSION_LESS 3.12)
|
||||||
set(_wpicky "")
|
set(_picky_tmp "")
|
||||||
foreach(_ccopt IN LISTS WPICKY)
|
foreach(_ccopt IN LISTS _picky)
|
||||||
list(APPEND _wpicky "/clang:${_ccopt}")
|
list(APPEND _picky_tmp "/clang:${_ccopt}")
|
||||||
endforeach()
|
endforeach()
|
||||||
set(WPICKY ${_wpicky})
|
set(_picky ${_picky_tmp})
|
||||||
|
else()
|
||||||
|
list(TRANSFORM _picky PREPEND "/clang:")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(WPICKY)
|
if(_picky)
|
||||||
string(REPLACE ";" " " WPICKY "${WPICKY}")
|
string(REPLACE ";" " " _picky "${_picky}")
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WPICKY}")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_picky}")
|
||||||
message(STATUS "Picky compiler options:${WPICKY}")
|
message(STATUS "Picky compiler options:${_picky}")
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user