Commit a4880cee authored by jcfr's avatar jcfr

COMP: Factor out code related to C/CXX flags to that it could be re-used within extension

git-svn-id: http://svn.slicer.org/Slicer4/trunk@16373 3bd1e089-480b-0410-8dfb-8563597acbee
parent c1f56bc9
################################################################################
#
# Program: 3D Slicer
#
# Copyright (c) 2010 Kitware Inc.
#
# See Doc/copyright/copyright.txt
# or http://www.slicer.org/copyright/copyright.txt for details.
#
# 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.
#
# This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
# and was partially funded by NIH grant 3P41RR013218-12S1
#
################################################################################
#
# Coverage flags
#
#
# Usage: If WITH_COVERAGE variable is True, the flags required to compute code coverage
# will be set into COVERAGE_CXX_FLAGS and COVERAGE_C_FLAGS variables.
#
IF(WITH_COVERAGE)
IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET(coverage_flags "-g -fprofile-arcs -ftest-coverage -O0 -DNDEBUG")
SET(COVERAGE_CXX_FLAGS ${coverage_flags})
SET(COVERAGE_C_FLAGS ${coverage_flags})
ENDIF()
ENDIF()
################################################################################
#
# Program: 3D Slicer
#
# Copyright (c) 2010 Kitware Inc.
#
# See Doc/copyright/copyright.txt
# or http://www.slicer.org/copyright/copyright.txt for details.
#
# 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.
#
# This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
# and was partially funded by NIH grant 3P41RR013218-12S1
#
################################################################################
#
# Required C/CXX flags
#
#
# Usage: The variable Slicer_REQUIRED_C_FLAGS and Slicer_REQUIRED_CXX_FLAGS
# will set appropriately.
#
IF(NOT DEFINED Slicer_REQUIRED_C_FLAGS} OR NOT DEFINED Slicer_REQUIRED_CXX_FLAGS)
INCLUDE(SlicerFunctionCheckCompilerFlags)
INCLUDE(SlicerFunctionGetGccVersion)
SET(tmp_c_flags)
SET(tmp_cxx_flags)
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("-Wl,--no-undefined" 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(tmp_cxx_flags "-Wl,--enable-auto-import ${tmp_cxx_flags}")
ENDIF()
# Note: -Wold-style-cast is too verbose
# Let's postpone the use of -Wsign-promo
SET(tmp_c_flags "${cflags} ${tmp_c_flags}")
SET(tmp_cxx_flags "${cflags} -Wno-deprecated -Woverloaded-virtual -Wstrict-null-sentinel ${tmp_cxx_flags}")
ELSEIF(MSVC)
SET(cflags "/Zm1000 /W3")
SET(tmp_c_flags "${cflags} ${tmp_c_flags}")
SET(tmp_cxx_flags "${cflags} /EHsc /GR ${tmp_cxx_flags}")
ENDIF()
SET(Slicer_REQUIRED_C_FLAGS ${tmp_c_flags})
SET(Slicer_REQUIRED_CXX_FLAGS ${tmp_cxx_flags})
ENDIF()
......@@ -41,9 +41,7 @@ INCLUDE(Slicer3PluginsMacros)
INCLUDE(SlicerMacroParseArguments)
INCLUDE(SlicerMacroBuildCLI)
INCLUDE(SlicerMacroEmptyExternalProject)
INCLUDE(SlicerFunctionCheckCompilerFlags)
INCLUDE(SlicerFunctionInstallLibrary)
INCLUDE(SlicerFunctionGetGccVersion)
#-----------------------------------------------------------------------------
# Platform checks
......@@ -181,48 +179,9 @@ SET(ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags")
MARK_AS_ADVANCED(ADDITIONAL_CXX_FLAGS)
#-----------------------------------------------------------------------------
# Set coverage Flags
# Set Slicer_{C,CXX}_REQUIRED_FLAGS variables
#-----------------------------------------------------------------------------
IF(WITH_COVERAGE)
IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET(coverage_flags "-g -fprofile-arcs -ftest-coverage -O0 -DNDEBUG")
SET(COVERAGE_CXX_FLAGS ${coverage_flags})
SET(COVERAGE_C_FLAGS ${coverage_flags})
ENDIF()
ENDIF()
#-----------------------------------------------------------------------------
# Slicer C/CXX Flags
#-----------------------------------------------------------------------------
SET(Slicer_C_FLAGS "${CMAKE_C_FLAGS_INIT} ${COVERAGE_C_FLAGS} ${ADDITIONAL_C_FLAGS}")
SET(Slicer_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} ${COVERAGE_CXX_FLAGS} ${ADDITIONAL_CXX_FLAGS}")
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("-Wl,--no-undefined" 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}")
ENDIF()
# Note: -Wold-style-cast is too verbose
# Let's postpone the use of -Wsign-promo
SET(Slicer_C_FLAGS "${cflags} ${Slicer_C_FLAGS}")
SET(Slicer_CXX_FLAGS "${cflags} -Wno-deprecated -Woverloaded-virtual -Wstrict-null-sentinel ${Slicer_CXX_FLAGS}")
ELSEIF(MSVC)
SET(cflags "/Zm1000 /W3")
SET(Slicer_C_FLAGS "${cflags} ${Slicer_C_FLAGS}")
SET(Slicer_CXX_FLAGS "${cflags} /EHsc /GR ${Slicer_CXX_FLAGS}")
ENDIF()
INCLUDE(SlicerBlockCXXRequiredFlags)
#-----------------------------------------------------------------------------
# Slicer install directories
......@@ -295,39 +254,6 @@ SET(Slicer_INSTALL_PLUGINS_CACHE_DIR "${Slicer_INSTALL_LIB_DIR}/PluginsCache")
SET(Slicer_HOME "${Slicer_BINARY_DIR}")
#-----------------------------------------------------------------------------
# Disable the warnings that DevStudio 2005 emits wrt to sprintf, strcpu, etc.
#
# On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
# warnings (copied from ITK's CMake files so that ITK templated code will compile
# correctly).
IF(WIN32)
IF(NOT BORLAND)
IF(NOT CYGWIN)
IF(NOT MINGW)
ADD_DEFINITIONS(
-D_CRT_FAR_MAPPINGS_NO_DEPRECATE
-D_CRT_IS_WCTYPE_NO_DEPRECATE
-D_CRT_MANAGED_FP_NO_DEPRECATE
-D_CRT_NONSTDC_NO_DEPRECATE
-D_CRT_SECURE_NO_DEPRECATE
-D_CRT_SECURE_NO_DEPRECATE_GLOBALS
-D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE
-D_CRT_TIME_FUNCTIONS_NO_DEPRECATE
-D_CRT_VCCLRIT_NO_DEPRECATE
-D_SCL_SECURE_NO_DEPRECATE
)
ENDIF()
ENDIF()
ENDIF()
ENDIF()
# Disable warning C4996: [...] This function or variable may be unsafe. [...]
# To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details
IF(MSVC90)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
ENDIF()
#-----------------------------------------------------------------------------
# Avoid linker bug in Mac OS 10.5
# See http://wiki.finkproject.org/index.php/Fink:Packaging:Preparing_for_10.5#OpenGL_Bug
......@@ -573,10 +499,21 @@ IF(NOT Slicer_INSTALL_NO_DEVELOPMENT)
ENDIF()
#-----------------------------------------------------------------------------
# Set C/CXX Flags
# Set COVERAGE_{C,CXX}_FLAGS variables
#-----------------------------------------------------------------------------
INCLUDE(SlicerBlockCXXCoverageFlags)
#-----------------------------------------------------------------------------
# Set {ITK,VTK}_REQUIRED_{C,CXX}_FLAGS variables
#-----------------------------------------------------------------------------
INCLUDE(vtkDetermineCompilerFlags)
INCLUDE(ITKPlatformSpecificChecks)
#-----------------------------------------------------------------------------
# Set CMAKE_{C,CXX}_FLAGS variables
#-----------------------------------------------------------------------------
SET(CMAKE_CXX_FLAGS ${Slicer_CXX_FLAGS} CACHE STRING "CMake C Flags" FORCE)
SET(CMAKE_C_FLAGS ${Slicer_C_FLAGS} CACHE STRING "CMake CXX Flags" FORCE)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_INIT} ${Slicer_REQUIRED_C_FLAGS} ${ITK_REQUIRED_C_FLAGS} ${VTK_REQUIRED_C_FLAGS} ${COVERAGE_C_FLAGS}" CACHE STRING "CMake C Flags" FORCE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} ${Slicer_REQUIRED_CXX_FLAGS} ${ITK_REQUIRED_CXX_FLAGS} ${VTK_REQUIRED_CXX_FLAGS} ${COVERAGE_CXX_FLAGS}" CACHE STRING "CMake CXX Flags" FORCE)
#-----------------------------------------------------------------------------
# Generate SlicerVersion.txt
......
......@@ -228,14 +228,15 @@ ExternalProject_Add(${proj}
CMAKE_ARGS
${slicer_superbuild_boolean_args}
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
-DADDITIONAL_C_FLAGS:STRING=${ADDITIONAL_C_FLAGS}
-DADDITIONAL_CXX_FLAGS:STRING=${ADDITIONAL_CXX_FLAGS}
-DSlicer_REQUIRED_C_FLAGS:STRING=${Slicer_REQUIRED_C_FLAGS}
-DSlicer_REQUIRED_CXX_FLAGS:STRING=${Slicer_REQUIRED_CXX_FLAGS}
-DWITH_COVERAGE:BOOL=${WITH_COVERAGE}
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DSubversion_SVN_EXECUTABLE:FILEPATH=${Subversion_SVN_EXECUTABLE}
-DGIT_EXECUTABLE:FILEPATH=${GIT_EXECUTABLE}
-DSlicer_SUPERBUILD:BOOL=OFF
-DSlicer_C_FLAGS:STRING=${Slicer_C_FLAGS}
-DSlicer_CXX_FLAGS:STRING=${Slicer_CXX_FLAGS}
-DCTEST_CONFIGURATION_TYPE:STRING=${CTEST_CONFIGURATION_TYPE}
-DDOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY:PATH=${DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY}
-DDOXYGEN_EXECUTABLE:FILEPATH=${DOXYGEN_EXECUTABLE}
......
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