forked from Tech-XCorp/scimake
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SciFortranFindVersion.cmake
201 lines (188 loc) · 6.49 KB
/
SciFortranFindVersion.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
######################################################################
#
# SciFortranFindVersion: Determine compiler version for any compiler
#
# $Rev$ $Date$
#
# Copyright 2012-2017, Tech-X Corporation, Boulder, CO.
# See LICENSE file (EclipseLicense.txt) for conditions of use.
#
######################################################################
SciPrintString("")
SciPrintString("CMAKE_Fortran_COMPILER_ID = '${CMAKE_Fortran_COMPILER_ID}'.")
if ("${CMAKE_Fortran_COMPILER_ID}" STREQUAL Cray)
exec_program(${CMAKE_Fortran_COMPILER}
ARGS -V
OUTPUT_VARIABLE fc_version_tmp
)
string(REGEX MATCH
"Version [0-9]+\\.[0-9]+\\.[0-9]+"
fc_version_tmp
${fc_version_tmp}
)
# MESSAGE("fc_version_tmp = ${fc_version_tmp}.")
string(REPLACE "Version " "" fc_version_tmp ${fc_version_tmp})
# MESSAGE("fc_version_tmp = ${fc_version_tmp}.")
elseif ("${CMAKE_Fortran_COMPILER_ID}" STREQUAL GNU)
# exec_program is deprecated
execute_process(
COMMAND ${CMAKE_Fortran_COMPILER} --version
OUTPUT_VARIABLE fc_version_str
)
# Test for ubuntu
# set(fc_version_str "gcc(Ubuntu 4.4.3-4ubuntu5) 4.4.3 ")
# message(STATUS "fc_version_str = '${fc_version_str}'")
# Works on stix: '(GCC) m.n.r' no trailing space on stix
# string(REGEX MATCH '(GCC) [0-9]+\\.[0-9]+\\.[0-9]+'
string(REGEX MATCH ".GCC. [0-9]+\\.[0-9]+\\.[0-9]+"
fc_version_tmp "${fc_version_str}"
)
# message(STATUS "fc_version_tmp = '${fc_version_tmp}'")
if (NOT fc_version_tmp)
# Works for Ubuntu
string(REGEX MATCH " [0-9]+\\.[0-9]+\\.[0-9]+ *\$"
fc_version_tmp "${fc_version_str}"
)
endif ()
if (NOT fc_version_tmp)
# Now try to get Gentoo...not very robust either, but nothing else is working.
# Could do with more sophisticated options such as multiline regex/ \s
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fc_version_tmp "${fc_version_str}" )
endif ()
# message(STATUS "fc_version_tmp = '${fc_version_tmp}'")
# message(STATUS "fc_version_str = '${fc_version_str}'")
if (NOT fc_version_tmp)
message(ERROR "Unable to extract version from '${fc_version_str}'")
endif ()
# message(STATUS "fc_version_tmp = '${fc_version_tmp}'")
# message(STATUS "fc_version_tmp = '${fc_version_tmp}'")
string(REPLACE "(GCC) " "" fc_version_tmp "${fc_version_tmp}")
string(STRIP ${fc_version_tmp} fc_version_tmp)
elseif ("${CMAKE_Fortran_COMPILER_ID}" STREQUAL Intel)
if (WIN32)
if (CMAKE_Fortran_COMPILER MATCHES "mpi")
exec_program(
ifort OUTPUT_VARIABLE fc_version_str
)
string(REGEX MATCH
"Version [0-9][0-9]\\.[0-9]\\.[0-9]\\.[0-9][0-9][0-9]"
fc_version_tmp
${fc_version_str}
)
string(REPLACE "Version " "" fc_version_tmp ${fc_version_tmp})
else ()
exec_program(${CMAKE_Fortran_COMPILER}
OUTPUT_VARIABLE fc_version_str
)
string(REGEX MATCH
"Version [0-9][0-9]\\.[0-9]\\.[0-9]\\.[0-9][0-9][0-9]"
fc_version_tmp
${fc_version_str}
)
string(REPLACE "Version " "" fc_version_tmp ${fc_version_tmp})
endif ()
else ()
execute_process(
COMMAND ${CMAKE_Fortran_COMPILER} --version
OUTPUT_VARIABLE fc_version_str
)
message(STATUS "fc_version_tmp = '${fc_version_str}'")
# Works on verus: '(ICC) m.n.r' no trailing space on stix
# string(REGEX MATCH '(GCC) [0-9]+\\.[0-9]+\\.[0-9]+'
#
# Roopa: Check if its ICC or IFORT
#
string(FIND ${fc_version_str} "(ICC)" fc_icc_tmp)
string(FIND ${fc_version_str} "(IFORT)" fc_ifort_tmp)
if (${fc_icc_tmp} STRGREATER "0")
if (DEBUG_CMAKE)
message(STATUS "Using Intel's icc compiler")
endif ()
set(fc_type_tmp "ICC")
elseif (${fc_ifort_tmp} STRGREATER "0")
if (DEBUG_CMAKE)
message(STATUS "Using Intel's ifort compiler")
endif ()
set(fc_type_tmp "IFORT")
endif ()
string(REGEX MATCH ".${fc_type_tmp}. [0-9]+\\.[0-9]+\\.[0-9]+"
fc_version_tmp "${fc_version_str}"
)
if (NOT fc_version_tmp)
string(REGEX MATCH ".${fc_type_tmp}. [0-9]+\\.[0-9]+" fc_version_tmp "${fc_version_str}" )
endif ()
if (NOT fc_version_tmp)
message(STATUS "hi there")
message(ERROR "Unable to extract version from '${fc_version_str}'")
endif ()
string(REPLACE "(${fc_type_tmp}) " "" fc_version_tmp "${fc_version_tmp}")
string(STRIP ${fc_version_tmp} fc_version_tmp)
endif ()
elseif (CMAKE_Fortran_COMPILER MATCHES "icl")
exec_program(${CMAKE_Fortran_COMPILER}
OUTPUT_VARIABLE fc_version_tmp
)
string(REGEX MATCH
"w_cproc_p_[0-9][0-9]\\.[0-9]\\.[0-9][0-9][0-9]"
fc_version_tmp
${fc_version_tmp}
)
string(REPLACE "w_cproc_p_" "" fc_version_tmp ${fc_version_tmp})
elseif (CMAKE_Fortran_COMPILER MATCHES "cl")
exec_program(${CMAKE_Fortran_COMPILER}
OUTPUT_VARIABLE fc_version_tmp
)
string(REGEX MATCH
"Version [0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+ for"
fc_version_tmp
${fc_version_tmp}
)
string(REPLACE "Version " "" fc_version_tmp ${fc_version_tmp})
string(REPLACE " for" "" fc_version_tmp ${fc_version_tmp})
elseif ("${CMAKE_Fortran_COMPILER_ID}" STREQUAL PathScale)
exec_program(${CMAKE_Fortran_COMPILER}
ARGS --version
OUTPUT_VARIABLE fc_version_tmp
)
# ARGS -v # This used to work above?
# MESSAGE("fc_version_tmp = ${fc_version_tmp}.")
string(REGEX MATCH
"Version [0-9]+\\.[0-9]"
fc_version_tmp
${fc_version_tmp}
)
string(REPLACE "Version " "" fc_version_tmp ${fc_version_tmp})
# MESSAGE("fc_version_tmp = ${fc_version_tmp}.")
elseif ("${CMAKE_Fortran_COMPILER_ID}" STREQUAL PGI)
exec_program(${CMAKE_Fortran_COMPILER}
ARGS -V
OUTPUT_VARIABLE fc_version_tmp
)
string(REGEX MATCH
"pgf90 [0-9]+\\.[0-9]+-[0-9]+"
fc_version_tmp
${fc_version_tmp}
)
# MESSAGE("fc_version_tmp = ${fc_version_tmp}.")
string(REPLACE "pgf90 " "" fc_version_tmp ${fc_version_tmp})
# MESSAGE("fc_version_tmp = ${fc_version_tmp}.")
elseif ("${CMAKE_Fortran_COMPILER_ID}" STREQUAL XL)
exec_program(${CMAKE_Fortran_COMPILER}
ARGS -qversion
OUTPUT_VARIABLE fc_version_tmp
)
# MESSAGE("fc_version_tmp = ${fc_version_tmp}.")
string(REGEX MATCH
"Version: .*"
fc_version_tmp
${fc_version_tmp}
)
# MESSAGE("fc_version_tmp = ${fc_version_tmp}.")
string(REPLACE "Version: " "" fc_version_tmp ${fc_version_tmp})
# MESSAGE("fc_version_tmp = ${fc_version_tmp}.")
# This does not work, as it sets Boost_INCLUDE_DIR
else ()
message(FATAL_ERROR "Unknown compiler ID, ${CMAKE_Fortran_COMPILER_ID}.")
endif ()
set(Fortran_VERSION ${fc_version_tmp})
SciPrintString(" Fortran_VERSION = '${Fortran_VERSION}'")