aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-04-15 15:27:49 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-04-21 13:19:58 +0200
commit4cde4075f97fc9f8d349591291289127666b35e5 (patch)
tree98a36dcfac8e46b11dfc27d38fcf33a8a5c41193
parent3506158551488788450498f9b4ffe86375172fea (diff)
Build system: Make numpy centrally available
In order to be able to use numpy in PySide6 modules besides libshiboken, move the numpy detection into the build scripts and pass it as a CMake variable. Task-number: PYSIDE-1540 Task-number: PYSIDE-1503 Change-Id: Ib30fdbab83904878286b7eaae1674ffba0f2febd Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--build_scripts/main.py6
-rw-r--r--build_scripts/utils.py10
-rw-r--r--sources/shiboken6/libshiboken/CMakeLists.txt28
3 files changed, 21 insertions, 23 deletions
diff --git a/build_scripts/main.py b/build_scripts/main.py
index a059ea834..0f887a830 100644
--- a/build_scripts/main.py
+++ b/build_scripts/main.py
@@ -46,7 +46,7 @@ import sys
from textwrap import dedent
import time
from .config import config
-from .utils import get_python_dict
+from .utils import get_numpy_location, get_python_dict
from .options import DistUtilsCommandMixin, OPTION
from .versions import PYSIDE, PYSIDE_MODULE, SHIBOKEN
from .wheel_utils import (get_package_version, get_qt_version,
@@ -768,6 +768,10 @@ class PysideBuild(_build, DistUtilsCommandMixin):
if OPTION['AVOID_PROTECTED_HACK']:
cmake_cmd.append("-DAVOID_PROTECTED_HACK=1")
+ numpy = get_numpy_location()
+ if numpy:
+ cmake_cmd.append(f"-DNUMPY_INCLUDE_DIR={numpy}")
+
if self.build_type.lower() == 'debug':
cmake_cmd.append(f"-DPYTHON_DEBUG_LIBRARY={self.py_library}")
diff --git a/build_scripts/utils.py b/build_scripts/utils.py
index d80e59a3d..0a9036905 100644
--- a/build_scripts/utils.py
+++ b/build_scripts/utils.py
@@ -38,6 +38,7 @@
#############################################################################
import sys
+from pathlib import Path
import os
import re
import stat
@@ -83,6 +84,15 @@ def update_env_path(newpaths):
os.environ['PATH'] = f"{path}{os.pathsep}{os.environ['PATH']}"
+def get_numpy_location():
+ for p in sys.path:
+ if 'site-' in p:
+ numpy = Path(p).resolve() / 'numpy'
+ if numpy.is_dir():
+ return os.fspath(numpy / 'core' / 'include')
+ return None
+
+
def winsdk_setenv(platform_arch, build_type):
from distutils.msvc9compiler import VERSION as MSVC_VERSION
from distutils.msvc9compiler import Reg
diff --git a/sources/shiboken6/libshiboken/CMakeLists.txt b/sources/shiboken6/libshiboken/CMakeLists.txt
index 84355e4d6..42d9ccb76 100644
--- a/sources/shiboken6/libshiboken/CMakeLists.txt
+++ b/sources/shiboken6/libshiboken/CMakeLists.txt
@@ -1,22 +1,5 @@
project(libshiboken)
-macro(get_numpy_location)
- execute_process(
- COMMAND ${PYTHON_EXECUTABLE} -c "if True:
- import sys
- import os
- numpy = ''
- for p in sys.path:
- if 'site-' in p:
- numpy = os.path.join(p, 'numpy')
- if os.path.exists(numpy):
- print(os.path.realpath(numpy))
- break"
- OUTPUT_VARIABLE PYTHON_NUMPY_LOCATION
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- message(STATUS "PYTHON_NUMPY_LOCATION: " ${PYTHON_NUMPY_LOCATION})
-endmacro()
-
option(ENABLE_VERSION_SUFFIX "Used to use current version in suffix to generated files. This is used to allow multiples versions installed simultaneous." FALSE)
if(ENABLE_VERSION_SUFFIX)
set(shiboken6_SUFFIX "-${shiboken_MAJOR_VERSION}.${shiboken_MINOR_VERSION}")
@@ -85,10 +68,11 @@ signature/signature_extend.cpp
signature/signature_helper.cpp
)
-get_numpy_location()
-
-if (NOT "${PYTHON_NUMPY_LOCATION}" STREQUAL "")
+if (NOT "${NUMPY_INCLUDE_DIR}" STREQUAL "")
+ message(STATUS "NUMPY_INCLUDE_DIR: " ${NUMPY_INCLUDE_DIR})
list(APPEND libshiboken_SRC sbknumpyarrayconverter.cpp)
+else()
+ message(STATUS "NUMPY not found")
endif()
set(APIEXTRACTOR_EXTRA_INCLUDES ${APIEXTRACTOR_EXTRA_INCLUDES} ${LIBXSLT_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR})
@@ -102,8 +86,8 @@ target_include_directories(libshiboken PUBLIC
$<INSTALL_INTERFACE:include/shiboken6>
)
-if (NOT "${PYTHON_NUMPY_LOCATION}" STREQUAL "")
- target_include_directories(libshiboken PRIVATE ${PYTHON_NUMPY_LOCATION}/core/include)
+if (NOT "${NUMPY_INCLUDE_DIR}" STREQUAL "")
+ target_include_directories(libshiboken PRIVATE ${NUMPY_INCLUDE_DIR})
target_compile_definitions(libshiboken PRIVATE -DHAVE_NUMPY
PRIVATE -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION)