From 6fa545cc18904962cf523a23cb384ce47a049e8b Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 5 Jul 2022 13:03:55 +0200 Subject: [PATCH] Only set _FORTIFY_SOURCE when a higher level of this flag has not been set Signed-off-by: Claudio Cambra --- cmake/modules/DefineCompilerFlags.cmake | 2 +- src/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/modules/DefineCompilerFlags.cmake b/cmake/modules/DefineCompilerFlags.cmake index b38c85569c811..22b4ce2036062 100644 --- a/cmake/modules/DefineCompilerFlags.cmake +++ b/cmake/modules/DefineCompilerFlags.cmake @@ -47,7 +47,7 @@ if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)") if (CMAKE_BUILD_TYPE) string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) - if (CMAKE_BUILD_TYPE_LOWER MATCHES "(release|relwithdebinfo|minsizerel)") + if (CMAKE_BUILD_TYPE_LOWER MATCHES "(release|relwithdebinfo|minsizerel)" AND (NOT ${_FORTIFY_SOURCE} GREATER 2)) check_c_compiler_flag("-Wp,-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE) if (WITH_FORTIFY_SOURCE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wp,-D_FORTIFY_SOURCE=2") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0c051c9a46d01..abecf82aefaf2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,7 +31,7 @@ if(NOT MSVC) endif() string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) - if(CMAKE_BUILD_TYPE_LOWER MATCHES "(release|relwithdebinfo|minsizerel)") + if(CMAKE_BUILD_TYPE_LOWER MATCHES "(release|relwithdebinfo|minsizerel)" AND (NOT ${_FORTIFY_SOURCE} GREATER 2)) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORTIFY_SOURCE=2") endif()