Only define _FORTIFY_SOURCE if not built-in

Some platforms (Alpine Linux being one) define _FORTIFY_SOURCE
as a built-in. Redefining it causes a compilation error since we
treat warnings as errors.

Fixes: #22
pull/23/head
Thomas Orozco 9 years ago
parent 9bfb4a505f
commit ad11e868f0
  1. 17
      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")

Loading…
Cancel
Save