1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
5 if(CMAKE_Fortran_COMPILER_FORCED)
6 # The compiler configuration was forced by the user.
7 # Assume the user has configured all compiler information.
8 set(CMAKE_Fortran_COMPILER_WORKS TRUE)
12 include(CMakeTestCompilerCommon)
14 # Remove any cached result from an older CMake version.
15 # We now store this in CMakeFortranCompiler.cmake.
16 unset(CMAKE_Fortran_COMPILER_WORKS CACHE)
18 # Try to identify the ABI and configure it into CMakeFortranCompiler.cmake
19 include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
20 CMAKE_DETERMINE_COMPILER_ABI(Fortran ${CMAKE_ROOT}/Modules/CMakeFortranCompilerABI.F90)
21 if(CMAKE_Fortran_ABI_COMPILED)
22 # The compiler worked so skip dedicated test below.
23 set(CMAKE_Fortran_COMPILER_WORKS TRUE)
24 set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1)
25 message(STATUS "Check for working Fortran compiler: ${CMAKE_Fortran_COMPILER} - skipped")
27 cmake_determine_compiler_abi(Fortran ${CMAKE_ROOT}/Modules/CMakeFortranCompilerABI.F)
28 if(CMAKE_Fortran_ABI_COMPILED)
29 set(CMAKE_Fortran_COMPILER_WORKS TRUE)
30 message(STATUS "Check for working Fortran 77 compiler: ${CMAKE_Fortran_COMPILER} - skipped")
34 # This file is used by EnableLanguage in cmGlobalGenerator to
35 # determine that the selected Fortran compiler can actually compile
36 # and link the most basic of programs. If not, a fatal error
37 # is set and cmake stops processing commands and will not generate
38 # any makefiles or projects.
39 if(NOT CMAKE_Fortran_COMPILER_WORKS)
40 PrintTestCompilerStatus("Fortran")
41 set(__TestCompiler_testFortranCompilerSource "
46 # Clear result from normal variable.
47 unset(CMAKE_Fortran_COMPILER_WORKS)
48 # Puts test result in cache variable.
49 try_compile(CMAKE_Fortran_COMPILER_WORKS
50 SOURCE_FROM_VAR testFortranCompiler.f __TestCompiler_testFortranCompilerSource
51 OUTPUT_VARIABLE OUTPUT)
52 unset(__TestCompiler_testFortranCompilerSource)
53 # Move result from cache to normal variable.
54 set(CMAKE_Fortran_COMPILER_WORKS ${CMAKE_Fortran_COMPILER_WORKS})
55 unset(CMAKE_Fortran_COMPILER_WORKS CACHE)
56 if(NOT CMAKE_Fortran_COMPILER_WORKS)
57 PrintTestCompilerResult(CHECK_FAIL "broken")
58 string(REPLACE "\n" "\n " _output "${OUTPUT}")
59 message(FATAL_ERROR "The Fortran compiler\n \"${CMAKE_Fortran_COMPILER}\"\n"
60 "is not able to compile a simple test program.\nIt fails "
61 "with the following output:\n ${_output}\n\n"
62 "CMake will not be able to correctly generate this project.")
64 PrintTestCompilerResult(CHECK_PASS "works")
67 # Test for Fortran 90 support by using an f90-specific construct.
68 if(NOT DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90)
69 message(CHECK_START "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90")
70 set(__TestCompiler_testFortranCompilerSource "
72 integer stop ; stop = 1 ; do while ( stop .eq. 0 ) ; end do
73 END PROGRAM TESTFortran90
75 try_compile(CMAKE_Fortran_COMPILER_SUPPORTS_F90
76 SOURCE_FROM_VAR testFortranCompilerF90.f90 __TestCompiler_testFortranCompilerF90Source
77 OUTPUT_VARIABLE OUTPUT)
78 unset(__TestCompiler_testFortranCompilerF90Source)
79 if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
80 message(CHECK_PASS "yes")
81 set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1)
83 message(CHECK_FAIL "no")
84 set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 0)
86 unset(CMAKE_Fortran_COMPILER_SUPPORTS_F90 CACHE)
89 # Re-configure to save learned information.
91 ${CMAKE_ROOT}/Modules/CMakeFortranCompiler.cmake.in
92 ${CMAKE_PLATFORM_INFO_DIR}/CMakeFortranCompiler.cmake
95 include(${CMAKE_PLATFORM_INFO_DIR}/CMakeFortranCompiler.cmake)
97 if(CMAKE_Fortran_SIZEOF_DATA_PTR)
98 foreach(f ${CMAKE_Fortran_ABI_FILES})
101 unset(CMAKE_Fortran_ABI_FILES)