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.
This commit is contained in:
Brad King 2009-12-10 12:16:38 -05:00
parent faf6d82bd6
commit 55275e017d
3 changed files with 50 additions and 17 deletions

View File

@ -62,9 +62,6 @@ IF(NOT CMAKE_Fortran_COMPILER)
# The order is 95 or newer compilers first, then 90, # The order is 95 or newer compilers first, then 90,
# then 77 or older compilers, gnu is always last in the group, # then 77 or older compilers, gnu is always last in the group,
# so if you paid for a compiler it is picked by default. # so if you paid for a compiler it is picked by default.
# NOTE for testing purposes this list is DUPLICATED in
# CMake/Source/CMakeLists.txt, IF YOU CHANGE THIS LIST,
# PLEASE UPDATE THAT FILE AS WELL!
SET(CMAKE_Fortran_COMPILER_LIST SET(CMAKE_Fortran_COMPILER_LIST
ifort ifc efc f95 pgf95 lf95 xlf95 fort gfortran gfortran-4 g95 f90 ifort ifc efc f95 pgf95 lf95 xlf95 fort gfortran gfortran-4 g95 f90
pgf90 xlf90 epcf90 fort77 frt pgf77 xlf fl32 af77 g77 f77 pgf90 xlf90 epcf90 fort77 frt pgf77 xlf fl32 af77 g77 f77

View File

@ -1472,17 +1472,9 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=CVS -P ${CMake_SOURCE_DIR}/Utilities/Rel
# fortran does not work for IDE builds because # fortran does not work for IDE builds because
# CMAKE_STANDARD_LIBRARIES needs to be per language # CMAKE_STANDARD_LIBRARIES needs to be per language
IF(CMAKE_TEST_GENERATOR MATCHES "Makefiles" IF(CMAKE_TEST_GENERATOR MATCHES "Make|KDevelop")
OR CMAKE_TEST_GENERATOR MATCHES "KDevelop") INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/CheckFortran.cmake)
# see if we can find a fortran compiler on the machine IF(CMAKE_Fortran_COMPILER)
# if so, add the fortran test and see if it works.
SET(CMAKE_Fortran_COMPILER_LIST ifort ifc efc f95 pgf95
lf95 xlf95 fort gfortran gfortran-4 f90 pgf90 xlf90
epcf90 f77 fort77 frt pgf77 xlf fl32 af77 g77 )
FIND_PROGRAM(CMAKE_Fortran_COMPILER_FULLPATH NAMES
${CMAKE_Fortran_COMPILER_LIST} )
MARK_AS_ADVANCED(CMAKE_Fortran_COMPILER_FULLPATH)
IF(CMAKE_Fortran_COMPILER_FULLPATH)
ADD_TEST(Fortran ${CMAKE_CTEST_COMMAND} ADD_TEST(Fortran ${CMAKE_CTEST_COMMAND}
--build-and-test --build-and-test
"${CMake_SOURCE_DIR}/Tests/Fortran" "${CMake_SOURCE_DIR}/Tests/Fortran"
@ -1493,9 +1485,8 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=CVS -P ${CMake_SOURCE_DIR}/Utilities/Rel
--build-two-config --build-two-config
--test-command testf) --test-command testf)
LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Fortran") LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Fortran")
ENDIF(CMAKE_Fortran_COMPILER_FULLPATH) ENDIF()
ENDIF(CMAKE_TEST_GENERATOR MATCHES "Makefiles" ENDIF()
OR CMAKE_TEST_GENERATOR MATCHES "KDevelop")
IF(NOT CMAKE_TEST_GENERATOR MATCHES "Xcode") IF(NOT CMAKE_TEST_GENERATOR MATCHES "Xcode")
INCLUDE(FindJava) INCLUDE(FindJava)

45
Tests/CheckFortran.cmake Normal file
View File

@ -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()