CheckFortranSourceCompiles.cmake 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. CheckFortranSourceCompiles
  5. --------------------------
  6. .. versionadded:: 3.1
  7. Check if given Fortran source compiles and links into an executable.
  8. .. command:: check_fortran_source_compiles
  9. .. code-block:: cmake
  10. check_fortran_source_compiles(<code> <resultVar>
  11. [FAIL_REGEX <regex>...]
  12. [SRC_EXT <extension>]
  13. )
  14. Checks that the source supplied in ``<code>`` can be compiled as a Fortran
  15. source file and linked as an executable. The ``<code>`` must be a Fortran
  16. ``program``.
  17. .. code-block:: cmake
  18. check_fortran_source_compiles("program test
  19. error stop
  20. end program"
  21. HAVE_ERROR_STOP
  22. SRC_EXT .F90)
  23. This command can help avoid costly build processes when a compiler lacks support
  24. for a necessary feature, or a particular vendor library is not compatible with
  25. the Fortran compiler version being used. This generate-time check may advise the
  26. user of such before the main build process. See also the
  27. :command:`check_fortran_source_runs` command to run the compiled code.
  28. The result will be stored in the internal cache
  29. variable ``<resultVar>``, with a boolean true value for success and boolean
  30. false for failure.
  31. If ``FAIL_REGEX`` is provided, then failure is determined by checking
  32. if anything in the output matches any of the specified regular expressions.
  33. By default, the test source file will be given a ``.F`` file extension. The
  34. ``SRC_EXT`` option can be used to override this with ``.<extension>`` instead--
  35. ``.F90`` is a typical choice.
  36. The check is only performed once, with the result cached in the variable named
  37. by ``<resultVar>``. Every subsequent CMake run will reuse this cached value
  38. rather than performing the check again, even if the ``<code>`` changes. In
  39. order to force the check to be re-evaluated, the variable named by
  40. ``<resultVar>`` must be manually removed from the cache.
  41. The compile and link commands can be influenced by setting any of the
  42. following variables prior to calling ``check_fortran_source_compiles()``:
  43. .. include:: /module/CMAKE_REQUIRED_FLAGS.txt
  44. .. include:: /module/CMAKE_REQUIRED_DEFINITIONS.txt
  45. .. include:: /module/CMAKE_REQUIRED_INCLUDES.txt
  46. .. include:: /module/CMAKE_REQUIRED_LINK_OPTIONS.txt
  47. .. include:: /module/CMAKE_REQUIRED_LIBRARIES.txt
  48. .. include:: /module/CMAKE_REQUIRED_QUIET.txt
  49. #]=======================================================================]
  50. include_guard(GLOBAL)
  51. include(Internal/CheckSourceCompiles)
  52. macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR)
  53. # Pass the SRC_EXT we used by default historically.
  54. # A user-provided SRC_EXT argument in ARGN will override ours.
  55. cmake_check_source_compiles(Fortran "${SOURCE}" ${VAR} SRC_EXT "F" ${ARGN})
  56. endmacro()