CheckFortranSourceRuns.cmake 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_LINK_DIRECTORIES.txt
  36. .. include:: /module/CMAKE_REQUIRED_QUIET.txt
  37. #]=======================================================================]
  38. include_guard(GLOBAL)
  39. include(Internal/CheckSourceRuns)
  40. macro(CHECK_Fortran_SOURCE_RUNS SOURCE VAR)
  41. # Pass the SRC_EXT we used by default historically.
  42. # A user-provided SRC_EXT argument in ARGN will override ours.
  43. cmake_check_source_runs(Fortran "${SOURCE}" ${VAR} SRC_EXT "F90" ${ARGN})
  44. endmacro()