CheckFortranSourceCompiles.cmake 2.4 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. CheckFortranSourceCompiles
  5. --------------------------
  6. .. versionadded:: 3.1
  7. Check once if Fortran source code can be built.
  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. Check once that the source supplied in ``<code>`` can be built. The result is
  15. stored in the internal cache variable specified by ``<resultVar>``, with
  16. boolean ``true`` for success and boolean ``false`` for failure.
  17. If ``FAIL_REGEX`` is provided, then failure is determined by checking
  18. if anything in the compiler output matches any of the specified regular
  19. expressions.
  20. By default, the test source file will be given a ``.F`` file extension. The
  21. ``SRC_EXT`` option can be used to override this with ``.<extension>`` instead--
  22. ``.F90`` is a typical choice.
  23. See also :command:`check_source_compiles` for a more general command syntax.
  24. See also :command:`check_source_runs` to run compiled source.
  25. Internally, :command:`try_compile` is used to compile the source. If
  26. :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` is set to ``EXECUTABLE`` (default),
  27. the source is compiled and linked as an executable program. If set to
  28. ``STATIC_LIBRARY``, the source is compiled but not linked. In any case, all
  29. functions must be declared as usual.
  30. The compile and link commands can be influenced by setting any of the
  31. following variables prior to calling ``check_fortran_source_compiles()``:
  32. .. include:: /module/CMAKE_REQUIRED_FLAGS.txt
  33. .. include:: /module/CMAKE_REQUIRED_DEFINITIONS.txt
  34. .. include:: /module/CMAKE_REQUIRED_INCLUDES.txt
  35. .. include:: /module/CMAKE_REQUIRED_LINK_OPTIONS.txt
  36. .. include:: /module/CMAKE_REQUIRED_LIBRARIES.txt
  37. .. include:: /module/CMAKE_REQUIRED_QUIET.txt
  38. #]=======================================================================]
  39. include_guard(GLOBAL)
  40. include(Internal/CheckSourceCompiles)
  41. macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR)
  42. # Pass the SRC_EXT we used by default historically.
  43. # A user-provided SRC_EXT argument in ARGN will override ours.
  44. cmake_check_source_compiles(Fortran "${SOURCE}" ${VAR} SRC_EXT "F" ${ARGN})
  45. endmacro()