blob: e0913bf5a5ea3588fdedd8162db5ec6e99d7fdf9 [file] [log] [blame]
Jonathan Peyton2e013352015-07-15 16:05:30 +00001#
2#//===----------------------------------------------------------------------===//
3#//
4#// The LLVM Compiler Infrastructure
5#//
6#// This file is dual licensed under the MIT and the University of Illinois Open
7#// Source Licenses. See LICENSE.txt for details.
8#//
9#//===----------------------------------------------------------------------===//
10#
11
12# Checking a fortran compiler flag
13# There is no real trivial way to do this in CMake, so we implement it here
14# this will have ${boolean} = TRUE if the flag succeeds, otherwise false.
15function(libomp_check_fortran_flag flag boolean)
16 if(NOT DEFINED "${boolean}")
17 set(retval TRUE)
18 set(fortran_source
19" program hello
20 print *, \"Hello World!\"
21 end program hello")
22
23 set(failed_regexes "[Ee]rror;[Uu]nknown;[Ss]kipping")
24 if(CMAKE_VERSION VERSION_GREATER 3.1 OR CMAKE_VERSION VERSION_EQUAL 3.1)
25 include(CheckFortranSourceCompiles)
26 check_fortran_source_compiles("${fortran_source}" ${boolean} FAIL_REGEX "${failed_regexes}")
27 set(${boolean} ${${boolean}} PARENT_SCOPE)
28 return()
29 else()
30 # Our manual check for cmake versions that don't have CheckFortranSourceCompiles
31 set(base_dir ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/fortran_flag_check)
32 file(MAKE_DIRECTORY ${base_dir})
33 file(WRITE ${base_dir}/fortran_source.f "${fortran_source}")
34
35 message(STATUS "Performing Test ${boolean}")
36 execute_process(
37 COMMAND ${CMAKE_Fortran_COMPILER} "${flag}" ${base_dir}/fortran_source.f
38 WORKING_DIRECTORY ${base_dir}
39 RESULT_VARIABLE exit_code
40 OUTPUT_VARIABLE OUTPUT
41 ERROR_VARIABLE OUTPUT
42 )
43
44 if(${exit_code} EQUAL 0)
45 foreach(regex IN LISTS failed_regexes)
46 if("${OUTPUT}" MATCHES ${regex})
47 set(retval FALSE)
48 endif()
49 endforeach()
50 else()
51 set(retval FALSE)
52 endif()
53
54 if(${retval})
55 set(${boolean} 1 CACHE INTERNAL "Test ${boolean}")
56 message(STATUS "Performing Test ${boolean} - Success")
57 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
58 "Performing Fortran Compiler Flag test ${boolean} succeeded with the following output:\n"
59 "${OUTPUT}\n"
60 "Source file was:\n${fortran_source}\n")
61 else()
62 set(${boolean} "" CACHE INTERNAL "Test ${boolean}")
63 message(STATUS "Performing Test ${boolean} - Failed")
64 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
65 "Performing Fortran Compiler Flag test ${boolean} failed with the following output:\n"
66 "${OUTPUT}\n"
67 "Source file was:\n${fortran_source}\n")
68 endif()
69 endif()
70
71 set(${boolean} ${retval} PARENT_SCOPE)
72 endif()
73endfunction()