2 #=============================================================================
3 # Copyright 2004-2011 Kitware, Inc.
5 # Distributed under the OSI-approved BSD License (the "License");
6 # see accompanying file Copyright.txt for details.
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.)
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
21 # Load compiler-specific information.
22 if(CMAKE_Fortran_COMPILER_ID)
23 include(Compiler/${CMAKE_Fortran_COMPILER_ID}-Fortran OPTIONAL)
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)
32 if(CMAKE_Fortran_COMPILER_ID)
33 include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_Fortran_COMPILER_ID}-Fortran OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
35 if (NOT _INCLUDED_FILE)
36 include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL
37 RESULT_VARIABLE _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)
47 if(CMAKE_Fortran_SIZEOF_DATA_PTR)
48 foreach(f ${CMAKE_Fortran_ABI_FILES})
51 unset(CMAKE_Fortran_ABI_FILES)
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.
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}")
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}")
73 # Fortran needs cmake to do a requires step during its build process to
75 set(CMAKE_NEEDS_REQUIRES_STEP_Fortran_FLAG 1)
77 if(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIC)
78 set(CMAKE_Fortran_COMPILE_OPTIONS_PIC ${CMAKE_C_COMPILE_OPTIONS_PIC})
81 if(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIE)
82 set(CMAKE_Fortran_COMPILE_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE})
85 if(NOT CMAKE_Fortran_COMPILE_OPTIONS_DLL)
86 set(CMAKE_Fortran_COMPILE_OPTIONS_DLL ${CMAKE_C_COMPILE_OPTIONS_DLL})
89 # Create a set of shared library variable specific to Fortran
90 # For 90% of the systems, these are the same flags as the C versions
91 # so if these are not set just copy the flags from the c version
92 if(NOT DEFINED CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS)
93 set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
96 if(NOT DEFINED CMAKE_SHARED_LIBRARY_Fortran_FLAGS)
97 set(CMAKE_SHARED_LIBRARY_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
100 if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
101 set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
104 if(NOT DEFINED CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG)
105 set(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
108 if(NOT DEFINED CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP)
109 set(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
112 if(NOT DEFINED CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG)
113 set(CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
116 if(NOT DEFINED CMAKE_EXE_EXPORTS_Fortran_FLAG)
117 set(CMAKE_EXE_EXPORTS_Fortran_FLAG ${CMAKE_EXE_EXPORTS_C_FLAG})
120 if(NOT DEFINED CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG)
121 set(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG})
124 # for most systems a module is the same as a shared library
125 # so unless the variable CMAKE_MODULE_EXISTS is set just
126 # copy the values from the LIBRARY variables
127 if(NOT CMAKE_MODULE_EXISTS)
128 set(CMAKE_SHARED_MODULE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_Fortran_FLAGS})
129 set(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS})
133 if(NOT DEFINED CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS)
134 set(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS})
137 if(NOT DEFINED CMAKE_SHARED_MODULE_Fortran_FLAGS)
138 set(CMAKE_SHARED_MODULE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS})
141 if(NOT DEFINED CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG)
142 set(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG})
145 if(NOT DEFINED CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP)
146 set(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP})
149 if(NOT DEFINED CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG)
150 set(CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG})
153 if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH)
154 set(CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH})
157 if(NOT CMAKE_INCLUDE_FLAG_Fortran)
158 set(CMAKE_INCLUDE_FLAG_Fortran ${CMAKE_INCLUDE_FLAG_C})
161 if(NOT CMAKE_INCLUDE_FLAG_SEP_Fortran)
162 set(CMAKE_INCLUDE_FLAG_SEP_Fortran ${CMAKE_INCLUDE_FLAG_SEP_C})
165 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.")
167 set(CMAKE_Fortran_FLAGS_INIT "$ENV{FFLAGS} ${CMAKE_Fortran_FLAGS_INIT}")
168 # avoid just having a space as the initial value for the cache
169 if(CMAKE_Fortran_FLAGS_INIT STREQUAL " ")
170 set(CMAKE_Fortran_FLAGS_INIT)
172 set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_INIT}" CACHE STRING
173 "Flags for Fortran compiler.")
175 include(CMakeCommonLanguageInclude)
177 # now define the following rule variables
178 # CMAKE_Fortran_CREATE_SHARED_LIBRARY
179 # CMAKE_Fortran_CREATE_SHARED_MODULE
180 # CMAKE_Fortran_COMPILE_OBJECT
181 # CMAKE_Fortran_LINK_EXECUTABLE
183 # create a Fortran shared library
184 if(NOT CMAKE_Fortran_CREATE_SHARED_LIBRARY)
185 set(CMAKE_Fortran_CREATE_SHARED_LIBRARY
186 "<CMAKE_Fortran_COMPILER> <CMAKE_SHARED_LIBRARY_Fortran_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
189 # create a Fortran shared module just copy the shared library rule
190 if(NOT CMAKE_Fortran_CREATE_SHARED_MODULE)
191 set(CMAKE_Fortran_CREATE_SHARED_MODULE ${CMAKE_Fortran_CREATE_SHARED_LIBRARY})
194 # Create a static archive incrementally for large object file counts.
195 # If CMAKE_Fortran_CREATE_STATIC_LIBRARY is set it will override these.
196 if(NOT DEFINED CMAKE_Fortran_ARCHIVE_CREATE)
197 set(CMAKE_Fortran_ARCHIVE_CREATE "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS>")
199 if(NOT DEFINED CMAKE_Fortran_ARCHIVE_APPEND)
200 set(CMAKE_Fortran_ARCHIVE_APPEND "<CMAKE_AR> r <TARGET> <LINK_FLAGS> <OBJECTS>")
202 if(NOT DEFINED CMAKE_Fortran_ARCHIVE_FINISH)
203 set(CMAKE_Fortran_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
206 # compile a Fortran file into an object file
207 # (put -o after -c to workaround bug in at least one mpif77 wrapper)
208 if(NOT CMAKE_Fortran_COMPILE_OBJECT)
209 set(CMAKE_Fortran_COMPILE_OBJECT
210 "<CMAKE_Fortran_COMPILER> <DEFINES> <FLAGS> -c <SOURCE> -o <OBJECT>")
213 # link a fortran program
214 if(NOT CMAKE_Fortran_LINK_EXECUTABLE)
215 set(CMAKE_Fortran_LINK_EXECUTABLE
216 "<CMAKE_Fortran_COMPILER> <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
219 if(CMAKE_Fortran_STANDARD_LIBRARIES_INIT)
220 set(CMAKE_Fortran_STANDARD_LIBRARIES "${CMAKE_Fortran_STANDARD_LIBRARIES_INIT}"
221 CACHE STRING "Libraries linked by defalut with all Fortran applications.")
222 mark_as_advanced(CMAKE_Fortran_STANDARD_LIBRARIES)
225 if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
226 set (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG_INIT}" CACHE STRING
227 "Flags used by the compiler during debug builds.")
228 set (CMAKE_Fortran_FLAGS_MINSIZEREL "${CMAKE_Fortran_FLAGS_MINSIZEREL_INIT}" CACHE STRING
229 "Flags used by the compiler during release minsize builds.")
230 set (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE_INIT}" CACHE STRING
231 "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).")
232 set (CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
233 "Flags used by the compiler during Release with Debug Info builds.")
239 CMAKE_Fortran_FLAGS_DEBUG
240 CMAKE_Fortran_FLAGS_MINSIZEREL
241 CMAKE_Fortran_FLAGS_RELEASE
242 CMAKE_Fortran_FLAGS_RELWITHDEBINFO)
244 # set this variable so we can avoid loading this more than once.
245 set(CMAKE_Fortran_INFORMATION_LOADED 1)