Debian Codegraph @

cmake/modules/FindPythonModule.cmake

raw
1 # Find if a Python module is installed
2 # Found at http://www.cmake.org/pipermail/cmake/2011-January/041666.html
3 # To use do: find_python_module(PyQt4 REQUIRED)
4
5 # Modified to give PY_FOO_FOUND global scope
6
7 function(find_python_module module)
8 string(TOUPPER ${module} module_upper)
9 if(NOT PY_${module_upper}_path)
10 if(ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED")
11 set(${module}_FIND_REQUIRED TRUE)
12 endif()
13 # A module's location is usually a directory, but for binary modules
14 # it's a .so file.
15 execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
16 "import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))"
17 RESULT_VARIABLE _${module}_status
18 OUTPUT_VARIABLE _${module}_location
19 ERROR_QUIET
20 OUTPUT_STRIP_TRAILING_WHITESPACE)
21 if(NOT _${module}_status)
22 set(PY_${module_upper}_path ${_${module}_location} CACHE STRING
23 "Location of Python module ${module}")
24 endif(NOT _${module}_status)
25 endif(NOT PY_${module_upper}_path)
26 find_package_handle_standard_args(PY_${module} DEFAULT_MSG PY_${module_upper}_path)
27
28 # Raise scope (make PY_FOO_FOUND global)
29 SET(PY_${module_upper}_FOUND ${PY_${module_upper}_FOUND} PARENT_SCOPE)
30 endfunction(find_python_module)