]> https://gitweb.dealii.org/ - dealii.git/commitdiff
CMake: Restructure compiler sanity checks into a macro
authorMatthias Maier <tamiko@43-1.org>
Wed, 13 Jul 2016 13:34:58 +0000 (08:34 -0500)
committerMatthias Maier <tamiko@43-1.org>
Thu, 14 Jul 2016 00:19:05 +0000 (19:19 -0500)
cmake/macros/macro_check_compiler_flags.cmake [new file with mode: 0644]
cmake/setup_compiler_flags.cmake

diff --git a/cmake/macros/macro_check_compiler_flags.cmake b/cmake/macros/macro_check_compiler_flags.cmake
new file mode 100644 (file)
index 0000000..6261c8e
--- /dev/null
@@ -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()
index 3dc72be873de64b72932d6655fdc8618138f1fec..cbe4ee2ad1170a9a910beeed60c0ba53714df154 100644 (file)
@@ -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.
 ##
 # 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()
 
 
 ########################################################################

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.