Skip to content
Snippets Groups Projects
Commit 0bf3201d authored by Stefan Wunsch's avatar Stefan Wunsch Committed by Lorenzo Moneta
Browse files

Fix in `find_python_module` cmake function `REQUIRED` flag; adapt function so...

Fix in `find_python_module` cmake function `REQUIRED` flag; adapt function so that it prints cause of error
parent 03f3d550
No related branches found
No related tags found
No related merge requests found
......@@ -955,24 +955,28 @@ endfunction()
# find_python_module(module [REQUIRED])
#----------------------------------------------------------------------------
function(find_python_module module)
string(TOUPPER ${module} module_upper)
if(NOT PY_${module_upper})
if(ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED")
set(${module}_FIND_REQUIRED TRUE)
endif()
# A module's location is usually a directory, but for binary modules
# it's a .so file.
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))"
RESULT_VARIABLE _${module}_status
OUTPUT_VARIABLE _${module}_location
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT _${module}_status)
set(PY_${module_upper} ${_${module}_location} CACHE STRING "Location of Python module ${module}")
endif()
endif()
find_package_handle_standard_args(PY_${module} DEFAULT_MSG PY_${module_upper})
set(PY_${module_upper}_FOUND ${PY_${module_upper}_FOUND} PARENT_SCOPE)
string(TOUPPER ${module} module_upper)
if(NOT PY_${module_upper})
if(ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED")
set(py_${module}_FIND_REQUIRED TRUE)
endif()
# A module's location is usually a directory, but for binary modules
# it's a .so file.
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))"
RESULT_VARIABLE _${module}_status
OUTPUT_VARIABLE _${module}_location
ERROR_VARIABLE _${module}_error
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE)
if(NOT _${module}_status)
set(PY_${module_upper} ${_${module}_location} CACHE STRING "Location of Python module ${module}")
else(NOT _${module}_status)
message(STATUS "Failed to find Python module ${module}: ${_${module}_error}")
endif()
endif()
find_package_handle_standard_args(py_${module} DEFAULT_MSG PY_${module_upper})
set(PY_${module_upper}_FOUND ${PY_${module_upper}_FOUND} PARENT_SCOPE)
endfunction()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment