1 function(find_python_module MODULE PREFIX)
3 COMMAND ${PYTHON_EXECUTABLE} -c "import sys, ${MODULE}; sys.stdout.write(${MODULE}.__version__)"
4 OUTPUT_VARIABLE _version
5 RESULT_VARIABLE _status
7 OUTPUT_STRIP_TRAILING_WHITESPACE
10 # Export version variables to parent scope. This is needed by
11 # find_package_handle_standard_args
12 set(${PREFIX}_VERSION_STRING ${_version} PARENT_SCOPE)
14 # A status returns 0 if everything is okay. And zero is false. To make
15 # checking in the outer scope less surprising
17 set("${PREFIX}_STATUS" "success" PARENT_SCOPE)
18 endif (_status EQUAL 0)
19 endfunction(find_python_module MODULE PREFIX)
21 # This macro provides a simple way for basic python find modules to be
22 # extremely simple without duplicate boilerplate
23 macro(basic_python_module MODULE PREFIX)
24 find_python_module("${MODULE}" "${PREFIX}")
26 include(FindPackageHandleStandardArgs)
27 find_package_handle_standard_args(
29 REQUIRED_VARS "${PREFIX}_STATUS"
30 VERSION_VAR "${PREFIX}_VERSION_STRING"
33 # This isn't needed in the parent scope, just here.
34 unset("${PREFIX}_STATUS")
35 endmacro(basic_python_module MODULE PREFIX)