diff options
author | Brad King <brad.king@kitware.com> | 2009-12-10 17:16:38 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-12-10 17:16:38 (GMT) |
commit | 55275e017dfdd2826e2791ac16d29ea0cdfc55ac (patch) | |
tree | 37190e6c53b7547b362e5da3b88be38e164850a9 /Tests/CheckFortran.cmake | |
parent | faf6d82bd6b6d31887f1f909d3b46b5fd130a435 (diff) | |
download | CMake-55275e017dfdd2826e2791ac16d29ea0cdfc55ac.zip CMake-55275e017dfdd2826e2791ac16d29ea0cdfc55ac.tar.gz CMake-55275e017dfdd2826e2791ac16d29ea0cdfc55ac.tar.bz2 |
New decision method to enable Fortran tests
CMake does not enable Fortran for its own build, but it needs to find a
Fortran compiler to know if it is possible to enable Fortran tests.
Previously we searched for a hard-coded list of Fortran compilers which
was duplicated from the CMakeDetermineFortranCompiler.cmake module. We
now run CMake on a small test project that enables the Fortran language
and reports the compiler it found. This represents a more realistic
check of whether the Fortran tests will be able to find a compiler.
Diffstat (limited to 'Tests/CheckFortran.cmake')
-rw-r--r-- | Tests/CheckFortran.cmake | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Tests/CheckFortran.cmake b/Tests/CheckFortran.cmake new file mode 100644 index 0000000..cf47576 --- /dev/null +++ b/Tests/CheckFortran.cmake @@ -0,0 +1,45 @@ + +#============================================================================= +# Copyright 2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distributed this file outside of CMake, substitute the full +# License text for the above reference.) + +if(NOT DEFINED CMAKE_Fortran_COMPILER) + set(_desc "Looking for a Fortran compiler") + message(STATUS ${_desc}) + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckFortran/CMakeLists.txt" + "cmake_minimum_required(VERSION 2.4) +project(CheckFortran Fortran) +file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\" + \"set(CMAKE_Fortran_COMPILER \\\"\${CMAKE_Fortran_COMPILER}\\\")\\n\") +") + execute_process( + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckFortran + COMMAND ${CMAKE_COMMAND} . -G ${CMAKE_GENERATOR} + OUTPUT_VARIABLE output + ERROR_VARIABLE output + RESULT_VARIABLE result + ) + include(${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckFortran/result.cmake OPTIONAL) + if(CMAKE_Fortran_COMPILER AND "${result}" STREQUAL "0") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "${_desc} passed with the following output:\n" + "${output}\n") + else() + set(CMAKE_Fortran_COMPILER NOTFOUND) + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "${_desc} failed with the following output:\n" + "${output}\n") + endif() + message(STATUS "${_desc} - ${CMAKE_Fortran_COMPILER}") + set(CMAKE_Fortran_COMPILER "${CMAKE_Fortran_COMPILER}" CACHE FILEPATH "Fortran compiler") + mark_as_advanced(CMAKE_Fortran_COMPILER) +endif() |