CheckFortranSourceRuns.cmake 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. CheckFortranSourceRuns
  5. ----------------------
  6. .. versionadded:: 3.14
  7. This module provides a command to check whether a Fortran source can be built
  8. and run.
  9. Load this module in a CMake project with:
  10. .. code-block:: cmake
  11. include(CheckFortranSourceRuns)
  12. Commands
  13. ^^^^^^^^
  14. This module provides the following command:
  15. .. command:: check_fortran_source_runs
  16. Checks once whether the given Fortran source compiles and links into an
  17. executable that can subsequently be run.
  18. .. code-block:: cmake
  19. check_fortran_source_runs(<code> <variable> [SRC_EXT <extension>])
  20. The Fortran source supplied in ``<code>`` must contain a Fortran ``program``
  21. unit. The result of the check is stored in the internal cache variable
  22. specified by ``<variable>``. If the code builds and runs with exit code
  23. ``0``, success is indicated by a boolean true value. Failure to build or
  24. run is indicated by a boolean false value, such as an empty string or an
  25. error message.
  26. The options are:
  27. ``SRC_EXT <extension>``
  28. By default, the internal test source file used for the check will be
  29. given a ``.F90`` file extension. This option can be used to change the
  30. extension to ``.<extension>`` instead.
  31. .. rubric:: Variables Affecting the Check
  32. The following variables may be set before calling this command to modify
  33. the way the check is run:
  34. .. include:: /module/include/CMAKE_REQUIRED_FLAGS.rst
  35. .. include:: /module/include/CMAKE_REQUIRED_DEFINITIONS.rst
  36. .. include:: /module/include/CMAKE_REQUIRED_INCLUDES.rst
  37. .. include:: /module/include/CMAKE_REQUIRED_LINK_OPTIONS.rst
  38. .. include:: /module/include/CMAKE_REQUIRED_LIBRARIES.rst
  39. .. include:: /module/include/CMAKE_REQUIRED_LINK_DIRECTORIES.rst
  40. .. include:: /module/include/CMAKE_REQUIRED_QUIET.rst
  41. Examples
  42. ^^^^^^^^
  43. The following example shows how to use this module to check whether a Fortran
  44. source code runs and store the result of the check in an internal cache
  45. variable ``HAVE_COARRAY``:
  46. .. code-block:: cmake
  47. include(CheckFortranSourceRuns)
  48. check_fortran_source_runs([[
  49. program test
  50. real :: x[*]
  51. call co_sum(x)
  52. end program
  53. ]] HAVE_COARRAY)
  54. See Also
  55. ^^^^^^^^
  56. * The :module:`CheckSourceRuns` module for a more general command syntax.
  57. * The :module:`CheckSourceCompiles` module to check whether a source code
  58. can be built.
  59. #]=======================================================================]
  60. include_guard(GLOBAL)
  61. include(Internal/CheckSourceRuns)
  62. macro(CHECK_Fortran_SOURCE_RUNS SOURCE VAR)
  63. # Pass the SRC_EXT we used by default historically.
  64. # A user-provided SRC_EXT argument in ARGN will override ours.
  65. cmake_check_source_runs(Fortran "${SOURCE}" ${VAR} SRC_EXT "F90" ${ARGN})
  66. endmacro()