Commit 4919d278 authored by jcfr's avatar jcfr
Browse files

COMP: Conditionally includes '-fstack-protector-all' when building with Gcc

With older version of gcc supporting the flag -fstack-protector-all,
an extra dependency to libssp.so is introduced. If gcc version is
less than 4.4.0 and the build type is Release let's not include the flag.

Doing so should allow to build Release package made for distribution using older linux distro
without introducing an extra dependency.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@15646 3bd1e089-480b-0410-8dfb-8563597acbee
parent 9c3724c7
###########################################################################
#
# Library: CTK
#
# Copyright (c) Kitware Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.commontk.org/LICENSE
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
FUNCTION(slicerFunctionGetGccVersion path_to_gcc output_var)
IF(CMAKE_COMPILER_IS_GNUCXX)
EXECUTE_PROCESS(
COMMAND ${path_to_gcc} -dumpversion
RESULT_VARIABLE result
OUTPUT_VARIABLE output
ERROR_VARIABLE error
)
IF(result)
MESSAGE(FATAL_ERROR "Failed to obtain compiler version running [${path_to_gcc} -dumpversion]: ${error}")
ENDIF()
SET(${output_var} ${output} PARENT_SCOPE)
ENDIF()
ENDFUNCTION()
......@@ -41,6 +41,7 @@ INCLUDE(CMake/SlicerMacroBuildCLI.cmake)
INCLUDE(CMake/SlicerMacroEmptyExternalProject.cmake)
INCLUDE(CMake/SlicerFunctionCheckCompilerFlags.cmake)
INCLUDE(CMake/SlicerFunctionInstallLibrary.cmake)
INCLUDE(CMake/SlicerFunctionGetGccVersion.cmake)
#-----------------------------------------------------------------------------
# Update CMake module path
......@@ -199,7 +200,14 @@ SET(Slicer_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} ${COVERAGE_CXX_FLAGS} ${ADDITIONAL
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(cflags "-Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -D_FORTIFY_SOURCE=2")
SlicerFunctionCheckCompilerFlags("-fdiagnostics-show-option" cflags)
SlicerFunctionCheckCompilerFlags("-fstack-protector-all" cflags)
slicerFunctionGetGccVersion(${CMAKE_CXX_COMPILER} GCC_VERSION)
# With older version of gcc supporting the flag -fstack-protector-all, an extra dependency to libssp.so
# is introduced. If gcc is smaller than 4.4.0 and the build type is Release let's not include the flag.
# Doing so should allow to build package made for distribution using older linux distro.
IF(${GCC_VERSION} VERSION_GREATER "4.4.0" OR (${CMAKE_BUILD_TYPE} STREQUAL "Debug" AND ${GCC_VERSION} VERSION_LESS "4.4.0"))
SlicerFunctionCheckCompilerFlags("-fstack-protector-all" cflags)
ENDIF()
IF(MINGW)
# suppress warnings about auto imported symbols
SET(Slicer_CXX_FLAGS "-Wl,--enable-auto-import ${Slicer_CXX_FLAGS}")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment