# 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)
#
# 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)
#
--- /dev/null
+## ---------------------------------------------------------------------
+## $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()
#
# 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()
# "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 "")
+#
+#
#
</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 <...>
- cmake -DCMAKE_C_COMPILER="mpicc" -DCMAKE_CXX_COMPILER="mpicxx" <...>
+ cmake -DCMAKE_C_COMPILER="mpicc" -DCMAKE_CXX_COMPILER="mpicxx" -DCMAKE_Fortran_COMPILER="mpif90" <...>
</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>