forked from Tech-XCorp/scimake
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SciFindCompilerVersion.cmake
184 lines (166 loc) · 6 KB
/
SciFindCompilerVersion.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
######################################################################
#
# SciFindCompilerVersion: 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.
#
######################################################################
macro(SciFindCompilerVersion COMPLANG)
set(${COMPLANG}_COMPILER ${CMAKE_${COMPLANG}_COMPILER})
set(${COMPLANG}_COMPILER_ID ${CMAKE_${COMPLANG}_COMPILER_ID})
message(STATUS "Checking ${COMPLANG} compiler.")
SciPrintVar(CMAKE_${COMPLANG}_COMPILER)
SciPrintVar(CMAKE_${COMPLANG}_COMPILER_ID)
SciPrintVar(CMAKE_${COMPLANG}_COMPILER_VERSION)
SciPrintVar(${COMPLANG}_COMPILER)
SciPrintVar(${COMPLANG}_COMPILER_ID)
if (CMAKE_${COMPLANG}_COMPILER_ID STREQUAL GNU OR
CMAKE_${COMPLANG}_COMPILER_ID STREQUAL Clang)
# Get first line of version string
execute_process(
COMMAND ${CMAKE_${COMPLANG}_COMPILER} --version
OUTPUT_FILE ${PROJECT_BINARY_DIR}/_version.txt
)
file(STRINGS ${PROJECT_BINARY_DIR}/_version.txt _version_strlist)
file(REMOVE ${PROJECT_BINARY_DIR}/_version.txt)
list(GET _version_strlist 0 _version_str)
# New approach, just try to match a three-number version
# then a two-number version
# message(STATUS "_version_str = '${_version_str}'")
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+"
_version_tmp "${_version_str}"
)
if (NOT _version_tmp)
string(REGEX MATCH "[0-9]+\\.[0-9]+" _version_tmp "${_version_str}")
endif ()
if (NOT _version_tmp)
message(ERROR "Unable to extract version from '${_version_str}'")
endif ()
elseif (CMAKE_${COMPLANG}_COMPILER_ID STREQUAL Cray)
exec_program(${CMAKE_${COMPLANG}_COMPILER}
ARGS -V
OUTPUT_VARIABLE _version_tmp
)
string(REGEX MATCH
"Version [0-9]+\\.[0-9]+\\.[0-9]+"
_version_tmp
${_version_tmp}
)
# MESSAGE("_version_tmp = ${_version_tmp}.")
string(REPLACE "Version " "" _version_tmp ${_version_tmp})
# MESSAGE("_version_tmp = ${_version_tmp}.")
elseif (CMAKE_${COMPLANG}_COMPILER_ID STREQUAL Intel)
message(STATUS "Intel: CMAKE_${COMPLANG}_COMPILER = ${CMAKE_${COMPLANG}_COMPILER}")
if (WIN32)
if (CMAKE_${COMPLANG}_COMPILER MATCHES "icl")
exec_program(${CMAKE_${COMPLANG}_COMPILER}
OUTPUT_VARIABLE _version_str
)
string(REGEX MATCH
"Version [0-9][0-9]\\.[0-9]\\.[0-9]\\.[0-9][0-9][0-9]"
_version_tmp
${_version_str}
)
message(STATUS "Evaluating '${_version_str}'")
message(STATUS "Got '${_version_tmp}'")
string(REPLACE "Version " "" _version_tmp ${_version_tmp})
elseif (CMAKE_${COMPLANG}_COMPILER MATCHES "mpi")
exec_program(
icl OUTPUT_VARIABLE _version_str
)
string(REGEX MATCH
"Version [0-9][0-9]\\.[0-9]\\.[0-9]\\.[0-9][0-9][0-9]"
_version_tmp
${_version_str}
)
message(STATUS "Evaluating '${_version_str}'")
message(STATUS "Got '${_version_tmp}'")
string(REPLACE "Version " "" _version_tmp ${_version_tmp})
endif ()
else ()
if (CMAKE_${COMPLANG}_COMPILER MATCHES "icc"
OR CMAKE_${COMPLANG}_COMPILER MATCHES "icpc"
OR CMAKE_${COMPLANG}_COMPILER MATCHES "mpi"
OR CMAKE_${COMPLANG}_COMPILER MATCHES "CC"
OR CMAKE_${COMPLANG}_COMPILER MATCHES "cc")
execute_process(
COMMAND ${CMAKE_${COMPLANG}_COMPILER} --version
OUTPUT_VARIABLE _version_str
)
# Works on verus: '(ICC) m.n.r' no trailing space on stix
# string(REGEX MATCH '(GCC) [0-9]+\\.[0-9]+\\.[0-9]+'
string(REGEX MATCH ".ICC. [0-9]+\\.[0-9]+"
_version_tmp "${_version_str}"
)
if (DEBUG_CMAKE)
message(STATUS "Evaluating '${_version_str}'")
message(STATUS "Got '${_version_tmp}'")
endif ()
if (NOT _version_tmp)
message(ERROR "Unable to extract version from '${_version_str}'")
endif ()
string(REPLACE "(ICC) " "" _version_tmp "${_version_tmp}")
string(STRIP ${_version_tmp} _version_tmp)
endif ()
endif ()
elseif (CMAKE_${COMPLANG}_COMPILER MATCHES "cl")
exec_program(${CMAKE_${COMPLANG}_COMPILER}
OUTPUT_VARIABLE _version_tmp
)
string(REGEX MATCH
"Version [0-9]+\\.[0-9]+\\.[0-9]+(\\.[0-9]+)? for"
_version_tmp
${_version_tmp}
)
string(REPLACE "Version " "" _version_tmp ${_version_tmp})
string(REPLACE " for" "" _version_tmp ${_version_tmp})
elseif ("${CMAKE_${COMPLANG}_COMPILER_ID}" STREQUAL PathScale)
exec_program(${CMAKE_${COMPLANG}_COMPILER}
ARGS --version
OUTPUT_VARIABLE _version_tmp
)
# ARGS -v # This used to work above?
# MESSAGE("_version_tmp = ${_version_tmp}.")
string(REGEX MATCH
"Version [0-9]+\\.[0-9]"
_version_tmp
${_version_tmp}
)
string(REPLACE "Version " "" _version_tmp ${_version_tmp})
# MESSAGE("_version_tmp = ${_version_tmp}.")
elseif ("${CMAKE_${COMPLANG}_COMPILER_ID}" STREQUAL PGI)
exec_program(${CMAKE_${COMPLANG}_COMPILER}
ARGS -V
OUTPUT_VARIABLE _version_tmp
)
string(REGEX MATCH
"pgCC [0-9]+\\.[0-9]+-[0-9]+"
_version_tmp
${_version_tmp}
)
# MESSAGE("_version_tmp = ${_version_tmp}.")
string(REPLACE "pgCC " "" _version_tmp ${_version_tmp})
# MESSAGE("_version_tmp = ${_version_tmp}.")
elseif ("${CMAKE_${COMPLANG}_COMPILER_ID}" STREQUAL XL)
exec_program(${CMAKE_${COMPLANG}_COMPILER}
ARGS -qversion
OUTPUT_VARIABLE _version_tmp
)
# MESSAGE("_version_tmp = ${_version_tmp}.")
string(REGEX MATCH
"Version: .*"
_version_tmp
${_version_tmp}
)
# MESSAGE("_version_tmp = ${_version_tmp}.")
string(REPLACE "Version: " "" _version_tmp ${_version_tmp})
# MESSAGE("_version_tmp = ${_version_tmp}.")
else ()
message(FATAL_ERROR "Unknown compiler ID, ${CMAKE_${COMPLANG}_COMPILER_ID}.")
endif ()
set(${COMPLANG}_VERSION ${_version_tmp})
SciPrintVar(${COMPLANG}_VERSION)
endmacro()