CMakeFortranInformation.cmake 9.2 KB

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