InterpTools.cmake
Go to the documentation of this file.
1 # ============================================================================
2 # Copyright (c) 2011-2012 University of Pennsylvania
3 # Copyright (c) 2013-2016 Andreas Schuh
4 # All rights reserved.
5 #
6 # See COPYING file for license information or visit
7 # https://cmake-basis.github.io/download.html#license
8 # ============================================================================
9 
10 ##############################################################################
11 # @file InterpTools.cmake
12 # @brief Script interpreter tools.
13 #
14 # @ingroup CMakeTools
15 ##############################################################################
16 
18  return ()
19 else ()
21 endif ()
22 
23 
24 ## @addtogroup CMakeUtilities
25 # @{
26 
27 
28 # ----------------------------------------------------------------------------
29 ## @brief Get version of Python interpreter.
30 #
31 # @param [out] ARGV1 If given, the named variable is set to the version string
32 # of the Python interpreter. Otherwise, the variables
33 # @c PYTHON_VERSION_STRING, @c PYTHON_VERSION_MAJOR,
34 # @c PYTHON_VERSION_MINOR, and @c PYTHON_VERSION_PATCH are
35 # set in the scope of the caller.
36 function (basis_get_python_version)
37  if (PYTHON_EXECUTABLE)
38  execute_process(
39  COMMAND "${PYTHON_EXECUTABLE}" -E -c "import sys; sys.stdout.write(';'.join([str(x) for x in sys.version_info[:3]]))"
40  OUTPUT_VARIABLE VERSION
41  RESULT_VARIABLE RETVAL
42  ERROR_QUIET
43  )
44  if (RETVAL EQUAL 0)
45  string (REPLACE ";" "." VERSION_STRING "${VERSION}")
46  list (GET VERSION 0 VERSION_MAJOR)
47  list (GET VERSION 1 VERSION_MINOR)
48  list (GET VERSION 2 VERSION_PATCH)
49  if (VERSION_PATCH EQUAL 0)
50  string (REGEX REPLACE "\\.0$" "" VERSION_STRING "${VERSION_STRING}")
51  endif()
52  else ()
53  # sys.version predates sys.version_info
54  execute_process (
55  COMMAND "${PYTHON_EXECUTABLE}" -E -c "import sys; sys.stdout.write(sys.version)"
56  OUTPUT_VARIABLE VERSION
57  RESULT_VARIABLE RETVAL
58  ERROR_QUIET
59  )
60  if (RETVAL EQUAL 0)
61  string (REGEX REPLACE " .*" "" VERSION_STRING "${VERSION}")
62  string (REGEX REPLACE "^([0-9]+)\\.[0-9]+.*" "\\1" VERSION_MAJOR "${VERSION_STRING}")
63  string (REGEX REPLACE "^[0-9]+\\.([0-9])+.*" "\\1" VERSION_MINOR "${VERSION_STRING}")
64  if (VERSION_STRING MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+.*")
65  string (REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION_STRING}")
66  else ()
67  set (VERSION_PATCH "0")
68  endif()
69  else ()
70  # sys.version was first documented for Python 1.5
71  set (VERSION_STRING "1.4")
72  set (VERSION_MAJOR "1")
73  set (VERSION_MINOR "4")
74  set (VERSION_PATCH "0")
75  endif ()
76  endif ()
77  else ()
78  set (VERSION_STRING "0.0")
79  set (VERSION_MAJOR "0")
80  set (VERSION_MINOR "0")
81  set (VERSION_PATCH "0")
82  endif ()
83  if (ARGC EQUAL 1)
84  set (${ARGV0} "${VERSION_STRING}" PARENT_SCOPE)
85  else ()
86  set (PYTHON_VERSION_STRING "${VERSION_STRING}" PARENT_SCOPE)
87  set (PYTHON_VERSION_MAJOR "${VERSION_MAJOR}" PARENT_SCOPE)
88  set (PYTHON_VERSION_MINOR "${VERSION_MINOR}" PARENT_SCOPE)
89  set (PYTHON_VERSION_PATCH "${VERSION_PATCH}" PARENT_SCOPE)
90  endif ()
91 endfunction ()
92 
93 # ----------------------------------------------------------------------------
94 ## @brief Get version of Jython interpreter.
95 #
96 # @param [out] ARGV1 If given, the named variable is set to the version string
97 # of the Jython interpreter. Otherwise, the variables
98 # @c JYTHON_VERSION_STRING, @c JYTHON_VERSION_MAJOR,
99 # @c JYTHON_VERSION_MINOR, and @c JYTHON_VERSION_PATCH are
100 # set in the scope of the caller.
101 function (basis_get_jython_version)
102  if (JYTHON_EXECUTABLE)
103  execute_process(
104  COMMAND "${JYTHON_EXECUTABLE}" -c "import sys; sys.stdout.write(';'.join([str(x) for x in sys.version_info[:3]]))"
105  OUTPUT_VARIABLE VERSION
106  RESULT_VARIABLE RETVAL
107  ERROR_QUIET
108  )
109  if (RETVAL EQUAL 0)
110  string (REPLACE ";" "." VERSION_STRING "${VERSION}")
111  list (GET VERSION 0 VERSION_MAJOR)
112  list (GET VERSION 1 VERSION_MINOR)
113  list (GET VERSION 2 VERSION_PATCH)
114  if (VERSION_PATCH EQUAL 0)
115  string (REGEX REPLACE "\\.0$" "" VERSION_STRING "${VERSION_STRING}")
116  endif()
117  else ()
118  # sys.version predates sys.version_info
119  execute_process (
120  COMMAND "${JYTHON_EXECUTABLE}" -c "import sys; sys.stdout.write(sys.version)"
121  OUTPUT_VARIABLE VERSION
122  RESULT_VARIABLE RETVAL
123  ERROR_QUIET
124  )
125  if (RETVAL EQUAL 0)
126  string (REGEX REPLACE " .*" "" VERSION_STRING "${VERSION}")
127  string (REGEX REPLACE "^([0-9]+)\\.[0-9]+.*" "\\1" VERSION_MAJOR "${VERSION_STRING}")
128  string (REGEX REPLACE "^[0-9]+\\.([0-9])+.*" "\\1" VERSION_MINOR "${VERSION_STRING}")
129  if (VERSION_STRING MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+.*")
130  string (REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION_STRING}")
131  else ()
132  set (VERSION_PATCH "0")
133  endif()
134  else ()
135  set (VERSION_STRING "0.0")
136  set (VERSION_MAJOR "0")
137  set (VERSION_MINOR "0")
138  set (VERSION_PATCH "0")
139  endif ()
140  endif ()
141  else ()
142  set (VERSION_STRING "0.0")
143  set (VERSION_MAJOR "0")
144  set (VERSION_MINOR "0")
145  set (VERSION_PATCH "0")
146  endif ()
147  if (ARGC EQUAL 1)
148  set (${ARGV0} "${VERSION_STRING}" PARENT_SCOPE)
149  else ()
150  set (JYTHON_VERSION_STRING "${VERSION_STRING}" PARENT_SCOPE)
151  set (JYTHON_VERSION_MAJOR "${VERSION_MAJOR}" PARENT_SCOPE)
152  set (JYTHON_VERSION_MINOR "${VERSION_MINOR}" PARENT_SCOPE)
153  set (JYTHON_VERSION_PATCH "${VERSION_PATCH}" PARENT_SCOPE)
154  endif ()
155 endfunction ()
156 
157 # ----------------------------------------------------------------------------
158 ## @brief Get version of Perl interpreter.
159 #
160 # @param [out] ARGV1 If given, the named variable is set to the version string
161 # of the Perl interpreter. Otherwise, the variables
162 # @c PERL_VERSION_STRING, @c PERL_VERSION_MAJOR,
163 # @c PERL_VERSION_MINOR, and @c PERL_VERSION_PATCH are
164 # set in the scope of the caller.
165 function (basis_get_perl_version)
166  if (PERL_EXECUTABLE)
167  execute_process (COMMAND "${PERL_EXECUTABLE}" --version OUTPUT_VARIABLE VERSION)
168  else ()
169  set (VERSION)
170  endif ()
171  if (VERSION MATCHES "[( ]v([0-9]+)\\.([0-9]+)\\.([0-9]+)[ )]")
172  set (VERSION_MAJOR "${CMAKE_MATCH_1}")
173  set (VERSION_MINOR "${CMAKE_MATCH_2}")
174  set (VERSION_PATCH "${CMAKE_MATCH_3}")
175  set (VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
176  else ()
177  set (VERSION_STRING "0.0")
178  set (VERSION_MAJOR "0")
179  set (VERSION_MINOR "0")
180  set (VERSION_PATCH "0")
181  endif ()
182  if (ARGC EQUAL 1)
183  set (${ARGV0} "${VERSION_STRING}" PARENT_SCOPE)
184  else ()
185  set (PERL_VERSION_STRING "${VERSION_STRING}" PARENT_SCOPE)
186  set (PERL_VERSION_MAJOR "${VERSION_MAJOR}" PARENT_SCOPE)
187  set (PERL_VERSION_MINOR "${VERSION_MINOR}" PARENT_SCOPE)
188  set (PERL_VERSION_PATCH "${VERSION_PATCH}" PARENT_SCOPE)
189  endif ()
190 endfunction ()
191 
192 # ----------------------------------------------------------------------------
193 ## @brief Get version of Bash interpreter.
194 #
195 # @param [out] ARGV1 If given, the named variable is set to the version string
196 # of the Bash interpreter. Otherwise, the variables
197 # @c BASH_VERSION_STRING, @c BASH_VERSION_MAJOR,
198 # @c BASH_VERSION_MINOR, and @c BASH_VERSION_PATCH are
199 # set in the scope of the caller.
200 function (basis_get_bash_version)
201  if (BASH_EXECUTABLE)
202  execute_process (COMMAND "${BASH_EXECUTABLE}" --version OUTPUT_VARIABLE VERSION)
203  else ()
204  set (VERSION)
205  endif ()
206  if (VERSION MATCHES "version ([0-9]+)\\.([0-9]+)\\.([0-9]+)")
207  set (VERSION_MAJOR "${CMAKE_MATCH_1}")
208  set (VERSION_MINOR "${CMAKE_MATCH_2}")
209  set (VERSION_PATCH "${CMAKE_MATCH_3}")
210  set (VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
211  else ()
212  set (VERSION_STRING "0.0")
213  set (VERSION_MAJOR "0")
214  set (VERSION_MINOR "0")
215  set (VERSION_PATCH "0")
216  endif ()
217  if (ARGC EQUAL 1)
218  set (${ARGV0} "${VERSION_STRING}" PARENT_SCOPE)
219  else ()
220  set (BASH_VERSION_STRING "${VERSION_STRING}" PARENT_SCOPE)
221  set (BASH_VERSION_MAJOR "${VERSION_MAJOR}" PARENT_SCOPE)
222  set (BASH_VERSION_MINOR "${VERSION_MINOR}" PARENT_SCOPE)
223  set (BASH_VERSION_PATCH "${VERSION_PATCH}" PARENT_SCOPE)
224  endif ()
225 endfunction ()
226 
227 
228 ## @}
229 # end of Doxygen group
const unsigned int VERSION_MAJOR
The major version number.
Definition: basis.cxx:41
cmake PERL_VERSION_MINOR
Definition: FindPerl.cmake:84
cmake PERL_VERSION_STRING
Definition: FindPerl.cmake:86
function basis_get_bash_version(out ARGV1)
Get version of Bash interpreter.
cmake BASH_VERSION_MAJOR
Definition: FindBASH.cmake:12
cmake BASH_VERSION_STRING
Definition: FindBASH.cmake:39
cmake PYTHON_VERSION_MINOR
cmake BASH_VERSION_PATCH
Definition: FindBASH.cmake:38
cmake __BASIS_INTERPTOOLS_INCLUDED
cmake PYTHON_VERSION_PATCH
function basis_get_perl_version(out ARGV1)
Get version of Perl interpreter.
function basis_get_python_version(out ARGV1)
Get version of Python interpreter.
cmake BASH_VERSION_MINOR
Definition: FindBASH.cmake:37
cmake PERL_VERSION_PATCH
Definition: FindPerl.cmake:85
string VERSION
Project version.
Definition: utilities.sh:81
cmake RETVAL
cmake PYTHON_VERSION_MAJOR
cmake COMMAND
cmake JYTHON_VERSION_PATCH
function basis_get_jython_version(out ARGV1)
Get version of Jython interpreter.
const unsigned int VERSION_MINOR
The minor version number.
Definition: basis.cxx:42
cmake PERL_VERSION_MAJOR
Definition: FindPerl.cmake:83
const unsigned int VERSION_PATCH
The patch number.
Definition: basis.cxx:43
if(oldcoutbuf)
cmake PYTHON_VERSION_STRING