CMakeFortranInformation.cmake 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #=============================================================================
  2. # Copyright 2004-2011 Kitware, Inc.
  3. #
  4. # Distributed under the OSI-approved BSD License (the "License");
  5. # see accompanying file Copyright.txt for details.
  6. #
  7. # This software is distributed WITHOUT ANY WARRANTY; without even the
  8. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. # See the License for more information.
  10. #=============================================================================
  11. # (To distribute this file outside of CMake, substitute the full
  12. # License text for the above reference.)
  13. # This file sets the basic flags for the Fortran language in CMake.
  14. # It also loads the available platform file for the system-compiler
  15. # if it exists.
  16. SET(_INCLUDED_FILE 0)
  17. # Load compiler-specific information.
  18. IF(CMAKE_Fortran_COMPILER_ID)
  19. INCLUDE(Compiler/${CMAKE_Fortran_COMPILER_ID}-Fortran OPTIONAL)
  20. ENDIF(CMAKE_Fortran_COMPILER_ID)
  21. SET(CMAKE_BASE_NAME)
  22. GET_FILENAME_COMPONENT(CMAKE_BASE_NAME ${CMAKE_Fortran_COMPILER} NAME_WE)
  23. # since the gnu compiler has several names force g++
  24. IF(CMAKE_COMPILER_IS_GNUG77)
  25. SET(CMAKE_BASE_NAME g77)
  26. ENDIF(CMAKE_COMPILER_IS_GNUG77)
  27. IF(CMAKE_Fortran_COMPILER_ID)
  28. INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_Fortran_COMPILER_ID}-Fortran OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
  29. ENDIF(CMAKE_Fortran_COMPILER_ID)
  30. IF (NOT _INCLUDED_FILE)
  31. INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL
  32. RESULT_VARIABLE _INCLUDED_FILE)
  33. ENDIF (NOT _INCLUDED_FILE)
  34. # We specify the compiler information in the system file for some
  35. # platforms, but this language may not have been enabled when the file
  36. # was first included. Include it again to get the language info.
  37. # Remove this when all compiler info is removed from system files.
  38. IF (NOT _INCLUDED_FILE)
  39. INCLUDE(Platform/${CMAKE_SYSTEM_NAME} OPTIONAL)
  40. ENDIF (NOT _INCLUDED_FILE)
  41. IF(CMAKE_Fortran_SIZEOF_DATA_PTR)
  42. FOREACH(f ${CMAKE_Fortran_ABI_FILES})
  43. INCLUDE(${f})
  44. ENDFOREACH()
  45. UNSET(CMAKE_Fortran_ABI_FILES)
  46. ENDIF()
  47. # This should be included before the _INIT variables are
  48. # used to initialize the cache. Since the rule variables
  49. # have if blocks on them, users can still define them here.
  50. # But, it should still be after the platform file so changes can
  51. # be made to those values.
  52. IF(CMAKE_USER_MAKE_RULES_OVERRIDE)
  53. # Save the full path of the file so try_compile can use it.
  54. INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE} RESULT_VARIABLE _override)
  55. SET(CMAKE_USER_MAKE_RULES_OVERRIDE "${_override}")
  56. ENDIF()
  57. IF(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran)
  58. # Save the full path of the file so try_compile can use it.
  59. INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran} RESULT_VARIABLE _override)
  60. SET(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran "${_override}")
  61. ENDIF()
  62. # Fortran needs cmake to do a requires step during its build process to
  63. # catch any modules
  64. SET(CMAKE_NEEDS_REQUIRES_STEP_Fortran_FLAG 1)
  65. # Create a set of shared library variable specific to Fortran
  66. # For 90% of the systems, these are the same flags as the C versions
  67. # so if these are not set just copy the flags from the c version
  68. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS)
  69. SET(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
  70. ENDIF()
  71. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_Fortran_FLAGS)
  72. SET(CMAKE_SHARED_LIBRARY_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
  73. ENDIF()
  74. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
  75. SET(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
  76. ENDIF()
  77. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG)
  78. SET(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
  79. ENDIF()
  80. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP)
  81. SET(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
  82. ENDIF()
  83. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG)
  84. SET(CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
  85. ENDIF()
  86. IF(NOT DEFINED CMAKE_EXE_EXPORTS_Fortran_FLAG)
  87. SET(CMAKE_EXE_EXPORTS_Fortran_FLAG ${CMAKE_EXE_EXPORTS_C_FLAG})
  88. ENDIF()
  89. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG)
  90. SET(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG})
  91. ENDIF()
  92. # for most systems a module is the same as a shared library
  93. # so unless the variable CMAKE_MODULE_EXISTS is set just
  94. # copy the values from the LIBRARY variables
  95. IF(NOT CMAKE_MODULE_EXISTS)
  96. SET(CMAKE_SHARED_MODULE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_Fortran_FLAGS})
  97. SET(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS})
  98. ENDIF(NOT CMAKE_MODULE_EXISTS)
  99. # repeat for modules
  100. IF(NOT DEFINED CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS)
  101. SET(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS})
  102. ENDIF()
  103. IF(NOT DEFINED CMAKE_SHARED_MODULE_Fortran_FLAGS)
  104. SET(CMAKE_SHARED_MODULE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS})
  105. ENDIF()
  106. IF(NOT DEFINED CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG)
  107. SET(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG})
  108. ENDIF()
  109. IF(NOT DEFINED CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP)
  110. SET(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP})
  111. ENDIF()
  112. IF(NOT DEFINED CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG)
  113. SET(CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG})
  114. ENDIF()
  115. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH)
  116. SET(CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH})
  117. ENDIF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH)
  118. IF(NOT CMAKE_INCLUDE_FLAG_Fortran)
  119. SET(CMAKE_INCLUDE_FLAG_Fortran ${CMAKE_INCLUDE_FLAG_C})
  120. ENDIF(NOT CMAKE_INCLUDE_FLAG_Fortran)
  121. IF(NOT CMAKE_INCLUDE_FLAG_SEP_Fortran)
  122. SET(CMAKE_INCLUDE_FLAG_SEP_Fortran ${CMAKE_INCLUDE_FLAG_SEP_C})
  123. ENDIF(NOT CMAKE_INCLUDE_FLAG_SEP_Fortran)
  124. 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.")
  125. SET(CMAKE_Fortran_FLAGS_INIT "$ENV{FFLAGS} ${CMAKE_Fortran_FLAGS_INIT}")
  126. # avoid just having a space as the initial value for the cache
  127. IF(CMAKE_Fortran_FLAGS_INIT STREQUAL " ")
  128. SET(CMAKE_Fortran_FLAGS_INIT)
  129. ENDIF(CMAKE_Fortran_FLAGS_INIT STREQUAL " ")
  130. SET (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_INIT}" CACHE STRING
  131. "Flags for Fortran compiler.")
  132. INCLUDE(CMakeCommonLanguageInclude)
  133. # now define the following rule variables
  134. # CMAKE_Fortran_CREATE_SHARED_LIBRARY
  135. # CMAKE_Fortran_CREATE_SHARED_MODULE
  136. # CMAKE_Fortran_COMPILE_OBJECT
  137. # CMAKE_Fortran_LINK_EXECUTABLE
  138. # create a Fortran shared library
  139. IF(NOT CMAKE_Fortran_CREATE_SHARED_LIBRARY)
  140. SET(CMAKE_Fortran_CREATE_SHARED_LIBRARY
  141. "<CMAKE_Fortran_COMPILER> <CMAKE_SHARED_LIBRARY_Fortran_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
  142. ENDIF(NOT CMAKE_Fortran_CREATE_SHARED_LIBRARY)
  143. # create a Fortran shared module just copy the shared library rule
  144. IF(NOT CMAKE_Fortran_CREATE_SHARED_MODULE)
  145. SET(CMAKE_Fortran_CREATE_SHARED_MODULE ${CMAKE_Fortran_CREATE_SHARED_LIBRARY})
  146. ENDIF(NOT CMAKE_Fortran_CREATE_SHARED_MODULE)
  147. # Create a static archive incrementally for large object file counts.
  148. # If CMAKE_Fortran_CREATE_STATIC_LIBRARY is set it will override these.
  149. IF(NOT DEFINED CMAKE_Fortran_ARCHIVE_CREATE)
  150. SET(CMAKE_Fortran_ARCHIVE_CREATE "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS>")
  151. ENDIF()
  152. IF(NOT DEFINED CMAKE_Fortran_ARCHIVE_APPEND)
  153. SET(CMAKE_Fortran_ARCHIVE_APPEND "<CMAKE_AR> r <TARGET> <LINK_FLAGS> <OBJECTS>")
  154. ENDIF()
  155. IF(NOT DEFINED CMAKE_Fortran_ARCHIVE_FINISH)
  156. SET(CMAKE_Fortran_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
  157. ENDIF()
  158. # compile a Fortran file into an object file
  159. # (put -o after -c to workaround bug in at least one mpif77 wrapper)
  160. IF(NOT CMAKE_Fortran_COMPILE_OBJECT)
  161. SET(CMAKE_Fortran_COMPILE_OBJECT
  162. "<CMAKE_Fortran_COMPILER> <DEFINES> <FLAGS> -c <SOURCE> -o <OBJECT>")
  163. ENDIF(NOT CMAKE_Fortran_COMPILE_OBJECT)
  164. # link a fortran program
  165. IF(NOT CMAKE_Fortran_LINK_EXECUTABLE)
  166. SET(CMAKE_Fortran_LINK_EXECUTABLE
  167. "<CMAKE_Fortran_COMPILER> <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
  168. ENDIF(NOT CMAKE_Fortran_LINK_EXECUTABLE)
  169. IF(CMAKE_Fortran_STANDARD_LIBRARIES_INIT)
  170. SET(CMAKE_Fortran_STANDARD_LIBRARIES "${CMAKE_Fortran_STANDARD_LIBRARIES_INIT}"
  171. CACHE STRING "Libraries linked by defalut with all Fortran applications.")
  172. MARK_AS_ADVANCED(CMAKE_Fortran_STANDARD_LIBRARIES)
  173. ENDIF(CMAKE_Fortran_STANDARD_LIBRARIES_INIT)
  174. IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
  175. SET (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG_INIT}" CACHE STRING
  176. "Flags used by the compiler during debug builds.")
  177. SET (CMAKE_Fortran_FLAGS_MINSIZEREL "${CMAKE_Fortran_FLAGS_MINSIZEREL_INIT}" CACHE STRING
  178. "Flags used by the compiler during release minsize builds.")
  179. SET (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE_INIT}" CACHE STRING
  180. "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).")
  181. SET (CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
  182. "Flags used by the compiler during Release with Debug Info builds.")
  183. ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
  184. MARK_AS_ADVANCED(
  185. CMAKE_Fortran_FLAGS
  186. CMAKE_Fortran_FLAGS_DEBUG
  187. CMAKE_Fortran_FLAGS_MINSIZEREL
  188. CMAKE_Fortran_FLAGS_RELEASE
  189. CMAKE_Fortran_FLAGS_RELWITHDEBINFO)
  190. # set this variable so we can avoid loading this more than once.
  191. SET(CMAKE_Fortran_INFORMATION_LOADED 1)