Skip to content

Commit

Permalink
Merge pull request #261 from TallFurryMan/bugfix__gentoo_gcc_fortify_…
Browse files Browse the repository at this point in the history
…source

Avoid using _FORTIFY_SOURCE on systems where compiler predefines it.
  • Loading branch information
knro committed Jun 18, 2017
2 parents cfec266 + c570ba8 commit 4b02ab9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion libindi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)

include(GNUInstallDirs)
include(FeatureSummary)
include(CheckCCompilerFlag)

if(ANDROID OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
set(ANDROID ON)
Expand All @@ -34,7 +35,16 @@ ENDIF ()

# Add security (hardening flags)
IF (UNIX OR APPLE OR ANDROID)
SET(SEC_COMP_FLAGS "-D_FORTIFY_SOURCE=2 -fstack-protector-all -fPIE")
# Older compilers are predefining _FORTIFY_SOURCE, so defining it causes a
# warning, which is then considered an error. Second issue is that for
# these compilers, _FORTIFY_SOURCE must be used while optimizing, else
# causes a warning, which also results in an error. And finally, CMake is
# not using optimization when testing for libraries, hence breaking the build.
CHECK_C_COMPILER_FLAG("-Werror -D_FORTIFY_SOURCE=2" COMPATIBLE_FORTIFY_SOURCE)
IF (${COMPATIBLE_FORTIFY_SOURCE})
SET(SEC_COMP_FLAGS "-D_FORTIFY_SOURCE=2")
ENDIF ()
SET(SEC_COMP_FLAGS "${SEC_COMP_FLAGS} -fstack-protector-all -fPIE")
# Make sure to add optimization flag. Some systems require this for _FORTIFY_SOURCE.
IF (NOT CMAKE_BUILD_TYPE MATCHES "MinSizeRel" AND NOT CMAKE_BUILD_TYPE MATCHES "Release" AND NOT CMAKE_BUILD_TYPE MATCHES "Debug")
SET(SEC_COMP_FLAGS "${SEC_COMP_FLAGS} -O1")
Expand Down

0 comments on commit 4b02ab9

Please sign in to comment.