From bcd75a538ec459285ffa538498ed36a7b41a8d44 Mon Sep 17 00:00:00 2001 From: Nicky Date: Mon, 16 Jan 2017 15:54:24 +0100 Subject: [PATCH] Workaround for distributions who already define _FORTIFY_SOURCE by default (eg Gentoo) and do not redefine it then. --- indra/cmake/00-Common.cmake | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/indra/cmake/00-Common.cmake b/indra/cmake/00-Common.cmake index 89c34fa114..edc4b3286a 100644 --- a/indra/cmake/00-Common.cmake +++ b/indra/cmake/00-Common.cmake @@ -105,7 +105,22 @@ endif (WINDOWS) if (LINUX) set(CMAKE_SKIP_RPATH TRUE) - add_definitions(-D_FORTIFY_SOURCE=2) + # + # And another hack for FORTIFY_SOURCE. Some distributions (for example Gentoo) define FORTIFY_SOURCE by default. + # Check if this is the case, if yes, do not define it again. + + execute_process( + COMMAND echo "int main( char **a, int c ){ \n#ifdef _FORTIFY_SOURCE\n#error FORTITY_SOURCE_SET\n#else\nreturn 0;\n#endif\n}" + COMMAND sh -c "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -xc++ -w - -o /dev/null" + OUTPUT_VARIABLE FORTIFY_SOURCE_OUT + ERROR_VARIABLE FORTIFY_SOURCE_ERR + RESULT_VARIABLE FORTIFY_SOURCE_RES + ) + + + if ( ${FORTIFY_SOURCE_RES} EQUAL 0 ) + add_definitions(-D_FORTIFY_SOURCE=2) + endif() set(CMAKE_CXX_FLAGS "-Wno-deprecated -Wno-unused-but-set-variable -Wno-unused-variable ${CMAKE_CXX_FLAGS}")