CMakeFortranInformation.cmake 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 ${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. if(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIC)
  58. set(CMAKE_Fortran_COMPILE_OPTIONS_PIC ${CMAKE_C_COMPILE_OPTIONS_PIC})
  59. endif()
  60. if(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIE)
  61. set(CMAKE_Fortran_COMPILE_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE})
  62. endif()
  63. if(NOT CMAKE_Fortran_LINK_OPTIONS_PIE)
  64. set(CMAKE_Fortran_LINK_OPTIONS_PIE ${CMAKE_C_LINK_OPTIONS_PIE})
  65. endif()
  66. if(NOT CMAKE_Fortran_LINK_OPTIONS_NO_PIE)
  67. set(CMAKE_Fortran_LINK_OPTIONS_NO_PIE ${CMAKE_C_LINK_OPTIONS_NO_PIE})
  68. endif()
  69. if(NOT CMAKE_Fortran_COMPILE_OPTIONS_DLL)
  70. set(CMAKE_Fortran_COMPILE_OPTIONS_DLL ${CMAKE_C_COMPILE_OPTIONS_DLL})
  71. endif()
  72. # Create a set of shared library variable specific to Fortran
  73. # For 90% of the systems, these are the same flags as the C versions
  74. # so if these are not set just copy the flags from the c version
  75. if(NOT DEFINED CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS)
  76. set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
  77. endif()
  78. if(NOT DEFINED CMAKE_SHARED_LIBRARY_Fortran_FLAGS)
  79. set(CMAKE_SHARED_LIBRARY_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
  80. endif()
  81. if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
  82. set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
  83. endif()
  84. if(NOT DEFINED CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG)
  85. set(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
  86. endif()
  87. if(NOT DEFINED CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP)
  88. set(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
  89. endif()
  90. if(NOT DEFINED CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG)
  91. set(CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
  92. endif()
  93. if(NOT DEFINED CMAKE_EXE_EXPORTS_Fortran_FLAG)
  94. set(CMAKE_EXE_EXPORTS_Fortran_FLAG ${CMAKE_EXE_EXPORTS_C_FLAG})
  95. endif()
  96. if(NOT DEFINED CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG)
  97. set(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG})
  98. endif()
  99. # for most systems a module is the same as a shared library
  100. # so unless the variable CMAKE_MODULE_EXISTS is set just
  101. # copy the values from the LIBRARY variables
  102. if(NOT CMAKE_MODULE_EXISTS)
  103. set(CMAKE_SHARED_MODULE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_Fortran_FLAGS})
  104. set(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS})
  105. endif()
  106. # repeat for modules
  107. if(NOT DEFINED CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS)
  108. set(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS})
  109. endif()
  110. if(NOT DEFINED CMAKE_SHARED_MODULE_Fortran_FLAGS)
  111. set(CMAKE_SHARED_MODULE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS})
  112. endif()
  113. if(NOT DEFINED CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG)
  114. set(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG})
  115. endif()
  116. if(NOT DEFINED CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP)
  117. set(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP})
  118. endif()
  119. if(NOT DEFINED CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG)
  120. set(CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG})
  121. endif()
  122. if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH)
  123. set(CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH})
  124. endif()
  125. if(NOT CMAKE_INCLUDE_FLAG_Fortran)
  126. set(CMAKE_INCLUDE_FLAG_Fortran ${CMAKE_INCLUDE_FLAG_C})
  127. endif()
  128. 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.")
  129. set(CMAKE_Fortran_FLAGS_INIT "$ENV{FFLAGS} ${CMAKE_Fortran_FLAGS_INIT}")
  130. cmake_initialize_per_config_variable(CMAKE_Fortran_FLAGS "Flags used by the Fortran compiler")
  131. include(CMakeCommonLanguageInclude)
  132. # now define the following rule variables
  133. # CMAKE_Fortran_CREATE_SHARED_LIBRARY
  134. # CMAKE_Fortran_CREATE_SHARED_MODULE
  135. # CMAKE_Fortran_COMPILE_OBJECT
  136. # CMAKE_Fortran_LINK_EXECUTABLE
  137. # create a Fortran shared library
  138. if(NOT CMAKE_Fortran_CREATE_SHARED_LIBRARY)
  139. set(CMAKE_Fortran_CREATE_SHARED_LIBRARY
  140. "<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>")
  141. endif()
  142. # create a Fortran shared module just copy the shared library rule
  143. if(NOT CMAKE_Fortran_CREATE_SHARED_MODULE)
  144. set(CMAKE_Fortran_CREATE_SHARED_MODULE ${CMAKE_Fortran_CREATE_SHARED_LIBRARY})
  145. endif()
  146. # Create a static archive incrementally for large object file counts.
  147. # If CMAKE_Fortran_CREATE_STATIC_LIBRARY is set it will override these.
  148. if(NOT DEFINED CMAKE_Fortran_ARCHIVE_CREATE)
  149. set(CMAKE_Fortran_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")
  150. endif()
  151. if(NOT DEFINED CMAKE_Fortran_ARCHIVE_APPEND)
  152. set(CMAKE_Fortran_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
  153. endif()
  154. if(NOT DEFINED CMAKE_Fortran_ARCHIVE_FINISH)
  155. set(CMAKE_Fortran_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
  156. endif()
  157. # compile a Fortran file into an object file
  158. # (put -o after -c to workaround bug in at least one mpif77 wrapper)
  159. if(NOT CMAKE_Fortran_COMPILE_OBJECT)
  160. set(CMAKE_Fortran_COMPILE_OBJECT
  161. "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -c <SOURCE> -o <OBJECT>")
  162. endif()
  163. # link a fortran program
  164. if(NOT CMAKE_Fortran_LINK_EXECUTABLE)
  165. set(CMAKE_Fortran_LINK_EXECUTABLE
  166. "<CMAKE_Fortran_COMPILER> <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
  167. endif()
  168. if(CMAKE_Fortran_STANDARD_LIBRARIES_INIT)
  169. set(CMAKE_Fortran_STANDARD_LIBRARIES "${CMAKE_Fortran_STANDARD_LIBRARIES_INIT}"
  170. CACHE STRING "Libraries linked by default with all Fortran applications.")
  171. mark_as_advanced(CMAKE_Fortran_STANDARD_LIBRARIES)
  172. endif()
  173. # set this variable so we can avoid loading this more than once.
  174. set(CMAKE_Fortran_INFORMATION_LOADED 1)