summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorNotTsunami <4589807+NotTsunami@users.noreply.github.com>2021-07-12 13:46:56 -0400
committerMartijn van Beurden <mvanb1@gmail.com>2022-04-13 17:37:50 +0200
commit617efda90d046377bb911fb4f30e4f5445b7d781 (patch)
tree98474d25d13711b0a0c59059b989efe722b247e6 /CMakeLists.txt
parentf5efd956d90cb8fce5f1a02d804ebb2150052c84 (diff)
downloadflac-617efda90d046377bb911fb4f30e4f5445b7d781.tar.gz
CMake: Make FORTIFY_SOURCE optional
* Also add in checking for libssp for MinGW
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt18
1 files changed, 17 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 24d22d27..c8bc8174 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,6 +17,7 @@ option(BUILD_PROGRAMS "Build and install programs" ON)
option(BUILD_EXAMPLES "Build and install examples" ON)
option(BUILD_TESTING "Build tests" ON)
option(BUILD_DOCS "Build and install doxygen documents" ON)
+option(WITH_FORTIFY_SOURCE "Enable protection against buffer overflows" ON)
option(WITH_STACK_PROTECTOR "Enable GNU GCC stack smash protection" ON)
option(INSTALL_MANPAGES "Install MAN pages" ON)
option(INSTALL_PKGCONFIG_MODULES "Install PkgConfig modules" ON)
@@ -78,6 +79,15 @@ check_c_compiler_flag(-Wdeclaration-after-statement HAVE_DECL_AFTER_STMT_FLAG)
check_c_compiler_flag(-mstackrealign HAVE_STACKREALIGN_FLAG)
check_cxx_compiler_flag(-Weffc++ HAVE_WEFFCXX_FLAG)
+if(MINGW AND (WITH_FORTIFY_SOURCE OR WITH_STACK_PROTECTOR))
+ check_library_exists(ssp __stack_chk_fail "" HAVE_LIBSSP)
+ if(NOT HAVE_LIBSSP)
+ message(WARNING "Could not find libssp in MinGW, stack protection and/or FORTIFY_SOURCE are unavailable")
+ endif()
+elseif(NOT MSVC)
+ set(HAVE_LIBSSP 1)
+endif()
+
if(WITH_STACK_PROTECTOR)
if(NOT MSVC)
check_c_compiler_flag("-fstack-protector-strong" HAVE_STACK_PROTECTOR_FLAG)
@@ -95,7 +105,13 @@ add_compile_options(
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<BOOL:${HAVE_WEFFCXX_FLAG}>>:-Weffc++>
$<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:${HAVE_DECL_AFTER_STMT_FLAG}>>:-Wdeclaration-after-statement>)
-if(HAVE_STACK_PROTECTOR_FLAG)
+if(HAVE_LIBSSP) # Implies WITH_FORTIFY_SOURCE
+ add_definitions(-D_FORTIFY_SOURCE=2)
+else(WITH_FORTIFY_SOURCE)
+ add_definitions(-D_FORTIFY_SOURCE=1)
+endif()
+
+if(HAVE_STACK_PROTECTOR_FLAG AND HAVE_LIBSSP)
add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-fstack-protector-strong>)
endif()