KWSys Nightly Date Stamp
[cmake.git] / Modules / CMakeTestFortranCompiler.cmake
blobcb91572c0c272d905af02f9c8d5bb9fae0b0e0f7
2 # This file is used by EnableLanguage in cmGlobalGenerator to
3 # determine that that selected Fortran compiler can actually compile
4 # and link the most basic of programs.   If not, a fatal error
5 # is set and cmake stops processing commands and will not generate
6 # any makefiles or projects.
7 IF(NOT CMAKE_Fortran_COMPILER_WORKS)
8   MESSAGE(STATUS "Check for working Fortran compiler: ${CMAKE_Fortran_COMPILER}")
9   FILE(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f "
10         PROGRAM TESTFortran
11         PRINT *, 'Hello'
12         END
13   ")
14   TRY_COMPILE(CMAKE_Fortran_COMPILER_WORKS ${CMAKE_BINARY_DIR} 
15     ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f
16     OUTPUT_VARIABLE OUTPUT)
17   SET(FORTRAN_TEST_WAS_RUN 1)
18 ENDIF(NOT CMAKE_Fortran_COMPILER_WORKS)
20 IF(NOT CMAKE_Fortran_COMPILER_WORKS)
21   MESSAGE(STATUS "Check for working Fortran compiler: ${CMAKE_Fortran_COMPILER} -- broken")
22   FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
23     "Determining if the Fortran compiler works failed with "
24     "the following output:\n${OUTPUT}\n\n")
25   MESSAGE(FATAL_ERROR "The Fortran compiler \"${CMAKE_Fortran_COMPILER}\" "
26     "is not able to compile a simple test program.\nIt fails "
27     "with the following output:\n ${OUTPUT}\n\n"
28     "CMake will not be able to correctly generate this project.")
29 ELSE(NOT CMAKE_Fortran_COMPILER_WORKS)
30   IF(FORTRAN_TEST_WAS_RUN)
31     MESSAGE(STATUS "Check for working Fortran compiler: ${CMAKE_Fortran_COMPILER} -- works")
32     FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
33       "Determining if the Fortran compiler works passed with "
34       "the following output:\n${OUTPUT}\n\n")
35   ENDIF(FORTRAN_TEST_WAS_RUN)
36   SET(CMAKE_Fortran_COMPILER_WORKS 1 CACHE INTERNAL "")
38   IF(CMAKE_Fortran_COMPILER_FORCED)
39     # The compiler configuration was forced by the user.
40     # Assume the user has configured all compiler information.
41   ELSE(CMAKE_Fortran_COMPILER_FORCED)
42     # Try to identify the ABI and configure it into CMakeFortranCompiler.cmake
43     INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
44     CMAKE_DETERMINE_COMPILER_ABI(Fortran ${CMAKE_ROOT}/Modules/CMakeFortranCompilerABI.F)
46     # Test for Fortran 90 support by using an f90-specific construct.
47     IF(NOT DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90)
48       MESSAGE(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90")
49       FILE(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF90.f90 "
50       PROGRAM TESTFortran90
51       stop = 1 ; do while ( stop .eq. 0 ) ; end do
52       END PROGRAM TESTFortran90
54       TRY_COMPILE(CMAKE_Fortran_COMPILER_SUPPORTS_F90 ${CMAKE_BINARY_DIR}
55         ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF90.f90
56         OUTPUT_VARIABLE OUTPUT)
57       IF(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
58         MESSAGE(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90 -- yes")
59         FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
60           "Determining if the Fortran compiler supports Fortran 90 passed with "
61           "the following output:\n${OUTPUT}\n\n")
62         SET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1)
63       ELSE(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
64         MESSAGE(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90 -- no")
65         FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
66           "Determining if the Fortran compiler supports Fortran 90 failed with "
67           "the following output:\n${OUTPUT}\n\n")
68         SET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 0)
69       ENDIF(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
70       UNSET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 CACHE)
71     ENDIF(NOT DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90)
73     CONFIGURE_FILE(
74       ${CMAKE_ROOT}/Modules/CMakeFortranCompiler.cmake.in
75       ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeFortranCompiler.cmake
76       @ONLY IMMEDIATE # IMMEDIATE must be here for compatibility mode <= 2.0
77       )
78   ENDIF(CMAKE_Fortran_COMPILER_FORCED)
79 ENDIF(NOT CMAKE_Fortran_COMPILER_WORKS)