ENH: move EstimateFormatLength to kwsys
[cmake.git] / Modules / CMakeTestFortranCompiler.cmake
blob49c6664e10750ab34cd2a50b96ae8b62f37bce5f
1 # This file is used by EnableLanguage in cmGlobalGenerator to
2 # determine that that selected Fortran compiler can actually compile
3 # and link the most basic of programs.   If not, a fatal error
4 # is set and cmake stops processing commands and will not generate
5 # any makefiles or projects.
6 IF(NOT CMAKE_Fortran_COMPILER_WORKS)
7   MESSAGE(STATUS "Check for working Fortran compiler: ${CMAKE_Fortran_COMPILER}")
8   FILE(WRITE ${CMAKE_BINARY_DIR}/CMakeTmp/testFortranCompiler.f "
9         PROGRAM TESTFortran
10         PRINT *, 'Hello'
11         END
12   ")
13   TRY_COMPILE(CMAKE_Fortran_COMPILER_WORKS ${CMAKE_BINARY_DIR} 
14     ${CMAKE_BINARY_DIR}/CMakeTmp/testFortranCompiler.f
15     OUTPUT_VARIABLE OUTPUT)
16   SET(FORTRAN_TEST_WAS_RUN 1)
17 ENDIF(NOT CMAKE_Fortran_COMPILER_WORKS)
19 IF(NOT CMAKE_Fortran_COMPILER_WORKS)
20   MESSAGE(STATUS "Check for working Fortran compiler: ${CMAKE_Fortran_COMPILER} -- broken")
21   FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeError.log
22     "Determining if the Fortran compiler works failed with "
23     "the following output:\n${OUTPUT}\n\n")
24   MESSAGE(FATAL_ERROR "The Fortran compiler \"${CMAKE_Fortran_COMPILER}\" "
25     "is not able to compile a simple test program.\nIt fails "
26     "with the following output:\n ${OUTPUT}\n\n"
27     "CMake will not be able to correctly generate this project.")
28 ELSE(NOT CMAKE_Fortran_COMPILER_WORKS)
29   IF(FORTRAN_TEST_WAS_RUN)
30     MESSAGE(STATUS "Check for working Fortran compiler: ${CMAKE_Fortran_COMPILER} -- works")
31     FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log
32       "Determining if the Fortran compiler works passed with "
33       "the following output:\n${OUTPUT}\n\n")
34   ENDIF(FORTRAN_TEST_WAS_RUN)
35   SET(CMAKE_Fortran_COMPILER_WORKS 1 CACHE INTERNAL "")
36 ENDIF(NOT CMAKE_Fortran_COMPILER_WORKS)
38 IF(CMAKE_Fortran_COMPILER_WORKS)
39   # Test for Fortran 90 support by using an f90-specific construct.
40   IF(DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90)
41   ELSE(DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90)
42     MESSAGE(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90")
43     FILE(WRITE ${CMAKE_BINARY_DIR}/CMakeTmp/testFortranCompilerF90.f90 "
44       PROGRAM TESTFortran90
45       stop = 1 ; do while ( stop .eq. 0 ) ; end do
46       END PROGRAM TESTFortran90
47   ")
48     TRY_COMPILE(CMAKE_Fortran_COMPILER_SUPPORTS_F90 ${CMAKE_BINARY_DIR}
49       ${CMAKE_BINARY_DIR}/CMakeTmp/testFortranCompilerF90.f90
50       OUTPUT_VARIABLE OUTPUT)
51     IF(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
52       MESSAGE(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90 -- yes")
53       FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log
54         "Determining if the Fortran compiler supports Fortran 90 passed with "
55         "the following output:\n${OUTPUT}\n\n")
56       SET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1 CACHE INTERNAL "")
57     ELSE(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
58       MESSAGE(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90 -- no")
59       FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeError.log
60         "Determining if the Fortran compiler supports Fortran 90 failed with "
61         "the following output:\n${OUTPUT}\n\n")
62       SET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 0 CACHE INTERNAL "")
63     ENDIF(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
64   ENDIF(DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90)
65 ENDIF(CMAKE_Fortran_COMPILER_WORKS)