-
Notifications
You must be signed in to change notification settings - Fork 0
/
sciEngFindVersion.cmake
61 lines (57 loc) · 2.26 KB
/
sciEngFindVersion.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
######################################################################
#
# sciEngFindVersion: Function to extract the version and revision
# number of a given executable from the output of "executable --version".
#
# $Id: sciEngFindVersion.cmake 1246 2012-01-31 21:44:54Z dws $
#
# Copyright © 2011-2012 Tech-X Corporation.
# Arbitrary redistribution allowed provided this copyright remains.
#
######################################################################
# sciEngFindVersion
#
# Args:
#
# INPUT
# EXECUTABLE: the full path and name of executable
# OUTPUT
# EXE_VERSION: the version and revision number of executable
#
# ASSUMPTIONS
# Assumes the output of "executable --version" first
# prints the executable name, a space, and then the version and revision number.
# "(executable name) (version number) (revision number)"
# (e.g. VORPAL 5.1.0 r18555 => 5.1.0-r18555)
#
function(sciEngFindVersion EXECUTABLE_TORUN EXE_VERSION)
# The result of executable --version is sent to standard error
execute_process(COMMAND ${EXECUTABLE_TORUN} "--version"
TIMEOUT 60
ERROR_VARIABLE EXE_STD_ERR
RESULT_VARIABLE EXE_RSLT
ERROR_STRIP_TRAILING_WHITESPACE
)
if (DEBUG_CMAKE)
message(STATUS "Result of running ${EXECUTABLE_TORUN} --version = \"${EXE_STD_ERR}\"")
endif ()
if (EXE_RSLT)
message(STATUS "[sciEngFindVersion] Exit status from ${EXECUTABLE_TORUN} --version nonzero; unable to determine version")
set(EXE_VERSION "VersionNumNotFound" PARENT_SCOPE)
else ()
string(LENGTH "${EXE_STD_ERR}" outputlength)
if (${outputlength})
# string(REPLACE takes the OUTPUT variable first,
# while string(STRIP and (TOLOWER takes the INPUT variable first.
string(STRIP ${EXE_STD_ERR} EXE_VERSION)
string(REGEX REPLACE "^([^ ]+[ ]+)(.*)" "\\2" EXE_VERSION ${EXE_VERSION})
string(REGEX REPLACE " " "-" EXE_VERSION ${EXE_VERSION})
string(TOLOWER ${EXE_VERSION} EXE_VERSION)
set(EXE_VERSION ${EXE_VERSION} PARENT_SCOPE)
message(STATUS "[sciEngFindVersion] Version number to be used: ${EXE_VERSION}")
else ()
message(STATUS "[sciEngFindVersion] Empty ${EXECUTABLE_TORUN} --version output, unable to determine version")
set(EXE_VERSION "VersionNumNotFound" PARENT_SCOPE)
endif ()
endif ()
endfunction()