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
6 GET_FILENAME_COMPONENT(CMAKE_BASE_NAME ${CMAKE_Fortran_COMPILER} NAME_WE)
7 # since the gnu compiler has several names force g++
8 IF(CMAKE_COMPILER_IS_GNUG77)
9 SET(CMAKE_BASE_NAME g77)
10 ENDIF(CMAKE_COMPILER_IS_GNUG77)
11 IF(CMAKE_Fortran_COMPILER_ID)
12 IF(EXISTS ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_Fortran_COMPILER_ID}-Fortran.cmake)
13 SET(CMAKE_BASE_NAME ${CMAKE_Fortran_COMPILER_ID}-Fortran)
14 ENDIF(EXISTS ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_Fortran_COMPILER_ID}-Fortran.cmake)
15 ENDIF(CMAKE_Fortran_COMPILER_ID)
16 SET(CMAKE_SYSTEM_AND_Fortran_COMPILER_INFO_FILE
17 ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}.cmake)
18 INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL)
20 # This should be included before the _INIT variables are
21 # used to initialize the cache. Since the rule variables
22 # have if blocks on them, users can still define them here.
23 # But, it should still be after the platform file so changes can
24 # be made to those values.
26 IF(CMAKE_USER_MAKE_RULES_OVERRIDE)
27 INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE})
28 ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE)
30 IF(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran)
31 INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran})
32 ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran)
35 # Fortran needs cmake to do a requires step during its build process to
37 SET(CMAKE_NEEDS_REQUIRES_STEP_Fortran_FLAG 1)
39 # Create a set of shared library variable specific to Fortran
40 # For 90% of the systems, these are the same flags as the C versions
41 # so if these are not set just copy the flags from the c version
42 IF(NOT CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS)
43 SET(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
44 ENDIF(NOT CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS)
46 IF(NOT CMAKE_SHARED_LIBRARY_Fortran_FLAGS)
47 SET(CMAKE_SHARED_LIBRARY_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
48 ENDIF(NOT CMAKE_SHARED_LIBRARY_Fortran_FLAGS)
50 IF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
51 SET(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
52 ENDIF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
54 IF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG)
55 SET(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
56 ENDIF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG)
58 IF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP)
59 SET(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
60 ENDIF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP)
62 IF(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG)
63 SET(CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
64 ENDIF(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG)
67 IF(NOT CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS)
68 SET(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS})
69 ENDIF(NOT CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS)
71 IF(NOT CMAKE_SHARED_MODULE_Fortran_FLAGS)
72 SET(CMAKE_SHARED_MODULE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS})
73 ENDIF(NOT CMAKE_SHARED_MODULE_Fortran_FLAGS)
75 IF(NOT CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG)
76 SET(CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_MODULE_RUNTIME_C_FLAG})
77 ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG)
79 IF(NOT CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG_SEP)
80 SET(CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_MODULE_RUNTIME_C_FLAG_SEP})
81 ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG_SEP)
83 IF(NOT CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG)
84 SET(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG})
85 ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG)
87 IF(NOT CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP)
88 SET(CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP})
89 ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_Fortran_FLAG_SEP)
91 IF(NOT CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG)
92 SET(CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_Fortran_FLAG})
93 ENDIF(NOT CMAKE_EXECUTABLE_RPATH_LINK_Fortran_FLAG)
95 IF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH)
96 SET(CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH})
97 ENDIF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_Fortran_WITH_RUNTIME_PATH)
99 IF(NOT CMAKE_INCLUDE_FLAG_Fortran)
100 SET(CMAKE_INCLUDE_FLAG_Fortran ${CMAKE_INCLUDE_FLAG_C})
101 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)
107 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.")
109 SET(CMAKE_Fortran_FLAGS_INIT "$ENV{FFLAGS} ${CMAKE_Fortran_FLAGS_INIT}")
110 # avoid just having a space as the initial value for the cache
111 IF(CMAKE_Fortran_FLAGS_INIT STREQUAL " ")
112 SET(CMAKE_Fortran_FLAGS_INIT)
113 ENDIF(CMAKE_Fortran_FLAGS_INIT STREQUAL " ")
114 SET (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_INIT}" CACHE STRING
115 "Flags for Fortran compiler.")
117 INCLUDE(CMakeCommonLanguageInclude)
119 # now define the following rule variables
120 # CMAKE_Fortran_CREATE_SHARED_LIBRARY
121 # CMAKE_Fortran_CREATE_SHARED_MODULE
122 # CMAKE_Fortran_COMPILE_OBJECT
123 # CMAKE_Fortran_LINK_EXECUTABLE
125 # create a Fortran shared library
126 IF(NOT CMAKE_Fortran_CREATE_SHARED_LIBRARY)
127 SET(CMAKE_Fortran_CREATE_SHARED_LIBRARY
128 "<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>")
129 ENDIF(NOT CMAKE_Fortran_CREATE_SHARED_LIBRARY)
131 # create a Fortran shared module just copy the shared library rule
132 IF(NOT CMAKE_Fortran_CREATE_SHARED_MODULE)
133 SET(CMAKE_Fortran_CREATE_SHARED_MODULE ${CMAKE_Fortran_CREATE_SHARED_LIBRARY})
134 ENDIF(NOT CMAKE_Fortran_CREATE_SHARED_MODULE)
136 # Create a static archive incrementally for large object file counts.
137 # If CMAKE_Fortran_CREATE_STATIC_LIBRARY is set it will override these.
138 SET(CMAKE_Fortran_ARCHIVE_CREATE "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS>")
139 SET(CMAKE_Fortran_ARCHIVE_APPEND "<CMAKE_AR> r <TARGET> <LINK_FLAGS> <OBJECTS>")
140 SET(CMAKE_Fortran_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
142 # compile a Fortran file into an object file
143 IF(NOT CMAKE_Fortran_COMPILE_OBJECT)
144 SET(CMAKE_Fortran_COMPILE_OBJECT
145 "<CMAKE_Fortran_COMPILER> -o <OBJECT> <DEFINES> <FLAGS> -c <SOURCE>")
146 ENDIF(NOT CMAKE_Fortran_COMPILE_OBJECT)
148 # link a fortran program
149 IF(NOT CMAKE_Fortran_LINK_EXECUTABLE)
150 SET(CMAKE_Fortran_LINK_EXECUTABLE
151 "<CMAKE_Fortran_COMPILER> <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
152 ENDIF(NOT CMAKE_Fortran_LINK_EXECUTABLE)
154 IF(CMAKE_Fortran_STANDARD_LIBRARIES_INIT)
155 SET(CMAKE_Fortran_STANDARD_LIBRARIES "${CMAKE_Fortran_STANDARD_LIBRARIES_INIT}"
156 CACHE STRING "Libraries linked by defalut with all Fortran applications.")
157 MARK_AS_ADVANCED(CMAKE_Fortran_STANDARD_LIBRARIES)
158 ENDIF(CMAKE_Fortran_STANDARD_LIBRARIES_INIT)
160 IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
161 SET (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG_INIT}" CACHE STRING
162 "Flags used by the compiler during debug builds.")
163 SET (CMAKE_Fortran_FLAGS_MINSIZEREL "${CMAKE_Fortran_FLAGS_MINSIZEREL_INIT}" CACHE STRING
164 "Flags used by the compiler during release minsize builds.")
165 SET (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE_INIT}" CACHE STRING
166 "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).")
167 SET (CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
168 "Flags used by the compiler during Release with Debug Info builds.")
170 ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
174 CMAKE_Fortran_FLAGS_DEBUG
175 CMAKE_Fortran_FLAGS_MINSIZEREL
176 CMAKE_Fortran_FLAGS_RELEASE
177 CMAKE_Fortran_FLAGS_RELWITHDEBINFO)
179 # set this variable so we can avoid loading this more than once.
180 SET(CMAKE_Fortran_INFORMATION_LOADED 1)