CMakeFortranInformation.cmake 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. # This should be included before the _INIT variables are
  42. # used to initialize the cache. Since the rule variables
  43. # have if blocks on them, users can still define them here.
  44. # But, it should still be after the platform file so changes can
  45. # be made to those values.
  46. IF(CMAKE_USER_MAKE_RULES_OVERRIDE)
  47. # Save the full path of the file so try_compile can use it.
  48. INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE} RESULT_VARIABLE _override)
  49. SET(CMAKE_USER_MAKE_RULES_OVERRIDE "${_override}")
  50. ENDIF()
  51. IF(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran)
  52. # Save the full path of the file so try_compile can use it.
  53. INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran} RESULT_VARIABLE _override)
  54. SET(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran "${_override}")
  55. ENDIF()
  56. # Fortran needs cmake to do a requires step during its build process to
  57. # catch any modules
  58. SET(CMAKE_NEEDS_REQUIRES_STEP_Fortran_FLAG 1)
  59. # Create a set of shared library variable specific to Fortran
  60. # For 90% of the systems, these are the same flags as the C versions
  61. # so if these are not set just copy the flags from the c version
  62. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS)
  63. SET(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
  64. ENDIF()
  65. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_Fortran_FLAGS)
  66. SET(CMAKE_SHARED_LIBRARY_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
  67. ENDIF()
  68. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
  69. SET(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
  70. ENDIF()
  71. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG)
  72. SET(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
  73. ENDIF()
  74. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP)
  75. SET(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
  76. ENDIF()
  77. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG)
  78. SET(CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
  79. ENDIF()
  80. IF(NOT DEFINED CMAKE_EXE_EXPORTS_Fortran_FLAG)
  81. SET(CMAKE_EXE_EXPORTS_Fortran_FLAG ${CMAKE_EXE_EXPORTS_C_FLAG})
  82. ENDIF()
  83. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG)
  84. SET(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG})
  85. ENDIF()
  86. # repeat for modules
  87. IF(NOT DEFINED CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS)
  88. SET(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS})
  89. ENDIF()
  90. IF(NOT DEFINED CMAKE_SHARED_MODULE_Fortran_FLAGS)
  91. SET(CMAKE_SHARED_MODULE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS})
  92. ENDIF()
  93. IF(NOT DEFINED CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG)
  94. SET(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG})
  95. ENDIF()
  96. IF(NOT DEFINED CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP)
  97. SET(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP})
  98. ENDIF()
  99. IF(NOT DEFINED CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG)
  100. SET(CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG})
  101. ENDIF()
  102. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH)
  103. SET(CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH})
  104. ENDIF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH)
  105. IF(NOT CMAKE_INCLUDE_FLAG_Fortran)
  106. SET(CMAKE_INCLUDE_FLAG_Fortran ${CMAKE_INCLUDE_FLAG_C})
  107. ENDIF(NOT CMAKE_INCLUDE_FLAG_Fortran)
  108. IF(NOT CMAKE_INCLUDE_FLAG_SEP_Fortran)
  109. SET(CMAKE_INCLUDE_FLAG_SEP_Fortran ${CMAKE_INCLUDE_FLAG_SEP_C})
  110. ENDIF(NOT CMAKE_INCLUDE_FLAG_SEP_Fortran)
  111. 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.")
  112. SET(CMAKE_Fortran_FLAGS_INIT "$ENV{FFLAGS} ${CMAKE_Fortran_FLAGS_INIT}")
  113. # avoid just having a space as the initial value for the cache
  114. IF(CMAKE_Fortran_FLAGS_INIT STREQUAL " ")
  115. SET(CMAKE_Fortran_FLAGS_INIT)
  116. ENDIF(CMAKE_Fortran_FLAGS_INIT STREQUAL " ")
  117. SET (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_INIT}" CACHE STRING
  118. "Flags for Fortran compiler.")
  119. INCLUDE(CMakeCommonLanguageInclude)
  120. # now define the following rule variables
  121. # CMAKE_Fortran_CREATE_SHARED_LIBRARY
  122. # CMAKE_Fortran_CREATE_SHARED_MODULE
  123. # CMAKE_Fortran_COMPILE_OBJECT
  124. # CMAKE_Fortran_LINK_EXECUTABLE
  125. # create a Fortran shared library
  126. IF(NOT CMAKE_Fortran_CREATE_SHARED_LIBRARY)
  127. SET(CMAKE_Fortran_CREATE_SHARED_LIBRARY
  128. "<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>")
  129. ENDIF(NOT CMAKE_Fortran_CREATE_SHARED_LIBRARY)
  130. # create a Fortran shared module just copy the shared library rule
  131. IF(NOT CMAKE_Fortran_CREATE_SHARED_MODULE)
  132. SET(CMAKE_Fortran_CREATE_SHARED_MODULE ${CMAKE_Fortran_CREATE_SHARED_LIBRARY})
  133. ENDIF(NOT CMAKE_Fortran_CREATE_SHARED_MODULE)
  134. # Create a static archive incrementally for large object file counts.
  135. # If CMAKE_Fortran_CREATE_STATIC_LIBRARY is set it will override these.
  136. IF(NOT DEFINED CMAKE_Fortran_ARCHIVE_CREATE)
  137. SET(CMAKE_Fortran_ARCHIVE_CREATE "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS>")
  138. ENDIF()
  139. IF(NOT DEFINED CMAKE_Fortran_ARCHIVE_APPEND)
  140. SET(CMAKE_Fortran_ARCHIVE_APPEND "<CMAKE_AR> r <TARGET> <LINK_FLAGS> <OBJECTS>")
  141. ENDIF()
  142. IF(NOT DEFINED CMAKE_Fortran_ARCHIVE_FINISH)
  143. SET(CMAKE_Fortran_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
  144. ENDIF()
  145. # compile a Fortran file into an object file
  146. IF(NOT CMAKE_Fortran_COMPILE_OBJECT)
  147. SET(CMAKE_Fortran_COMPILE_OBJECT
  148. "<CMAKE_Fortran_COMPILER> -o <OBJECT> <DEFINES> <FLAGS> -c <SOURCE>")
  149. ENDIF(NOT CMAKE_Fortran_COMPILE_OBJECT)
  150. # link a fortran program
  151. IF(NOT CMAKE_Fortran_LINK_EXECUTABLE)
  152. SET(CMAKE_Fortran_LINK_EXECUTABLE
  153. "<CMAKE_Fortran_COMPILER> <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
  154. ENDIF(NOT CMAKE_Fortran_LINK_EXECUTABLE)
  155. IF(CMAKE_Fortran_STANDARD_LIBRARIES_INIT)
  156. SET(CMAKE_Fortran_STANDARD_LIBRARIES "${CMAKE_Fortran_STANDARD_LIBRARIES_INIT}"
  157. CACHE STRING "Libraries linked by defalut with all Fortran applications.")
  158. MARK_AS_ADVANCED(CMAKE_Fortran_STANDARD_LIBRARIES)
  159. ENDIF(CMAKE_Fortran_STANDARD_LIBRARIES_INIT)
  160. IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
  161. SET (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG_INIT}" CACHE STRING
  162. "Flags used by the compiler during debug builds.")
  163. SET (CMAKE_Fortran_FLAGS_MINSIZEREL "${CMAKE_Fortran_FLAGS_MINSIZEREL_INIT}" CACHE STRING
  164. "Flags used by the compiler during release minsize builds.")
  165. SET (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE_INIT}" CACHE STRING
  166. "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).")
  167. SET (CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
  168. "Flags used by the compiler during Release with Debug Info builds.")
  169. ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
  170. MARK_AS_ADVANCED(
  171. CMAKE_Fortran_FLAGS
  172. CMAKE_Fortran_FLAGS_DEBUG
  173. CMAKE_Fortran_FLAGS_MINSIZEREL
  174. CMAKE_Fortran_FLAGS_RELEASE
  175. CMAKE_Fortran_FLAGS_RELWITHDEBINFO)
  176. # set this variable so we can avoid loading this more than once.
  177. SET(CMAKE_Fortran_INFORMATION_LOADED 1)