CMakeFortranInformation.cmake 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. # This file sets the basic flags for the Fortran language in CMake.
  2. # It also loads the available platform file for the system-compiler
  3. # if it exists.
  4. GET_FILENAME_COMPONENT(CMAKE_BASE_NAME ${CMAKE_Fortran_COMPILER} NAME_WE)
  5. # since the gnu compiler has several names force g++
  6. IF(CMAKE_COMPILER_IS_GNUG77)
  7. SET(CMAKE_BASE_NAME g77)
  8. ENDIF(CMAKE_COMPILER_IS_GNUG77)
  9. IF(CMAKE_Fortran_COMPILER_ID)
  10. IF(EXISTS ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_Fortran_COMPILER_ID}-Fortran.cmake)
  11. SET(CMAKE_BASE_NAME ${CMAKE_Fortran_COMPILER_ID}-Fortran)
  12. ENDIF(EXISTS ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_Fortran_COMPILER_ID}-Fortran.cmake)
  13. ENDIF(CMAKE_Fortran_COMPILER_ID)
  14. SET(CMAKE_SYSTEM_AND_Fortran_COMPILER_INFO_FILE
  15. ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}.cmake)
  16. INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL)
  17. # This should be included before the _INIT variables are
  18. # used to initialize the cache. Since the rule variables
  19. # have if blocks on them, users can still define them here.
  20. # But, it should still be after the platform file so changes can
  21. # be made to those values.
  22. IF(CMAKE_USER_MAKE_RULES_OVERRIDE)
  23. INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE})
  24. ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE)
  25. IF(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran)
  26. INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran})
  27. ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran)
  28. # Fortran needs cmake to do a requires step during its build process to
  29. # catch any modules
  30. SET(CMAKE_NEEDS_REQUIRES_STEP_Fortran_FLAG 1)
  31. # Create a set of shared library variable specific to Fortran
  32. # For 90% of the systems, these are the same flags as the C versions
  33. # so if these are not set just copy the flags from the c version
  34. IF(NOT CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS)
  35. SET(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
  36. ENDIF(NOT CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS)
  37. IF(NOT CMAKE_SHARED_LIBRARY_Fortran_FLAGS)
  38. SET(CMAKE_SHARED_LIBRARY_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
  39. ENDIF(NOT CMAKE_SHARED_LIBRARY_Fortran_FLAGS)
  40. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
  41. SET(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
  42. ENDIF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
  43. IF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG)
  44. SET(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
  45. ENDIF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG)
  46. IF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP)
  47. SET(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
  48. ENDIF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP)
  49. IF(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG)
  50. SET(CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
  51. ENDIF(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG)
  52. # repeat for modules
  53. IF(NOT CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS)
  54. SET(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS})
  55. ENDIF(NOT CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS)
  56. IF(NOT CMAKE_SHARED_MODULE_Fortran_FLAGS)
  57. SET(CMAKE_SHARED_MODULE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS})
  58. ENDIF(NOT CMAKE_SHARED_MODULE_Fortran_FLAGS)
  59. IF(NOT CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG)
  60. SET(CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_MODULE_RUNTIME_C_FLAG})
  61. ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG)
  62. IF(NOT CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG_SEP)
  63. SET(CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_MODULE_RUNTIME_C_FLAG_SEP})
  64. ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG_SEP)
  65. IF(NOT CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG)
  66. SET(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG})
  67. ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG)
  68. IF(NOT CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP)
  69. SET(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP})
  70. ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP)
  71. IF(NOT CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG)
  72. SET(CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG})
  73. ENDIF(NOT CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG)
  74. IF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH)
  75. SET(CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH})
  76. ENDIF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH)
  77. IF(NOT CMAKE_INCLUDE_FLAG_Fortran)
  78. SET(CMAKE_INCLUDE_FLAG_Fortran ${CMAKE_INCLUDE_FLAG_C})
  79. ENDIF(NOT CMAKE_INCLUDE_FLAG_Fortran)
  80. IF(NOT CMAKE_INCLUDE_FLAG_SEP_Fortran)
  81. SET(CMAKE_INCLUDE_FLAG_SEP_Fortran ${CMAKE_INCLUDE_FLAG_SEP_C})
  82. ENDIF(NOT CMAKE_INCLUDE_FLAG_SEP_Fortran)
  83. 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.")
  84. SET (CMAKE_Fortran_FLAGS "$ENV{FFLAGS}" CACHE STRING
  85. "Flags for Fortran compiler.")
  86. IF (CMAKE_Fortran_FLAGS_INIT)
  87. SET (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${CMAKE_Fortran_FLAGS_INIT}")
  88. ENDIF (CMAKE_Fortran_FLAGS_INIT)
  89. INCLUDE(CMakeCommonLanguageInclude)
  90. # now define the following rule variables
  91. # CMAKE_Fortran_CREATE_SHARED_LIBRARY
  92. # CMAKE_Fortran_CREATE_SHARED_MODULE
  93. # CMAKE_Fortran_CREATE_STATIC_LIBRARY
  94. # CMAKE_Fortran_COMPILE_OBJECT
  95. # CMAKE_Fortran_LINK_EXECUTABLE
  96. # create a Fortran shared library
  97. IF(NOT CMAKE_Fortran_CREATE_SHARED_LIBRARY)
  98. SET(CMAKE_Fortran_CREATE_SHARED_LIBRARY
  99. "<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>")
  100. ENDIF(NOT CMAKE_Fortran_CREATE_SHARED_LIBRARY)
  101. # create a Fortran shared module just copy the shared library rule
  102. IF(NOT CMAKE_Fortran_CREATE_SHARED_MODULE)
  103. SET(CMAKE_Fortran_CREATE_SHARED_MODULE ${CMAKE_Fortran_CREATE_SHARED_LIBRARY})
  104. ENDIF(NOT CMAKE_Fortran_CREATE_SHARED_MODULE)
  105. # create a Fortran static library
  106. IF(NOT CMAKE_Fortran_CREATE_STATIC_LIBRARY)
  107. SET(CMAKE_Fortran_CREATE_STATIC_LIBRARY
  108. "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS> "
  109. "<CMAKE_RANLIB> <TARGET> ")
  110. ENDIF(NOT CMAKE_Fortran_CREATE_STATIC_LIBRARY)
  111. # compile a Fortran file into an object file
  112. IF(NOT CMAKE_Fortran_COMPILE_OBJECT)
  113. SET(CMAKE_Fortran_COMPILE_OBJECT
  114. "<CMAKE_Fortran_COMPILER> -o <OBJECT> <DEFINES> <FLAGS> -c <SOURCE>")
  115. ENDIF(NOT CMAKE_Fortran_COMPILE_OBJECT)
  116. # link a fortran program
  117. IF(NOT CMAKE_Fortran_LINK_EXECUTABLE)
  118. SET(CMAKE_Fortran_LINK_EXECUTABLE
  119. "<CMAKE_Fortran_COMPILER> <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
  120. ENDIF(NOT CMAKE_Fortran_LINK_EXECUTABLE)
  121. IF(CMAKE_Fortran_STANDARD_LIBRARIES_INIT)
  122. SET(CMAKE_Fortran_STANDARD_LIBRARIES "${CMAKE_Fortran_STANDARD_LIBRARIES_INIT}"
  123. CACHE STRING "Libraries linked by defalut with all Fortran applications.")
  124. MARK_AS_ADVANCED(CMAKE_Fortran_STANDARD_LIBRARIES)
  125. ENDIF(CMAKE_Fortran_STANDARD_LIBRARIES_INIT)
  126. IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
  127. SET (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG_INIT}" CACHE STRING
  128. "Flags used by the compiler during debug builds.")
  129. SET (CMAKE_Fortran_FLAGS_MINSIZEREL "${CMAKE_Fortran_FLAGS_MINSIZEREL_INIT}" CACHE STRING
  130. "Flags used by the compiler during release minsize builds.")
  131. SET (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE_INIT}" CACHE STRING
  132. "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).")
  133. SET (CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
  134. "Flags used by the compiler during Release with Debug Info builds.")
  135. ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
  136. MARK_AS_ADVANCED(
  137. CMAKE_Fortran_FLAGS
  138. CMAKE_Fortran_FLAGS_DEBUG
  139. CMAKE_Fortran_FLAGS_MINSIZEREL
  140. CMAKE_Fortran_FLAGS_RELEASE
  141. CMAKE_Fortran_FLAGS_RELWITHDEBINFO)
  142. # set this variable so we can avoid loading this more than once.
  143. SET(CMAKE_Fortran_INFORMATION_LOADED 1)