Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Modules / CMakeFortranInformation.cmake
blob25ebe21e31449db475db8043f66dd10fede0f092
2 # This file sets the basic flags for the Fortran language in CMake.
3 # It also loads the available platform file for the system-compiler
4 # if it exists.
6 SET(CMAKE_BASE_NAME)
7 GET_FILENAME_COMPONENT(CMAKE_BASE_NAME ${CMAKE_Fortran_COMPILER} NAME_WE)
8 # since the gnu compiler has several names force g++
9 IF(CMAKE_COMPILER_IS_GNUG77)
10   SET(CMAKE_BASE_NAME g77)
11 ENDIF(CMAKE_COMPILER_IS_GNUG77)
12 IF(CMAKE_Fortran_COMPILER_ID)
13   IF(EXISTS ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_Fortran_COMPILER_ID}-Fortran.cmake)
14     SET(CMAKE_BASE_NAME ${CMAKE_Fortran_COMPILER_ID}-Fortran)
15   ENDIF(EXISTS ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_Fortran_COMPILER_ID}-Fortran.cmake)
16 ENDIF(CMAKE_Fortran_COMPILER_ID)
17 SET(CMAKE_SYSTEM_AND_Fortran_COMPILER_INFO_FILE
18   ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}.cmake)
19 INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL)
21 # This should be included before the _INIT variables are
22 # used to initialize the cache.  Since the rule variables 
23 # have if blocks on them, users can still define them here.
24 # But, it should still be after the platform file so changes can
25 # be made to those values.
27 IF(CMAKE_USER_MAKE_RULES_OVERRIDE)
28    INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE})
29 ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE)
31 IF(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran)
32    INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran})
33 ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran)
36 # Fortran needs cmake to do a requires step during its build process to 
37 # catch any modules
38 SET(CMAKE_NEEDS_REQUIRES_STEP_Fortran_FLAG 1)
40 # Create a set of shared library variable specific to Fortran
41 # For 90% of the systems, these are the same flags as the C versions
42 # so if these are not set just copy the flags from the c version
43 IF(NOT CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS)
44   SET(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
45 ENDIF(NOT CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS)
47 IF(NOT CMAKE_SHARED_LIBRARY_Fortran_FLAGS)
48   SET(CMAKE_SHARED_LIBRARY_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
49 ENDIF(NOT CMAKE_SHARED_LIBRARY_Fortran_FLAGS)
51 IF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
52   SET(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
53 ENDIF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
55 IF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG)
56   SET(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG}) 
57 ENDIF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG)
59 IF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP)
60   SET(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
61 ENDIF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP)
63 IF(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG)
64   SET(CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
65 ENDIF(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG)
67 # repeat for modules
68 IF(NOT CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS)
69   SET(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS})
70 ENDIF(NOT CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS)
72 IF(NOT CMAKE_SHARED_MODULE_Fortran_FLAGS)
73   SET(CMAKE_SHARED_MODULE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS})
74 ENDIF(NOT CMAKE_SHARED_MODULE_Fortran_FLAGS)
76 IF(NOT CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG)
77   SET(CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_MODULE_RUNTIME_C_FLAG}) 
78 ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG)
80 IF(NOT CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG_SEP)
81   SET(CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_MODULE_RUNTIME_C_FLAG_SEP})
82 ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG_SEP)
84 IF(NOT CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG)
85   SET(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG})
86 ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG)
88 IF(NOT CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP)
89   SET(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP})
90 ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP)
92 IF(NOT CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG)
93   SET(CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG})
94 ENDIF(NOT CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG)
96 IF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH)
97   SET(CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH})
98 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)
104 IF(NOT CMAKE_INCLUDE_FLAG_SEP_Fortran)
105   SET(CMAKE_INCLUDE_FLAG_SEP_Fortran ${CMAKE_INCLUDE_FLAG_SEP_C})
106 ENDIF(NOT CMAKE_INCLUDE_FLAG_SEP_Fortran)
108 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.")
110 SET(CMAKE_Fortran_FLAGS_INIT "$ENV{FFLAGS} ${CMAKE_Fortran_FLAGS_INIT}")
111 # avoid just having a space as the initial value for the cache 
112 IF(CMAKE_Fortran_FLAGS_INIT STREQUAL " ")
113   SET(CMAKE_Fortran_FLAGS_INIT)
114 ENDIF(CMAKE_Fortran_FLAGS_INIT STREQUAL " ")
115 SET (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_INIT}" CACHE STRING
116      "Flags for Fortran compiler.")
118 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
126 # create a Fortran shared library
127 IF(NOT CMAKE_Fortran_CREATE_SHARED_LIBRARY)
128   SET(CMAKE_Fortran_CREATE_SHARED_LIBRARY
129       "<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>")
130 ENDIF(NOT CMAKE_Fortran_CREATE_SHARED_LIBRARY)
132 # create a Fortran shared module just copy the shared library rule
133 IF(NOT CMAKE_Fortran_CREATE_SHARED_MODULE)
134   SET(CMAKE_Fortran_CREATE_SHARED_MODULE ${CMAKE_Fortran_CREATE_SHARED_LIBRARY})
135 ENDIF(NOT CMAKE_Fortran_CREATE_SHARED_MODULE)
137 # Create a static archive incrementally for large object file counts.
138 # If CMAKE_Fortran_CREATE_STATIC_LIBRARY is set it will override these.
139 SET(CMAKE_Fortran_ARCHIVE_CREATE "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS>")
140 SET(CMAKE_Fortran_ARCHIVE_APPEND "<CMAKE_AR> r  <TARGET> <LINK_FLAGS> <OBJECTS>")
141 SET(CMAKE_Fortran_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
143 # compile a Fortran file into an object file
144 IF(NOT CMAKE_Fortran_COMPILE_OBJECT)
145   SET(CMAKE_Fortran_COMPILE_OBJECT
146     "<CMAKE_Fortran_COMPILER> -o <OBJECT> <DEFINES> <FLAGS> -c <SOURCE>")
147 ENDIF(NOT CMAKE_Fortran_COMPILE_OBJECT)
149 # link a fortran program
150 IF(NOT CMAKE_Fortran_LINK_EXECUTABLE)
151   SET(CMAKE_Fortran_LINK_EXECUTABLE
152     "<CMAKE_Fortran_COMPILER> <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES>")
153 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)
161 IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
162   SET (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG_INIT}" CACHE STRING
163      "Flags used by the compiler during debug builds.")
164   SET (CMAKE_Fortran_FLAGS_MINSIZEREL "${CMAKE_Fortran_FLAGS_MINSIZEREL_INIT}" CACHE STRING
165       "Flags used by the compiler during release minsize builds.")
166   SET (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE_INIT}" CACHE STRING
167      "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).")
168   SET (CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
169      "Flags used by the compiler during Release with Debug Info builds.")
171 ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
173 MARK_AS_ADVANCED(
174 CMAKE_Fortran_FLAGS
175 CMAKE_Fortran_FLAGS_DEBUG
176 CMAKE_Fortran_FLAGS_MINSIZEREL
177 CMAKE_Fortran_FLAGS_RELEASE
178 CMAKE_Fortran_FLAGS_RELWITHDEBINFO)
180 # set this variable so we can avoid loading this more than once.
181 SET(CMAKE_Fortran_INFORMATION_LOADED 1)