CMakeFortranInformation.cmake 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. include(CMakeLanguageInformation)
  4. # This file sets the basic flags for the Fortran language in CMake.
  5. # It also loads the available platform file for the system-compiler
  6. # if it exists.
  7. set(_INCLUDED_FILE 0)
  8. # Load compiler-specific information.
  9. if(CMAKE_Fortran_COMPILER_ID)
  10. include(Compiler/${CMAKE_Fortran_COMPILER_ID}-Fortran OPTIONAL)
  11. endif()
  12. set(CMAKE_BASE_NAME)
  13. get_filename_component(CMAKE_BASE_NAME "${CMAKE_Fortran_COMPILER}" NAME_WE)
  14. # since the gnu compiler has several names force g++
  15. if(CMAKE_COMPILER_IS_GNUG77)
  16. set(CMAKE_BASE_NAME g77)
  17. endif()
  18. if(CMAKE_Fortran_COMPILER_ID)
  19. include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_Fortran_COMPILER_ID}-Fortran OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
  20. endif()
  21. if (NOT _INCLUDED_FILE)
  22. include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL
  23. RESULT_VARIABLE _INCLUDED_FILE)
  24. endif ()
  25. # load any compiler-wrapper specific information
  26. if (CMAKE_Fortran_COMPILER_WRAPPER)
  27. __cmake_include_compiler_wrapper(Fortran)
  28. endif ()
  29. # We specify the compiler information in the system file for some
  30. # platforms, but this language may not have been enabled when the file
  31. # was first included. Include it again to get the language info.
  32. # Remove this when all compiler info is removed from system files.
  33. if (NOT _INCLUDED_FILE)
  34. include(Platform/${CMAKE_SYSTEM_NAME} OPTIONAL)
  35. endif ()
  36. if(CMAKE_Fortran_SIZEOF_DATA_PTR)
  37. foreach(f IN LISTS CMAKE_Fortran_ABI_FILES)
  38. include(${f})
  39. endforeach()
  40. unset(CMAKE_Fortran_ABI_FILES)
  41. endif()
  42. # This should be included before the _INIT variables are
  43. # used to initialize the cache. Since the rule variables
  44. # have if blocks on them, users can still define them here.
  45. # But, it should still be after the platform file so changes can
  46. # be made to those values.
  47. if(CMAKE_USER_MAKE_RULES_OVERRIDE)
  48. # Save the full path of the file so try_compile can use it.
  49. include(${CMAKE_USER_MAKE_RULES_OVERRIDE} RESULT_VARIABLE _override)
  50. set(CMAKE_USER_MAKE_RULES_OVERRIDE "${_override}")
  51. endif()
  52. if(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran)
  53. # Save the full path of the file so try_compile can use it.
  54. include(${CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran} RESULT_VARIABLE _override)
  55. set(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran "${_override}")
  56. endif()
  57. set(CMAKE_VERBOSE_MAKEFILE FALSE CACHE BOOL "If this value is on, makefiles will be generated without the .SILENT directive, and all commands will be echoed to the console during the make. This is useful for debugging only. With Visual Studio IDE projects all commands are done without /nologo.")
  58. set(CMAKE_Fortran_FLAGS_INIT "$ENV{FFLAGS} ${CMAKE_Fortran_FLAGS_INIT}")
  59. cmake_initialize_per_config_variable(CMAKE_Fortran_FLAGS "Flags used by the Fortran compiler")
  60. if(NOT CMAKE_Fortran_COMPILER_LAUNCHER AND DEFINED ENV{CMAKE_Fortran_COMPILER_LAUNCHER})
  61. set(CMAKE_Fortran_COMPILER_LAUNCHER "$ENV{CMAKE_Fortran_COMPILER_LAUNCHER}"
  62. CACHE STRING "Compiler launcher for Fortran.")
  63. endif()
  64. include(CMakeCommonLanguageInclude)
  65. _cmake_common_language_platform_flags(Fortran)
  66. # now define the following rule variables
  67. # CMAKE_Fortran_CREATE_SHARED_LIBRARY
  68. # CMAKE_Fortran_CREATE_SHARED_MODULE
  69. # CMAKE_Fortran_COMPILE_OBJECT
  70. # CMAKE_Fortran_LINK_EXECUTABLE
  71. # create a Fortran shared library
  72. if(NOT CMAKE_Fortran_CREATE_SHARED_LIBRARY)
  73. set(CMAKE_Fortran_CREATE_SHARED_LIBRARY
  74. "<CMAKE_Fortran_COMPILER> <CMAKE_SHARED_LIBRARY_Fortran_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
  75. endif()
  76. # create a Fortran shared module just copy the shared library rule
  77. if(NOT CMAKE_Fortran_CREATE_SHARED_MODULE)
  78. set(CMAKE_Fortran_CREATE_SHARED_MODULE ${CMAKE_Fortran_CREATE_SHARED_LIBRARY})
  79. endif()
  80. # Create a static archive incrementally for large object file counts.
  81. # If CMAKE_Fortran_CREATE_STATIC_LIBRARY is set it will override these.
  82. if(NOT DEFINED CMAKE_Fortran_ARCHIVE_CREATE)
  83. set(CMAKE_Fortran_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")
  84. endif()
  85. if(NOT DEFINED CMAKE_Fortran_ARCHIVE_APPEND)
  86. set(CMAKE_Fortran_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
  87. endif()
  88. if(NOT DEFINED CMAKE_Fortran_ARCHIVE_FINISH)
  89. set(CMAKE_Fortran_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
  90. endif()
  91. # compile a Fortran file into an object file
  92. # (put -o after -c to workaround bug in at least one mpif77 wrapper)
  93. if(NOT CMAKE_Fortran_COMPILE_OBJECT)
  94. set(CMAKE_Fortran_COMPILE_OBJECT
  95. "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -c <SOURCE> -o <OBJECT>")
  96. endif()
  97. # link a fortran program
  98. if(NOT CMAKE_Fortran_LINK_EXECUTABLE)
  99. set(CMAKE_Fortran_LINK_EXECUTABLE
  100. "<CMAKE_Fortran_COMPILER> <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
  101. endif()
  102. if(CMAKE_Fortran_STANDARD_LIBRARIES_INIT)
  103. set(CMAKE_Fortran_STANDARD_LIBRARIES "${CMAKE_Fortran_STANDARD_LIBRARIES_INIT}"
  104. CACHE STRING "Libraries linked by default with all Fortran applications.")
  105. mark_as_advanced(CMAKE_Fortran_STANDARD_LIBRARIES)
  106. endif()
  107. set(CMAKE_Fortran_USE_LINKER_INFORMATION TRUE)
  108. # set this variable so we can avoid loading this more than once.
  109. set(CMAKE_Fortran_INFORMATION_LOADED 1)