From ad11e868f08d73bf944f14fdf2edc9e79a545dc3 Mon Sep 17 00:00:00 2001 From: Thomas Orozco Date: Tue, 3 Nov 2015 16:29:00 +0100 Subject: [PATCH] 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 --- CMakeLists.txt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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")