aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Reed <m.reed@mykolab.com>2015-08-26 18:00:33 -0400
committerMichael Reed <m.reed@mykolab.com>2015-08-26 18:05:38 -0400
commit2b4cbbebf478dd949b45f23996c7dd713ee562f3 (patch)
tree4e1906cd46097a721ce76c30c9d4766dad35007b
parentb2ece148e6f16f50b45fc2af55ef5b8202e810ee (diff)
downloadrneovim-2b4cbbebf478dd949b45f23996c7dd713ee562f3.tar.gz
rneovim-2b4cbbebf478dd949b45f23996c7dd713ee562f3.tar.bz2
rneovim-2b4cbbebf478dd949b45f23996c7dd713ee562f3.zip
cmake: Build with -fstack-protector-strong if available #2597
If not available, fall back to -fstack-protector + --param=ssp-buffer-size=4 If that isn't available, do nothing. See the following articles for more information: https://lwn.net/Articles/584225/ https://outflux.net/blog/archives/2014/01/27/fstack-protector-strong/
-rw-r--r--CMakeLists.txt15
1 files changed, 12 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b2e19c6d6f..3334f14cca 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -101,7 +101,7 @@ if(NOT HAS_ACCEPTABLE_FORTIFY)
# Extract possible prefix to _FORTIFY_SOURCE (e.g. -Wp,-D_FORTIFY_SOURCE).
STRING(REGEX MATCH "[^\ ]+-D_FORTIFY_SOURCE" _FORTIFY_SOURCE_PREFIX "${CMAKE_C_FLAGS}")
STRING(REPLACE "-D_FORTIFY_SOURCE" "" _FORTIFY_SOURCE_PREFIX "${_FORTIFY_SOURCE_PREFIX}" )
- if (NOT _FORTIFY_SOURCE_PREFIX STREQUAL "")
+ if(NOT _FORTIFY_SOURCE_PREFIX STREQUAL "")
message(STATUS "Detected _FORTIFY_SOURCE Prefix=${_FORTIFY_SOURCE_PREFIX}.")
endif()
# -U in add_definitions doesn't end up in the correct spot, so we add it to
@@ -112,11 +112,21 @@ endif()
add_definitions(-Wall -Wextra -pedantic -Wno-unused-parameter
-Wstrict-prototypes -std=gnu99)
-if (MINGW)
+if(MINGW)
# Use POSIX compatible stdio in Mingw
add_definitions(-D__USE_MINGW_ANSI_STDIO)
endif()
+include(CheckCCompilerFlag)
+check_c_compiler_flag(-fstack-protector-strong HAS_FSTACK_PROTECTOR_STRONG_FLAG)
+check_c_compiler_flag(-fstack-protector HAS_FSTACK_PROTECTOR_FLAG)
+
+if(HAS_FSTACK_PROTECTOR_STRONG_FLAG)
+ add_definitions(-fstack-protector-strong)
+elseif(HAS_FSTACK_PROTECTOR_FLAG)
+ add_definitions(-fstack-protector --param ssp-buffer-size=4)
+endif()
+
option(
TRAVIS_CI_BUILD "Travis CI build. Extra compilation flags will be set." OFF)
@@ -126,7 +136,6 @@ if(TRAVIS_CI_BUILD)
endif()
if(CMAKE_COMPILER_IS_GNUCC)
- include(CheckCCompilerFlag)
check_c_compiler_flag(-Og HAS_OG_FLAG)
else()
set(HAS_OG_FLAG 0)