mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-07-29 13:01:13 +03:00
cmake: Improve compiler flag detection
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user