1 # define system dependent compiler flags
3 include(CheckCCompilerFlag)
4 include(CheckCCompilerFlagSSP)
6 if (UNIX AND NOT WIN32)
8 # Define GNUCC compiler flags
10 if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)")
13 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pedantic -pedantic-errors")
14 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wshadow -Wmissing-prototypes -Wdeclaration-after-statement")
15 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused -Wfloat-equal -Wpointer-arith -Wwrite-strings -Wformat-security")
16 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-format-attribute")
19 check_c_compiler_flag("-fPIC" WITH_FPIC)
21 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
24 check_c_compiler_flag_ssp("-fstack-protector" WITH_STACK_PROTECTOR)
25 if (WITH_STACK_PROTECTOR)
26 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
27 endif (WITH_STACK_PROTECTOR)
30 string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
31 if (CMAKE_BUILD_TYPE_LOWER MATCHES (release|relwithdebinfo|minsizerel))
32 check_c_compiler_flag("-Wp,-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE)
33 if (WITH_FORTIFY_SOURCE)
34 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wp,-D_FORTIFY_SOURCE=2")
35 endif (WITH_FORTIFY_SOURCE)
38 endif (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)")
41 # Check for large filesystem support
43 if (CMAKE_SIZEOF_VOID_P MATCHES "8")
44 # with large file support
51 OUTPUT_STRIP_TRAILING_WHITESPACE
53 else (CMAKE_SIZEOF_VOID_P MATCHES "8")
54 # with large file support
61 OUTPUT_STRIP_TRAILING_WHITESPACE
63 endif (CMAKE_SIZEOF_VOID_P MATCHES "8")
65 string(REGEX REPLACE "[\r\n]" " " "${_lfs_CFLAGS}" "${${_lfs_CFLAGS}}")
66 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_lfs_CFLAGS}")
69 endif (UNIX AND NOT WIN32)
72 # Use secure functions by defaualt and suppress warnings about
73 #"deprecated" functions
74 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1")
75 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1")
76 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_NONSTDC_NO_WARNINGS=1 /D _CRT_SECURE_NO_WARNINGS=1")