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