CheckFortranSourceRuns.cmake 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. CheckFortranSourceRuns
  5. ----------------------
  6. .. versionadded:: 3.14
  7. Check once if given Fortran source compiles and links into an executable and can
  8. subsequently be run.
  9. .. command:: check_fortran_source_runs
  10. .. code-block:: cmake
  11. check_fortran_source_runs(<code> <resultVar>
  12. [SRC_EXT <extension>])
  13. Check once that the source supplied in ``<code>`` can be built, linked as an
  14. executable, and then run. The ``<code>`` must contain a Fortran ``program``.
  15. The result is stored in the internal cache variable specified by
  16. ``<resultVar>``. Success of build and run is indicated by boolean ``true``.
  17. Failure to build or run is indicated by boolean ``false`` such as an empty
  18. string or an error message.
  19. .. code-block:: cmake
  20. check_fortran_source_runs("program test
  21. real :: x[*]
  22. call co_sum(x)
  23. end program"
  24. HAVE_COARRAY)
  25. By default, the test source file will be given a ``.F90`` file extension. The
  26. ``SRC_EXT`` option can be used to override this with ``.<extension>`` instead.
  27. See also :command:`check_source_runs` for a more general command syntax.
  28. The compile and link commands can be influenced by setting any of the
  29. following variables prior to calling ``check_fortran_source_runs()``:
  30. .. include:: /module/CMAKE_REQUIRED_FLAGS.txt
  31. .. include:: /module/CMAKE_REQUIRED_DEFINITIONS.txt
  32. .. include:: /module/CMAKE_REQUIRED_INCLUDES.txt
  33. .. include:: /module/CMAKE_REQUIRED_LINK_OPTIONS.txt
  34. .. include:: /module/CMAKE_REQUIRED_LIBRARIES.txt
  35. .. include:: /module/CMAKE_REQUIRED_QUIET.txt
  36. #]=======================================================================]
  37. include_guard(GLOBAL)
  38. include(Internal/CheckSourceRuns)
  39. macro(CHECK_Fortran_SOURCE_RUNS SOURCE VAR)
  40. # Pass the SRC_EXT we used by default historically.
  41. # A user-provided SRC_EXT argument in ARGN will override ours.
  42. cmake_check_source_runs(Fortran "${SOURCE}" ${VAR} SRC_EXT "F90" ${ARGN})
  43. endmacro()