1 ############################################################################## 2 # @file FindJythonInterp.cmake 3 # @brief Find Jython interpreter. 5 # @par Output variables: 8 # @tp @b JYTHONINTERP_FOUND @endtp 9 # <td>Whether the Jython executable was found.</td> 12 # @tp @b JYTHON_EXECUTABLE @endtp 13 # <td>Path to the Jython interpreter.</td> 16 # @tp @b JYTHON_VERSION_STRING @endtp 17 # <td>Jython version found, e.g. 2.5.2.</td> 20 # @tp @b JYTHON_VERSION_MAJOR @endtp 21 # <td>Jython major version found, e.g. 2.</td> 24 # @tp @b JYTHON_VERSION_MINOR @endtp 25 # <td>Jython minor version found, e.g. 5.</td> 28 # @tp @b JYTHON_VERSION_PATCH @endtp 29 # <td>Jython patch version found, e.g. 2.</td> 33 # @ingroup CMakeFindModules 34 ############################################################################## 36 #============================================================================= 37 # Copyright 2011-2012 University of Pennsylvania 38 # Copyright 2013-2016 Andreas Schuh <andreas.schuh.84@gmail.com> 40 # Distributed under the OSI-approved BSD License (the "License"); 41 # see accompanying file Copyright.txt for details. 43 # This software is distributed WITHOUT ANY WARRANTY; without even the 44 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 45 # See the License for more information. 46 #============================================================================= 47 # (To distribute this file outside of CMake, substitute the full 48 # License text for the above reference.) 58 set(_JythonInterp_HINTS)
59 if (_JythonInterp_ROOT)
60 list(APPEND _JythonInterp_HINTS
"${_JythonInterp_ROOT}/bin")
64 set(_JythonInterp_PATHS
70 # find jython executable
71 find_program(JYTHON_EXECUTABLE
73 HINTS ${_JythonInterp_HINTS}
74 PATHS ${_JythonInterp_PATHS}
77 mark_as_advanced(JYTHON_EXECUTABLE)
79 # determine jython version 80 if (JYTHON_EXECUTABLE)
81 execute_process (
COMMAND "${JYTHON_EXECUTABLE}" -c
"import sys; sys.stdout.write(';'.join([str(x) for x in sys.version_info[:3]]))" 82 OUTPUT_VARIABLE _JYTHON_VERSION
83 RESULT_VARIABLE _JYTHON_VERSION_RESULT
85 if (_JYTHON_VERSION_RESULT EQUAL 0)
86 string (REPLACE
";" "." JYTHON_VERSION_STRING
"${_JYTHON_VERSION}")
87 list (GET _JYTHON_VERSION 0 JYTHON_VERSION_MAJOR)
88 list (GET _JYTHON_VERSION 1 JYTHON_VERSION_MINOR)
90 if (JYTHON_VERSION_PATCH EQUAL 0)
91 # it's called "Jython 2.5", not "2.5.0" 92 string (REGEX REPLACE
"\\.0$" "" JYTHON_VERSION_STRING
"${JYTHON_VERSION_STRING}")
95 # sys.version predates sys.version_info, so use that 96 execute_process(
COMMAND "${JYTHON_EXECUTABLE}" -c
"import sys; sys.stdout.write(sys.version)" 97 OUTPUT_VARIABLE _JYTHON_VERSION
98 RESULT_VARIABLE _JYTHON_VERSION_RESULT
100 if (_JYTHON_VERSION_RESULT EQUAL 0)
101 string (REGEX REPLACE
" .*" "" JYTHON_VERSION_STRING
"${_JYTHON_VERSION}")
102 string (REGEX REPLACE
"^([0-9]+)\\.[0-9]+.*" "\\1" JYTHON_VERSION_MAJOR
"${JYTHON_VERSION_STRING}")
103 string (REGEX REPLACE
"^[0-9]+\\.([0-9])+.*" "\\1" JYTHON_VERSION_MINOR
"${JYTHON_VERSION_STRING}")
104 if (JYTHON_VERSION_STRING MATCHES
"^[0-9]+\\.[0-9]+\\.[0-9]+.*")
105 string (REGEX REPLACE
"^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" JYTHON_VERSION_PATCH
"${JYTHON_VERSION_STRING}")
107 set (JYTHON_VERSION_PATCH
"0")
110 set (JYTHON_VERSION_STRING)
111 set (JYTHON_VERSION_MAJOR)
112 set (JYTHON_VERSION_MINOR)
113 set (JYTHON_VERSION_PATCH)
116 unset (_JYTHON_VERSION)
117 unset (_JYTHON_VERSION_RESULT)
120 # handle QUIET, REQUIRED, and [EXACT] VERSION arguments and set JYTHONINTERP_FOUND 121 include(FindPackageHandleStandardArgs)
122 find_package_handle_standard_args(
127 JYTHON_VERSION_STRING
130 # unset local auxiliary variables 131 unset(_JythonInterp_ROOT)
132 unset(_JythonInterp_HINTS)
133 unset(_JythonInterp_PATHS)
cmake JYTHON_VERSION_PATCH