diff --git a/cmake/BornAgain/multipython/PyDependences.cmake b/cmake/BornAgain/multipython/PyDependences.cmake index 6e6707318713a9d96d37f497583033bdf83aed0c..83528071959793fd59fc560da961119fd870e908 100644 --- a/cmake/BornAgain/multipython/PyDependences.cmake +++ b/cmake/BornAgain/multipython/PyDependences.cmake @@ -63,8 +63,21 @@ function(find_multipython_dependences main_python_version) endforeach() if(BORNAGAIN_PYTHON_PACKAGE_VERSIONS) + + # check presence of some Python modules + foreach(pkg build setuptools wheel) + message(STATUS "Searching Python package ${pkg}") + execute_process( + COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/cmake/tests/find_pkg.py ${pkg} + RESULT_VARIABLE PKG_FOUND) + if(NOT PKG_FOUND EQUAL 0) + message(FATAL_ERROR "Python package ${pkg} not found") + endif() + endforeach() + # add the required build directories for the Python packages set_python_package_dirs("${BORNAGAIN_PYTHON_PACKAGE_VERSIONS}") + endif(BORNAGAIN_PYTHON_PACKAGE_VERSIONS) # A member is included to build the _main_ version diff --git a/cmake/tests/find_pkg.py b/cmake/tests/find_pkg.py new file mode 100755 index 0000000000000000000000000000000000000000..e0ca1f60080c2a77946efdefc0aa1b390c45596a --- /dev/null +++ b/cmake/tests/find_pkg.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +# A BornAgain auxiliary script. +# License: Public Domain. + +# Checks whether a given Python3 module is installed. +# +# Takes module name as argument. +# Returns 0 if module can be imported. Otherwise returns 1. + +import sys +pkg = sys.argv[1] +try: + __import__(pkg) +except: + print(" find_pkg.py: package", pkg, "not found") + sys.exit(1) + +print(" find_pkg.py: package", pkg, "found") +sys.exit(0)