diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2018-08-24 07:43:04 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2018-08-24 07:51:00 +0200 |
commit | a97e227a9dc6f4bc62ac9b7045b6f9bc64537932 (patch) | |
tree | 6b09bd74442feb9bb05ef0730e49195c98734d05 | |
parent | 119a457357bbf225c032dd559dc098449e4fcdf7 (diff) | |
download | libssh-a97e227a9dc6f4bc62ac9b7045b6f9bc64537932.tar.gz libssh-a97e227a9dc6f4bc62ac9b7045b6f9bc64537932.tar.xz libssh-a97e227a9dc6f4bc62ac9b7045b6f9bc64537932.zip |
cmake: Improve compiler flag detection
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r-- | CompilerChecks.cmake | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/CompilerChecks.cmake b/CompilerChecks.cmake index 57afba81..f8a7af14 100644 --- a/CompilerChecks.cmake +++ b/CompilerChecks.cmake @@ -2,6 +2,20 @@ include(AddCCompilerFlag) include(CheckCCompilerFlagSSP) if (UNIX) + # + # Check for -Werror turned on if possible + # + # This will prevent that compiler flags are detected incorrectly. + # + check_c_compiler_flag("-Werror" REQUIRED_FLAGS_WERROR) + if (REQUIRED_FLAGS_WERROR) + set(CMAKE_REQUIRED_FLAGS "-Werror") + + if (PICKY_DEVELOPER) + list(APPEND SUPPORTED_COMPILER_FLAGS "-Werror") + endif() + endif() + add_c_compiler_flag("-std=gnu99" SUPPORTED_COMPILER_FLAGS) add_c_compiler_flag("-pedantic" SUPPORTED_COMPILER_FLAGS) add_c_compiler_flag("-pedantic-errors" SUPPORTED_COMPILER_FLAGS) @@ -28,28 +42,20 @@ if (UNIX) add_c_compiler_flag("-Werror=strict-overflow" SUPPORTED_COMPILER_FLAGS) add_c_compiler_flag("-Wstrict-overflow=2" SUPPORTED_COMPILER_FLAGS) add_c_compiler_flag("-Wno-format-zero-length" SUPPORTED_COMPILER_FLAGS) + + check_c_compiler_flag("-Wformat" REQUIRED_FLAGS_WFORMAT) + if (REQUIRED_FLAGS_WFORMAT) + list(APPEND SUPPORTED_COMPILER_FLAGS "-Wformat") + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wformat") + endif() add_c_compiler_flag("-Wformat-security" SUPPORTED_COMPILER_FLAGS) add_c_compiler_flag("-Werror=format-security" SUPPORTED_COMPILER_FLAGS) - # - # Check for -f options with -Werror turned on if possible - # - # This will prevent that compiler flags are detected incorrectly. - # - check_c_compiler_flag("-Werror" REQUIRED_FLAGS_WERROR) - if (REQUIRED_FLAGS_WERROR) - set(CMAKE_REQUIRED_FLAGS "-Werror") - endif() + # Allow zero for a variadic macro argument + add_c_compiler_flag("-Wno-gnu-zero-variadic-macro-arguments" SUPPORTED_COMPILER_FLAGS) add_c_compiler_flag("-fno-common" SUPPORTED_COMPILER_FLAGS) - check_c_compiler_flag_ssp("-fstack-protector" WITH_STACK_PROTECTOR) - if (WITH_STACK_PROTECTOR) - list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-protector") - endif() - unset(CMAKE_REQUIRED_FLAGS) - - if (CMAKE_BUILD_TYPE) string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) if (CMAKE_BUILD_TYPE_LOWER MATCHES (release|relwithdebinfo|minsizerel)) @@ -57,14 +63,18 @@ if (UNIX) endif() endif() + check_c_compiler_flag_ssp("-fstack-protector" WITH_STACK_PROTECTOR) + if (WITH_STACK_PROTECTOR) + list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-protector") + endif() + if (PICKY_DEVELOPER) - add_c_compiler_flag("-Werror" SUPPORTED_COMPILER_FLAGS) add_c_compiler_flag("-Wno-error=deprecated-declarations" SUPPORTED_COMPILER_FLAGS) add_c_compiler_flag("-Wno-error=tautological-compare" SUPPORTED_COMPILER_FLAGS) endif() - # Allow zero for a variadic macro argument - add_c_compiler_flag("-Wno-gnu-zero-variadic-macro-arguments" SUPPORTED_COMPILER_FLAGS) + # Unset CMAKE_REQUIRED_FLAGS + unset(CMAKE_REQUIRED_FLAGS) endif() if (MSVC) |