|
| 1 | +include(AddCCompilerFlag) |
| 2 | +include(CheckCCompilerFlagSSP) |
| 3 | + |
| 4 | +if (UNIX) |
| 5 | + # |
| 6 | + # Check for -Werror turned on if possible |
| 7 | + # |
| 8 | + # This will prevent that compiler flags are detected incorrectly. |
| 9 | + # |
| 10 | + check_c_compiler_flag("-Werror" REQUIRED_FLAGS_WERROR) |
| 11 | + if (REQUIRED_FLAGS_WERROR) |
| 12 | + set(CMAKE_REQUIRED_FLAGS "-Werror") |
| 13 | + |
| 14 | + if (PICKY_DEVELOPER) |
| 15 | + list(APPEND SUPPORTED_COMPILER_FLAGS "-Werror") |
| 16 | + endif() |
| 17 | + endif() |
| 18 | + |
| 19 | + add_c_compiler_flag("-std=gnu99" SUPPORTED_COMPILER_FLAGS) |
| 20 | + add_c_compiler_flag("-pedantic" SUPPORTED_COMPILER_FLAGS) |
| 21 | + add_c_compiler_flag("-pedantic-errors" SUPPORTED_COMPILER_FLAGS) |
| 22 | + add_c_compiler_flag("-Wall" SUPPORTED_COMPILER_FLAGS) |
| 23 | + add_c_compiler_flag("-Wshadow" SUPPORTED_COMPILER_FLAGS) |
| 24 | + add_c_compiler_flag("-Wmissing-prototypes" SUPPORTED_COMPILER_FLAGS) |
| 25 | + add_c_compiler_flag("-Wcast-align" SUPPORTED_COMPILER_FLAGS) |
| 26 | + #add_c_compiler_flag("-Wcast-qual" SUPPORTED_COMPILER_FLAGS) |
| 27 | + add_c_compiler_flag("-Werror=address" SUPPORTED_COMPILER_FLAGS) |
| 28 | + add_c_compiler_flag("-Wstrict-prototypes" SUPPORTED_COMPILER_FLAGS) |
| 29 | + add_c_compiler_flag("-Werror=strict-prototypes" SUPPORTED_COMPILER_FLAGS) |
| 30 | + add_c_compiler_flag("-Wwrite-strings" SUPPORTED_COMPILER_FLAGS) |
| 31 | + add_c_compiler_flag("-Werror=write-strings" SUPPORTED_COMPILER_FLAGS) |
| 32 | + add_c_compiler_flag("-Werror-implicit-function-declaration" SUPPORTED_COMPILER_FLAGS) |
| 33 | + add_c_compiler_flag("-Wpointer-arith" SUPPORTED_COMPILER_FLAGS) |
| 34 | + add_c_compiler_flag("-Werror=pointer-arith" SUPPORTED_COMPILER_FLAGS) |
| 35 | + add_c_compiler_flag("-Wdeclaration-after-statement" SUPPORTED_COMPILER_FLAGS) |
| 36 | + add_c_compiler_flag("-Werror=declaration-after-statement" SUPPORTED_COMPILER_FLAGS) |
| 37 | + add_c_compiler_flag("-Wreturn-type" SUPPORTED_COMPILER_FLAGS) |
| 38 | + add_c_compiler_flag("-Werror=return-type" SUPPORTED_COMPILER_FLAGS) |
| 39 | + add_c_compiler_flag("-Wuninitialized" SUPPORTED_COMPILER_FLAGS) |
| 40 | + add_c_compiler_flag("-Werror=uninitialized" SUPPORTED_COMPILER_FLAGS) |
| 41 | + add_c_compiler_flag("-Wimplicit-fallthrough" SUPPORTED_COMPILER_FLAGS) |
| 42 | + add_c_compiler_flag("-Werror=strict-overflow" SUPPORTED_COMPILER_FLAGS) |
| 43 | + add_c_compiler_flag("-Wstrict-overflow=2" SUPPORTED_COMPILER_FLAGS) |
| 44 | + add_c_compiler_flag("-Wno-format-zero-length" SUPPORTED_COMPILER_FLAGS) |
| 45 | + |
| 46 | + check_c_compiler_flag("-Wformat" REQUIRED_FLAGS_WFORMAT) |
| 47 | + if (REQUIRED_FLAGS_WFORMAT) |
| 48 | + list(APPEND SUPPORTED_COMPILER_FLAGS "-Wformat") |
| 49 | + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wformat") |
| 50 | + endif() |
| 51 | + add_c_compiler_flag("-Wformat-security" SUPPORTED_COMPILER_FLAGS) |
| 52 | + add_c_compiler_flag("-Werror=format-security" SUPPORTED_COMPILER_FLAGS) |
| 53 | + |
| 54 | + # Allow zero for a variadic macro argument |
| 55 | + add_c_compiler_flag("-Wno-gnu-zero-variadic-macro-arguments" SUPPORTED_COMPILER_FLAGS) |
| 56 | + |
| 57 | + add_c_compiler_flag("-fno-common" SUPPORTED_COMPILER_FLAGS) |
| 58 | + |
| 59 | + if (CMAKE_BUILD_TYPE) |
| 60 | + string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) |
| 61 | + if (CMAKE_BUILD_TYPE_LOWER MATCHES (release|relwithdebinfo|minsizerel)) |
| 62 | + add_c_compiler_flag("-Wp,-D_FORTIFY_SOURCE=2" SUPPORTED_COMPILER_FLAGS) |
| 63 | + endif() |
| 64 | + endif() |
| 65 | + |
| 66 | + check_c_compiler_flag_ssp("-fstack-protector" WITH_STACK_PROTECTOR) |
| 67 | + if (WITH_STACK_PROTECTOR) |
| 68 | + list(APPEND SUPPORTED_COMPILER_FLAGS "-fstack-protector") |
| 69 | + endif() |
| 70 | + |
| 71 | + if (PICKY_DEVELOPER) |
| 72 | + add_c_compiler_flag("-Wno-error=deprecated-declarations" SUPPORTED_COMPILER_FLAGS) |
| 73 | + add_c_compiler_flag("-Wno-error=tautological-compare" SUPPORTED_COMPILER_FLAGS) |
| 74 | + endif() |
| 75 | + |
| 76 | + # Unset CMAKE_REQUIRED_FLAGS |
| 77 | + unset(CMAKE_REQUIRED_FLAGS) |
| 78 | +endif() |
| 79 | + |
| 80 | +if (MSVC) |
| 81 | + add_c_compiler_flag("/D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1" SUPPORTED_COMPILER_FLAGS) |
| 82 | + add_c_compiler_flag("/D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1" SUPPORTED_COMPILER_FLAGS) |
| 83 | + add_c_compiler_flag("/D _CRT_NONSTDC_NO_WARNINGS=1" SUPPORTED_COMPILER_FLAGS) |
| 84 | + add_c_compiler_flag("/D _CRT_SECURE_NO_WARNINGS=1" SUPPORTED_COMPILER_FLAGS) |
| 85 | +endif() |
| 86 | + |
| 87 | +# This removes this annoying warning |
| 88 | +# "warning: 'BN_CTX_free' is deprecated: first deprecated in OS X 10.7 [-Wdeprecated-declarations]" |
| 89 | +if (OSX) |
| 90 | + add_c_compiler_flag("-Wno-deprecated-declarations" SUPPORTED_COMPILER_FLAGS) |
| 91 | +endif() |
| 92 | + |
| 93 | +set(DEFAULT_C_COMPILE_FLAGS ${SUPPORTED_COMPILER_FLAGS} CACHE INTERNAL "Default C Compiler Flags" FORCE) |
0 commit comments