From: Matthias Maier Date: Wed, 13 Jul 2016 13:34:58 +0000 (-0500) Subject: CMake: Restructure compiler sanity checks into a macro X-Git-Tag: v8.5.0-rc1~875^2~8 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38b8a54c91ccd0057201ec24991bf5340188c126;p=dealii.git CMake: Restructure compiler sanity checks into a macro --- diff --git a/cmake/macros/macro_check_compiler_flags.cmake b/cmake/macros/macro_check_compiler_flags.cmake new file mode 100644 index 0000000000..6261c8e3e9 --- /dev/null +++ b/cmake/macros/macro_check_compiler_flags.cmake @@ -0,0 +1,50 @@ +## --------------------------------------------------------------------- +## +## Copyright (C) 2016 by the deal.II authors +## +## This file is part of the deal.II library. +## +## The deal.II library is free software; you can use it, redistribute +## it, and/or modify it under the terms of the GNU Lesser General +## Public License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## The full text of the license can be found in the file LICENSE at +## the top level of the deal.II distribution. +## +## --------------------------------------------------------------------- + +# +# Usage: +# CHECK_COMPILER_FLAGS(_compiler_flags_variable _linker_flags_variable _var) +# +# This macro tries to compile and link a simple "int main(){ return 0; } +# with the given set of compiler and flags provided in +# _compiler_flags_variable and _linker_flags_variable. If the test is +# succesful the variable ${_var} is set to true, otherwise to false. +# + +MACRO(CHECK_COMPILER_FLAGS _compiler_flags_variable _linker_flags_variable _var) + # + # Rerun this test if flags have changed: + # + IF(NOT "${${_compiler_flags_variable}}" STREQUAL "${CACHED_${_var}_${_compiler_flags_variable}}" + OR NOT "${${_linker_flags_variable}}" STREQUAL "${CACHED_${_var}_${_linker_flags_variable}}") + UNSET(${_var} CACHE) + ENDIF() + + SET(CACHED_${_var}_${_compiler_flags_variable} "${${_compiler_flags_variable}}" + CACHE INTERNAL "" FORCE + ) + SET(CACHED_${_var}_${_linker_flags_variable} "${${_linker_flags_variable}}" + CACHE INTERNAL "" FORCE + ) + + SET(CMAKE_REQUIRED_FLAGS ${${_compiler_flags_variable}}) + SET(CMAKE_REQUIRED_LIBRARIES ${${_linker_flags_variable}}) + CHECK_CXX_SOURCE_COMPILES("int main(){ return 0; }" ${_var}) + RESET_CMAKE_REQUIRED() + + IF(${_var}) + SET(${_var} TRUE CACHE INTERNAL "") + ENDIF() +ENDMACRO() diff --git a/cmake/setup_compiler_flags.cmake b/cmake/setup_compiler_flags.cmake index 3dc72be873..cbe4ee2ad1 100644 --- a/cmake/setup_compiler_flags.cmake +++ b/cmake/setup_compiler_flags.cmake @@ -1,6 +1,6 @@ ## --------------------------------------------------------------------- ## -## Copyright (C) 2012 - 2015 by the deal.II authors +## Copyright (C) 2012 - 2016 by the deal.II authors ## ## This file is part of the deal.II library. ## @@ -71,33 +71,26 @@ # Check the user provided CXX flags: # -IF(NOT "${DEAL_II_CXX_FLAGS_SAVED}" STREQUAL "${CACHED_DEAL_II_CXX_FLAGS_SAVED}" - OR NOT "${DEAL_II_LINKER_FLAGS_SAVED}" STREQUAL "${CACHED_DEAL_II_LINKER_FLAGS_SAVED}") - # Rerun this test if cxx flags changed: - UNSET(DEAL_II_HAVE_USABLE_CXX_FLAGS CACHE) -ELSE() - SET(DEAL_II_HAVE_USABLE_CXX_FLAGS TRUE CACHE INTERNAL "") -ENDIF() -SET(CACHED_DEAL_II_CXX_FLAGS_SAVED "${DEAL_II_CXX_FLAGS_SAVED}" CACHE INTERNAL "" FORCE) -SET(CACHED_DEAL_II_LINKER_FLAGS_SAVED "${DEAL_II_LINKER_FLAGS_SAVED}" CACHE INTERNAL "" FORCE) - -# Initialize all CMAKE_REQUIRED_* variables a this point: -RESET_CMAKE_REQUIRED() - -CHECK_CXX_SOURCE_COMPILES( - "int main(){ return 0; }" - DEAL_II_HAVE_USABLE_CXX_FLAGS) - -IF(NOT DEAL_II_HAVE_USABLE_CXX_FLAGS) - UNSET(DEAL_II_HAVE_USABLE_CXX_FLAGS CACHE) - MESSAGE(FATAL_ERROR " -Configuration error: Cannot compile with the user supplied flags: -CXX flags: ${DEAL_II_CXX_FLAGS_SAVED} -LD flags: ${DEAL_II_LINKER_FLAGS_SAVED} -Please check the CMake variables DEAL_II_CXX_FLAGS, DEAL_II_LINKER_FLAGS -and the environment variables CXXFLAGS, LDFLAGS.\n\n" +FOREACH(build ${DEAL_II_BUILD_TYPES}) + SET(_cxx_flags_${build} "${DEAL_II_CXX_FLAGS_SAVED} ${DEAL_II_CXX_FLAGS_${build}_SAVED}") + SET(_linker_flags_${build} "${DEAL_II_CXX_FLAGS_SAVED} ${DEAL_II_CXX_FLAGS_${build}_SAVED}") + + CHECK_COMPILER_FLAGS(_cxx_flags_${build} _linker_flags_${build} + DEAL_II_HAVE_USABLE_USER_FLAGS_${build} ) -ENDIF() + + IF(NOT DEAL_II_HAVE_USABLE_USER_FLAGS_${build}) + MESSAGE(FATAL_ERROR " + Configuration error: Cannot compile with the user supplied flags: + CXX flags (${build}): ${_cxx_flags_${build}} + LD flags (${build}): ${_linker_flags_${build}} + Please check the CMake variables + DEAL_II_CXX_FLAGS, DEAL_II_CXX_FLAGS_${build}, + DEAL_II_LINKER_FLAGS, DEAL_II_CXX_FLAGS_${build} + and the environment variables CXXFLAGS, LDFLAGS.\n\n" + ) + ENDIF() +ENDFOREACH() ########################################################################