|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
include(CheckCCompilerFlag) |
|
|
|
|
|
unset(_picky) |
|
|
|
|
|
if(CURL_WERROR AND |
|
|
((CMAKE_COMPILER_IS_GNUCC AND |
|
|
NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0 AND |
|
|
NOT CMAKE_VERSION VERSION_LESS 3.23.0) OR |
|
|
CMAKE_C_COMPILER_ID MATCHES "Clang")) |
|
|
list(APPEND _picky "-pedantic-errors") |
|
|
if(MSVC) |
|
|
list(APPEND _picky "-Wno-language-extension-token") |
|
|
endif() |
|
|
endif() |
|
|
|
|
|
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 "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.3)) |
|
|
list(APPEND _picky "-Werror=partial-availability") |
|
|
endif() |
|
|
|
|
|
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") |
|
|
list(APPEND _picky "-Werror-implicit-function-declaration") |
|
|
endif() |
|
|
|
|
|
if(PICKY_COMPILER) |
|
|
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(CMAKE_C_COMPILER_ID MATCHES "Clang") |
|
|
set(_picky_enable "-Wextra") |
|
|
else() |
|
|
set(_picky_enable "-W") |
|
|
endif() |
|
|
|
|
|
list(APPEND _picky_enable |
|
|
-Wall -pedantic |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set(_picky_detect |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
list(APPEND _picky_enable |
|
|
-Wbad-function-cast |
|
|
-Wconversion |
|
|
-Winline |
|
|
-Wmissing-declarations |
|
|
-Wmissing-prototypes |
|
|
-Wnested-externs |
|
|
-Wno-long-long |
|
|
-Wno-multichar |
|
|
-Wpointer-arith |
|
|
-Wshadow |
|
|
-Wsign-compare |
|
|
-Wundef |
|
|
-Wunused |
|
|
-Wwrite-strings |
|
|
) |
|
|
|
|
|
|
|
|
set(_picky_common_old |
|
|
-Waddress |
|
|
-Wattributes |
|
|
-Wcast-align |
|
|
-Wdeclaration-after-statement |
|
|
-Wdiv-by-zero |
|
|
-Wempty-body |
|
|
-Wendif-labels |
|
|
-Wfloat-equal |
|
|
-Wformat-security |
|
|
-Wignored-qualifiers |
|
|
-Wmissing-field-initializers |
|
|
-Wmissing-noreturn |
|
|
-Wno-format-nonliteral |
|
|
-Wno-system-headers |
|
|
|
|
|
-Wold-style-definition |
|
|
-Wredundant-decls |
|
|
-Wsign-conversion |
|
|
-Wno-error=sign-conversion |
|
|
-Wstrict-prototypes |
|
|
|
|
|
-Wtype-limits |
|
|
-Wunreachable-code |
|
|
|
|
|
-Wunused-parameter |
|
|
-Wvla |
|
|
) |
|
|
|
|
|
set(_picky_common |
|
|
-Wdouble-promotion |
|
|
-Wenum-conversion |
|
|
-Wpragmas |
|
|
-Wunused-const-variable |
|
|
) |
|
|
|
|
|
if(CMAKE_C_COMPILER_ID MATCHES "Clang") |
|
|
list(APPEND _picky_enable |
|
|
${_picky_common_old} |
|
|
-Wshift-sign-overflow |
|
|
-Wshorten-64-to-32 |
|
|
-Wformat=2 |
|
|
) |
|
|
if(NOT MSVC) |
|
|
list(APPEND _picky_enable |
|
|
-Wlanguage-extension-token |
|
|
) |
|
|
endif() |
|
|
|
|
|
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)) |
|
|
list(APPEND _picky_enable |
|
|
${_picky_common} |
|
|
|
|
|
-Wheader-guard |
|
|
-Wsometimes-uninitialized |
|
|
) |
|
|
endif() |
|
|
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)) |
|
|
list(APPEND _picky_enable |
|
|
-Wcomma |
|
|
-Wmissing-variable-declarations |
|
|
) |
|
|
endif() |
|
|
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)) |
|
|
list(APPEND _picky_enable |
|
|
-Wassign-enum |
|
|
-Wextra-semi-stmt |
|
|
) |
|
|
endif() |
|
|
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)) |
|
|
list(APPEND _picky_enable |
|
|
-Wimplicit-fallthrough |
|
|
) |
|
|
endif() |
|
|
else() |
|
|
list(APPEND _picky_detect |
|
|
${_picky_common} |
|
|
) |
|
|
|
|
|
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.3) |
|
|
list(APPEND _picky_enable |
|
|
${_picky_common_old} |
|
|
-Wclobbered |
|
|
-Wmissing-parameter-type |
|
|
-Wold-style-declaration |
|
|
-Wstrict-aliasing=3 |
|
|
-Wtrampolines |
|
|
) |
|
|
endif() |
|
|
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.5 AND MINGW) |
|
|
list(APPEND _picky_enable |
|
|
-Wno-pedantic-ms-format |
|
|
) |
|
|
endif() |
|
|
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8) |
|
|
list(APPEND _picky_enable |
|
|
-Wformat=2 |
|
|
) |
|
|
endif() |
|
|
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0) |
|
|
list(APPEND _picky_enable |
|
|
-Warray-bounds=2 -ftree-vrp |
|
|
) |
|
|
endif() |
|
|
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.0) |
|
|
list(APPEND _picky_enable |
|
|
-Wduplicated-cond |
|
|
-Wnull-dereference |
|
|
-fdelete-null-pointer-checks |
|
|
-Wshift-negative-value |
|
|
-Wshift-overflow=2 |
|
|
) |
|
|
endif() |
|
|
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0) |
|
|
list(APPEND _picky_enable |
|
|
-Walloc-zero |
|
|
-Wduplicated-branches |
|
|
-Wformat-truncation=2 |
|
|
-Wimplicit-fallthrough |
|
|
-Wrestrict |
|
|
) |
|
|
endif() |
|
|
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0) |
|
|
list(APPEND _picky_enable |
|
|
-Warith-conversion |
|
|
) |
|
|
endif() |
|
|
endif() |
|
|
|
|
|
|
|
|
|
|
|
foreach(_ccopt IN LISTS _picky_enable) |
|
|
list(APPEND _picky "${_ccopt}") |
|
|
endforeach() |
|
|
|
|
|
foreach(_ccopt IN LISTS _picky_detect) |
|
|
|
|
|
string(MAKE_C_IDENTIFIER "OPT${_ccopt}" _optvarname) |
|
|
|
|
|
|
|
|
string(REPLACE "-Wno-" "-W" _ccopt_on "${_ccopt}") |
|
|
check_c_compiler_flag(${_ccopt_on} ${_optvarname}) |
|
|
if(${_optvarname}) |
|
|
list(APPEND _picky "${_ccopt}") |
|
|
endif() |
|
|
endforeach() |
|
|
endif() |
|
|
endif() |
|
|
|
|
|
|
|
|
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND MSVC) |
|
|
if(CMAKE_VERSION VERSION_LESS 3.12) |
|
|
set(_picky_tmp "") |
|
|
foreach(_ccopt IN LISTS _picky) |
|
|
list(APPEND _picky_tmp "/clang:${_ccopt}") |
|
|
endforeach() |
|
|
set(_picky ${_picky_tmp}) |
|
|
else() |
|
|
list(TRANSFORM _picky PREPEND "/clang:") |
|
|
endif() |
|
|
endif() |
|
|
|
|
|
if(_picky) |
|
|
string(REPLACE ";" " " _picky "${_picky}") |
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_picky}") |
|
|
message(STATUS "Picky compiler options: ${_picky}") |
|
|
endif() |
|
|
|