Commit 9897118a authored by jcfr's avatar jcfr
Browse files

ENH: Regular C/CXX flags automatically added for GNUCXX compiler

The macro SlicerFunctionCheckCompilerFlags allows to check
if a given flag supported by the underlying compiler

git-svn-id: http://svn.slicer.org/Slicer4/trunk@15176 3bd1e089-480b-0410-8dfb-8563597acbee
parent 87eb8cdf
###########################################################################
#
# 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.
#
###########################################################################
# See http://github.com/commontk/CTK/blob/master/CMake/ctkFunctionCheckCompilerFlags.cmake
#
# Helper macro allowing to check if the given flags are supported
# by the underlying build tool
#
# If the flag(s) is/are supported, they will be appended to the string identified by RESULT_VAR
#
# Usage:
# ctkFunctionCheckCompilerFlags(FLAGS_TO_CHECK VALID_FLAGS_VAR)
#
# Example:
#
# set(myflags)
# ctkFunctionCheckCompilerFlags("-fprofile-arcs" myflags)
# message(1-myflags:${myflags})
# ctkFunctionCheckCompilerFlags("-fauto-bugfix" myflags)
# message(2-myflags:${myflags})
# ctkFunctionCheckCompilerFlags("-Wall" myflags)
# message(1-myflags:${myflags})
#
# The output will be:
# 1-myflags: -fprofile-arcs
# 2-myflags: -fprofile-arcs
# 3-myflags: -fprofile-arcs -Wall
INCLUDE(TestCXXAcceptsFlag)
FUNCTION(SlicerFunctionCheckCompilerFlags CXX_FLAG_TO_TEST RESULT_VAR)
IF(CXX_FLAG_TO_TEST STREQUAL "")
MESSAGE(FATAL_ERROR "CXX_FLAG_TO_TEST shouldn't be empty")
ENDIF()
CHECK_CXX_ACCEPTS_FLAG(${CXX_FLAG_TO_TEST} HAS_FLAG)
IF(HAS_FLAG)
SET(${RESULT_VAR} "${${RESULT_VAR}} ${CXX_FLAG_TO_TEST}" PARENT_SCOPE)
ENDIF()
ENDFUNCTION()
......@@ -38,6 +38,7 @@ INCLUDE(CMake/Slicer3PersistenceMacros.cmake)
INCLUDE(CMake/SlicerParseArgumentsMacro.cmake)
INCLUDE(CMake/Slicer3PluginsMacros.cmake)
INCLUDE(CMake/SlicerMacroEmptyExternalProject.cmake)
INCLUDE(CMake/SlicerFunctionCheckCompilerFlags.cmake)
#-----------------------------------------------------------------------------
# Platform check
......@@ -168,8 +169,21 @@ MARK_AS_ADVANCED(ADDITIONAL_CXX_FLAGS)
#-----------------------------------------------------------------------------
SET(Slicer_C_FLAGS "${ADDITIONAL_C_FLAGS}")
SET(Slicer_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("-fstack-protector-all" cflags)
IF(MINGW)
# suppress warnings about auto imported symbols
SET(Slicer_CXX_FLAGS "-Wl,--enable-auto-import ${Slicer_CXX_FLAGS}")
ENDIF()
SET(Slicer_C_FLAGS "${cflags} ${Slicer_C_FLAGS}")
SET(Slicer_CXX_FLAGS "${cflags} -Woverloaded-virtual -Wold-style-cast -Wstrict-null-sentinel -Wsign-promo ${Slicer_CXX_FLAGS}")
ENDIF()
#-----------------------------------------------------------------------------
# Superbuild script
#-----------------------------------------------------------------------------
......
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