diff --git a/CMakeLists.txt b/CMakeLists.txt index 0eaf532..a4d8d82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,22 @@ else() endif() # Flags -add_definitions (-D_FORTIFY_SOURCE=2) +include(CheckCSourceCompiles) + +check_c_source_compiles(" +#ifndef _FORTIFY_SOURCE +#error \"Not defined: _FORTIFY_SOURCE\" +#endif +int main(void) { + return 0; +} +" HAS_BUILTIN_FORTIFY) + +# Flags +if(NOT HAS_BUILTIN_FORTIFY) + add_definitions(-D_FORTIFY_SOURCE=2) +endif() + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Werror -Wextra -Wall -pedantic-errors -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat") set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-s")