]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
CMake: Implement ENABLE_LANGUAGE_OPTIONAL
authormaier <maier@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 22 Jul 2013 23:19:52 +0000 (23:19 +0000)
committermaier <maier@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 22 Jul 2013 23:19:52 +0000 (23:19 +0000)
git-svn-id: https://svn.dealii.org/trunk@30118 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/CMakeLists.txt
deal.II/cmake/configure/configure_1_mpi.cmake
deal.II/cmake/macros/macro_enable_language_optional.cmake [new file with mode: 0644]
deal.II/cmake/setup_compiler_flags.cmake
deal.II/doc/development/Config.sample
deal.II/doc/development/cmake.html

index 10ee330876ca91ecd7870e7f9d6caf588e806954..04dba539c696ceb060503a5d8e6d5094a214a21c 100644 (file)
@@ -69,16 +69,8 @@ INCLUDE(setup_cached_variables)
 # Now, set the project and set up the rest:
 #
 PROJECT(deal.II CXX)
-ENABLE_LANGUAGE(C)
-
-#
-# TODO: A quick test. Refactor.
-# It would be highly appreciated to use ENABLE_LANGUAGE(... OPTIONAL) here
-# - but this is broken beyond believe up until cmake-2.11.* *sigh*
-#
-IF(ENABLE_FORTRAN)
-  ENABLE_LANGUAGE(Fortran)
-ENDIF()
+ENABLE_LANGUAGE_OPTIONAL(C)
+ENABLE_LANGUAGE_OPTIONAL(Fortran)
 
 INCLUDE(setup_deal_ii)
 INCLUDE(setup_compiler_flags)
index 2b15c452c36f12a49f1ee1f027cd074148fb3626..85de2a41c2ec721d2dc7ffe0911379e21545ef4a 100644 (file)
@@ -17,6 +17,9 @@
 #
 # Configuration for mpi support:
 #
+# We look for the C and Fortran libraries as well because they are needed
+# by some external libraries:
+#
 
 MACRO(FEATURE_MPI_FIND_EXTERNAL var)
   #
diff --git a/deal.II/cmake/macros/macro_enable_language_optional.cmake b/deal.II/cmake/macros/macro_enable_language_optional.cmake
new file mode 100644 (file)
index 0000000..975f476
--- /dev/null
@@ -0,0 +1,65 @@
+## ---------------------------------------------------------------------
+## $Id$
+##
+## Copyright (C) 2013 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.
+##
+## ---------------------------------------------------------------------
+
+
+#
+# Test whether a usable language compiler is available and if yes, call
+# ENABLE_LANGUAGE(language)
+#
+# This works around a severe bug [1] in
+#
+#   ENABLE_LANGUAGE(Fortran OPTIONAL)
+#
+# [1] http://public.kitware.com/Bug/view.php?id=9220
+#
+# Usage:
+#     ENABLE_LANGUAGE_FORTRAN_OPTIONAL(language)
+#
+# where language is either C or Fortran
+#
+
+MACRO(ENABLE_LANGUAGE_OPTIONAL _language)
+  #
+  # Run this check exactly once:
+  #
+  IF(NOT ${_language}_CHECKED)
+    SET(${_language}_CHECKED TRUE CACHE INTERNAL "" FORCE)
+
+    SET(_tmp ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/${_language}_test)
+    file(REMOVE ${_tmp})
+
+    IF(DEFINED CMAKE_${_language}_COMPILER)
+      SET(_hint "-DCMAKE_${_language}_COMPILER=${CMAKE_${_language}_COMPILER}")
+    ENDIF()
+
+    FILE(WRITE ${_tmp}/CMakeLists.txt
+      "PROJECT(foobar ${_language})"
+      )
+    EXECUTE_PROCESS(
+      COMMAND ${CMAKE_COMMAND} ${_hint} .
+      WORKING_DIRECTORY ${_tmp}
+      RESULT_VARIABLE _result
+      OUTPUT_QUIET
+      ERROR_QUIET
+      )
+
+    IF("${_result}" STREQUAL "0")
+      ENABLE_LANGUAGE(${_language})
+    ELSE()
+      MESSAGE(STATUS "No working ${_language} compiler found, disabling ${_language}")
+    ENDIF()
+  ENDIF()
+ENDMACRO()
index 92baf5eb1a7a4864e03fc0df8e54bba83c6950bd..4815abf65fafa4af54fa8ac1da7d89f2afa25a42 100644 (file)
@@ -65,9 +65,7 @@
 #
 # Check the user provided CXX flags:
 #
-#
-# Omit to test for a sane C and Fortran toolchain for now..
-#
+MESSAGE(STATUS "")
 IF(NOT "${CMAKE_CXX_FLAGS_SAVED}" STREQUAL "${DEAL_II_CXX_FLAGS_SAVED}")
   UNSET(DEAL_II_HAVE_USABLE_CXX_FLAGS CACHE)
 ENDIF()
index 61716f2d5f6a6c6e71d0d4d0f08d642a6a6b705b..6f4ad89247bf0bfa16ed9fafe4c4a39b6f785e03 100644 (file)
 #   "C Compiler."
 #   )
 #
+# SET(CMAKE_Fortran_COMPILER "" CACHE STRING
+#   "Fortran Compiler."
+#   )
+#
 # SET(CMAKE_CXX_FLAGS "" CACHE STRING
 #   "The user supplied cache variable will be appended _at the end_ of the auto generated CMAKE_CXX_FLAGS variable"
 #   )
 # conservative. Only the current compiler and the variable MPI_CXX_COMPILER
 # is used to find MPI. (MPI_CXX_COMPILER takes precedence.)
 #
+# (MPI_C_COMPILER and MPI_Fortran_COMPILER are considered, too)
+#
+#
 # DEAL_II_WITH_MPI=ON will trigger a more sophisticated search for MPI.
 #
 # The best way to force a specific MPI implementation to be used is to set
-# CMAKE_C_COMPILER and CMAKE_CXX_COMPILER to the appropriate MPI wrapper
-# (See above).
+# CMAKE_CXX_COMPILER, CMAKE_C_COMPILER and CMAKE_Fortran_COMPILER to the
+# appropriate MPI wrapper (See above).
 #
 # Alternatively, specify the mpi wrapper that will be queried for the mpi
 # link interface:
 #
 # SET(MPI_CXX_COMPILER "mpicxx" CACHE STRING "")
 #
+# SET(MPI_C_COMPILER "mpicc" CACHE STRING "")
+# SET(MPI_Fortran_COMPILER "mpif90" CACHE STRING "")
+#
 #
 # Manual setup:
 #
 # SET(MPI_CXX_COMPILE_FLAGS "..." CACHE STRING "")
 # SET(MPI_CXX_LINK_FLAGS "..." CACHE STRING "")
 #
+# Additionally:
+#
+# SET(MPI_C_LIBRARIES "library;and;semicolon;separated;list;of;link;interface" CACHE STRING "")
+# SET(MPI_Fortran_LIBRARIES "library;and;semicolon;separated;list;of;link;interface" CACHE STRING "")
+#
+#
 
 
 #
index 75c7bb845187652588cbdf022cfb5b9f4f9c0539..05fe95d6e9b9c9627e625eb85589c9af404813dc 100644 (file)
 
     </p>
       Compilers can be switched either by command line or by setting
-      <code>CMAKE_(C|CXX)_COMPILER</code>:
+      <code>CMAKE_(C|CXX|Fortran)_COMPILER</code>:
       <pre>
 
      CC=mpicc CXX=mpicxx cmake &lt;...&gt;
 
-     cmake -DCMAKE_C_COMPILER="mpicc" -DCMAKE_CXX_COMPILER="mpicxx" &lt;...&gt;
+     cmake -DCMAKE_C_COMPILER="mpicc" -DCMAKE_CXX_COMPILER="mpicxx" -DCMAKE_Fortran_COMPILER="mpif90" &lt;...&gt;
       </pre>
       Please note that
       <ul>
           The compiler <i>must</i> be specified at the very first
           invokation of <code>cmake</code>.
         <li>
-          The specified C and CXX compilers must be the same compiler
-          brand and the same compiler version.
+          A working CXX compiler is needed. It is optional to provide a C
+          or Fortran compiler.
       </ul>
     </p>
 
     <p>
-      deal.II will configure sensible default <code>CFLAGS</code> and
-      <code>CXXFLAGS</code> depending on platform, compiler and build
-      target. There are two options to override this behaviour:
+      deal.II will configure sensible default <code>CXXFLAGS</code>
+      depending on platform, compiler and build target. There are two
+      options to override this behaviour:
 
       <ol>
        <li>

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.