ENH: move EstimateFormatLength to kwsys
[cmake.git] / Modules / CMakeFortranInformation.cmake
blob9b4d4c0ec639c9a12cccc65802c9bf6ce6ff4124
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.
5 GET_FILENAME_COMPONENT(CMAKE_BASE_NAME ${CMAKE_Fortran_COMPILER} NAME_WE)
6 # since the gnu compiler has several names force g++
7 IF(CMAKE_COMPILER_IS_GNUG77)
8   SET(CMAKE_BASE_NAME g77)
9 ENDIF(CMAKE_COMPILER_IS_GNUG77)
10 SET(CMAKE_SYSTEM_AND_Fortran_COMPILER_INFO_FILE
11   ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}.cmake)
12 INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL)
15 # Create a set of shared library variable specific to Fortran
16 # For 90% of the systems, these are the same flags as the C versions
17 # so if these are not set just copy the flags from the c version
18 IF(NOT CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS)
19   SET(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
20 ENDIF(NOT CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS)
22 IF(NOT CMAKE_SHARED_LIBRARY_Fortran_FLAGS)
23   SET(CMAKE_SHARED_LIBRARY_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
24 ENDIF(NOT CMAKE_SHARED_LIBRARY_Fortran_FLAGS)
26 IF(NOT CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
27   SET(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
28 ENDIF(NOT CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS)
30 IF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG)
31   SET(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG}) 
32 ENDIF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG)
34 IF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP)
35   SET(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
36 ENDIF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG_SEP)
38 # repeat for modules
39 IF(NOT CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS)
40   SET(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS})
41 ENDIF(NOT CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS)
43 IF(NOT CMAKE_SHARED_MODULE_Fortran_FLAGS)
44   SET(CMAKE_SHARED_MODULE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS})
45 ENDIF(NOT CMAKE_SHARED_MODULE_Fortran_FLAGS)
47 IF(NOT CMAKE_SHARED_MODULE_LINK_Fortran_FLAGS)
48   SET(CMAKE_SHARED_MODULE_LINK_Fortran_FLAGS ${CMAKE_SHARED_MODULE_LINK_C_FLAGS})
49 ENDIF(NOT CMAKE_SHARED_MODULE_LINK_Fortran_FLAGS)
51 IF(NOT CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG)
52   SET(CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG ${CMAKE_SHARED_MODULE_RUNTIME_C_FLAG}) 
53 ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG)
55 IF(NOT CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG_SEP)
56   SET(CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG_SEP ${CMAKE_SHARED_MODULE_RUNTIME_C_FLAG_SEP})
57 ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_Fortran_FLAG_SEP)
59 IF(NOT CMAKE_INCLUDE_FLAG_Fortran)
60   SET(CMAKE_INCLUDE_FLAG_Fortran ${CMAKE_INCLUDE_FLAG_C})
61 ENDIF(NOT CMAKE_INCLUDE_FLAG_Fortran)
63 IF(NOT CMAKE_INCLUDE_FLAG_SEP_Fortran)
64   SET(CMAKE_INCLUDE_FLAG_SEP_Fortran ${CMAKE_INCLUDE_FLAG_SEP_C})
65 ENDIF(NOT CMAKE_INCLUDE_FLAG_SEP_Fortran)
67 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.")
69 SET (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_ENV_INIT} $ENV{FFLAGS} ${CMAKE_Fortran_FLAGS_INIT}" CACHE STRING
70      "Flags for Fortran compiler.")
74 INCLUDE(CMakeCommonLanguageInclude)
76 # now define the following rule variables
77 # CMAKE_Fortran_CREATE_SHARED_LIBRARY
78 # CMAKE_Fortran_CREATE_SHARED_MODULE
79 # CMAKE_Fortran_CREATE_STATIC_LIBRARY
80 # CMAKE_Fortran_COMPILE_OBJECT
81 # CMAKE_Fortran_LINK_EXECUTABLE
83 # create a Fortran shared library
84 IF(NOT CMAKE_Fortran_CREATE_SHARED_LIBRARY)
85   SET(CMAKE_Fortran_CREATE_SHARED_LIBRARY
86       "<CMAKE_Fortran_COMPILER> <CMAKE_SHARED_LIBRARY_Fortran_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
87 ENDIF(NOT CMAKE_Fortran_CREATE_SHARED_LIBRARY)
89 # create a Fortran shared module just copy the shared library rule
90 IF(NOT CMAKE_Fortran_CREATE_SHARED_MODULE)
91   SET(CMAKE_Fortran_CREATE_SHARED_MODULE ${CMAKE_Fortran_CREATE_SHARED_LIBRARY})
92 ENDIF(NOT CMAKE_Fortran_CREATE_SHARED_MODULE)
94 # create a Fortran static library
95 IF(NOT CMAKE_Fortran_CREATE_STATIC_LIBRARY)
96   SET(CMAKE_Fortran_CREATE_STATIC_LIBRARY
97       "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS> "
98       "<CMAKE_RANLIB> <TARGET> ")
99 ENDIF(NOT CMAKE_Fortran_CREATE_STATIC_LIBRARY)
101 # compile a Fortran file into an object file
102 IF(NOT CMAKE_Fortran_COMPILE_OBJECT)
103   SET(CMAKE_Fortran_COMPILE_OBJECT
104     "<CMAKE_Fortran_COMPILER> -o <OBJECT>  <FLAGS> -c <SOURCE>")
105 ENDIF(NOT CMAKE_Fortran_COMPILE_OBJECT)
107 # link a fortran program
108 IF(NOT CMAKE_Fortran_LINK_EXECUTABLE)
109   SET(CMAKE_Fortran_LINK_EXECUTABLE
110     "<CMAKE_Fortran_COMPILER> <CMAKE_Fortran_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES>")
111 ENDIF(NOT CMAKE_Fortran_LINK_EXECUTABLE)
114 # Load the user define rules
115 IF(CMAKE_USER_MAKE_RULES_OVERRIDE)
116    INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE})
117 ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE)
120 MARK_AS_ADVANCED(
121 CMAKE_Fortran_FLAGS
122 CMAKE_Fortran_FLAGS_DEBUG
123 CMAKE_Fortran_FLAGS_MINSIZEREL
124 CMAKE_Fortran_FLAGS_RELEASE
125 CMAKE_Fortran_FLAGS_RELWITHDEBINFO)
127 # set this variable so we can avoid loading this more than once.
128 SET(CMAKE_Fortran_INFOMATION_LOADED 1)