summaryrefslogtreecommitdiff
path: root/media-gfx/openvdb/files/openvdb-9.0.0-numpy.patch
blob: 5fa90a7b6524134e4ac718ee0cc148dc01d34b41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
Grabbed relevant parts from upstream PR for 9.x; it's a variant
of https://github.com/gentoo/gentoo/pull/22738 which was for earlier versions.

https://github.com/AcademySoftwareFoundation/openvdb/pull/1237

From 3c5f69efeacca762406a80d74b39b970c7023bd6 Mon Sep 17 00:00:00 2001
From: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
Date: Thu, 28 Oct 2021 16:54:10 +0100
Subject: [PATCH 1/3] Improvements to find_package Python usage. Primarily
 fixes an issues where NumPy needs to be specified along with the Development
 and Interpreter components in a single call

Signed-off-by: Nick Avramoussis <4256455+Idclip@users.noreply.github.com>
---
 openvdb/openvdb/python/CMakeLists.txt | 97 +++++++++++++--------------
 1 file changed, 46 insertions(+), 51 deletions(-)

diff --git a/openvdb/openvdb/python/CMakeLists.txt b/openvdb/openvdb/python/CMakeLists.txt
index 7b36379f9..5e9141e8c 100644
--- a/openvdb/openvdb/python/CMakeLists.txt
+++ b/openvdb/openvdb/python/CMakeLists.txt
@@ -55,25 +55,39 @@ endif()
 # be provided to find_package(Python) with differing major versions. e.g.
 # calls to find_package(Python 2.7) fails if python3 is found on the system.
 function(OPENVDB_CHECK_PYTHON_VERSION)
-  set(_PY_VERSION ${ARGV0})
-  set(_PY_PATH ${ARGV1})
-  if(NOT _PY_VERSION)
-    message(FATAL_ERROR "Could NOT find Python (Required is at least version "
-      "\"${MINIMUM_PYTHON_VERSION}\")"
-    )
-  elseif(_PY_VERSION VERSION_LESS MINIMUM_PYTHON_VERSION)
-    message(FATAL_ERROR "Could NOT find Python: Found unsuitable version \"${_PY_VERSION}\""
-      "but required is at least \"${MINIMUM_PYTHON_VERSION}\" (found ${_PY_PATH})"
-    )
-  else()
-    message(STATUS "Found Python: ${_PY_PATH}) (found suitable version \"${_PY_VERSION}\", "
-      "minimum required is \"${MINIMUM_PYTHON_VERSION}\")"
+  set(PY_TARGET ${ARGV0})
+  set(PY_TARGET_VERSION ${ARGV1})
+  set(PY_TARGET_INCLUDES ${ARGV2})
+  set(MIN_VERSION ${ARGV3})
+  set(FUTURE_MIN_VERSION ${ARGV4})
+
+  if(NOT TARGET ${PY_TARGET})
+    message(FATAL_ERROR "Could NOT find ${PY_TARGET} (Required is at least version "
+      "\"${MIN_VERSION}\")"
     )
   endif()
+
+  if(PY_TARGET_VERSION AND MIN_VERSION)
+    if(PY_TARGET_VERSION VERSION_LESS MIN_VERSION)
+      message(FATAL_ERROR "Could NOT find ${PY_TARGET}: Found unsuitable version "
+        "\"${PY_TARGET_VERSION}\" but required is at least \"${MIN_VERSION}\" (found ${PY_TARGET_INCLUDES})"
+      )
+    endif()
+  endif()
+
+  message(STATUS "Found ${PY_TARGET}: ${PY_TARGET_INCLUDES}) (found suitable "
+    "version \"${PY_TARGET_VERSION}\", minimum required is \"${MIN_VERSION}\")"
+  )
+
+  if(OPENVDB_FUTURE_DEPRECATION AND PY_TARGET_VERSION AND FUTURE_MIN_VERSION)
+    if(PY_TARGET_VERSION VERSION_LESS FUTURE_MIN_VERSION)
+      message(DEPRECATION "Support for ${PY_TARGET} versions < ${FUTURE_MIN_VERSION} "
+        "is deprecated and will be removed.")
+    endif()
+  endif()
 endfunction()
 
 # Configure Python and Numpy. Note that:
-#  - find_package(Python NumPy) requires CMake >= 3.14
 #  - find_package(Python Development) target Python::Module requires CMake >= 3.15
 #  - find_package(Python Development.Module) requires CMake >= 3.18
 # To ensure consistent versions between components Interpreter, Compiler,
@@ -85,38 +99,30 @@ endfunction()
 set(OPENVDB_PYTHON_DEPS)
 set(OPENVDB_PYTHON_REQUIRED_COMPONENTS Development)
 if(NOT DEFINED PYOPENVDB_INSTALL_DIRECTORY)
-    list(APPEND OPENVDB_PYTHON_REQUIRED_COMPONENTS Interpreter)
+  list(APPEND OPENVDB_PYTHON_REQUIRED_COMPONENTS Interpreter)
 endif()
 
-find_package(Python QUIET COMPONENTS ${OPENVDB_PYTHON_REQUIRED_COMPONENTS})
-OPENVDB_CHECK_PYTHON_VERSION(${Python_VERSION} ${Python_INCLUDE_DIRS})
-
 if(USE_NUMPY)
-  find_package(Python QUIET COMPONENTS NumPy)
-  if(NOT TARGET Python::NumPy)
-      message(FATAL_ERROR "Could NOT find NumPy (Required is at least version "
-        "\"${MINIMUM_NUMPY_VERSION}\")"
-      )
-  elseif(Python_NumPy_VERSION VERSION_LESS MINIMUM_NUMPY_VERSION)
-    message(FATAL_ERROR "Could NOT find NumPy: Found unsuitable version \"${Python_NumPy_VERSION}\""
-      "but required is at least \"${MINIMUM_NUMPY_VERSION}\" (found ${Python_NumPy_INCLUDE_DIRS})"
-    )
-  else()
-    message(STATUS "Found NumPy: ${Python_NumPy_INCLUDE_DIRS} (found suitable "
-      "version \"${Python_NumPy_VERSION}\", minimum required is "
-      "\"${MINIMUM_NUMPY_VERSION}\")"
-    )
-  endif()
-  list(APPEND OPENVDB_PYTHON_DEPS Python::NumPy)
+  list(APPEND OPENVDB_PYTHON_REQUIRED_COMPONENTS NumPy)
 endif()
 
+# Make sure find_package(Python) is only ever invoked once with all required components
+find_package(Python COMPONENTS ${OPENVDB_PYTHON_REQUIRED_COMPONENTS})
+
+openvdb_check_python_version(Python::Module
+  "${Python_VERSION}"
+  "${Python_INCLUDE_DIRS}"
+  "${MINIMUM_PYTHON_VERSION}"
+  "${FUTURE_MINIMUM_PYTHON_VERSION}")
+list(APPEND OPENVDB_PYTHON_DEPS Python::Module)
+
 if(USE_NUMPY)
-  if(OPENVDB_FUTURE_DEPRECATION AND FUTURE_MINIMUM_NUMPY_VERSION)
-    if(Python_NumPy_VERSION VERSION_LESS FUTURE_MINIMUM_NUMPY_VERSION)
-      message(DEPRECATION "Support for NumPy versions < ${FUTURE_MINIMUM_NUMPY_VERSION} "
-        "is deprecated and will be removed.")
-    endif()
-  endif()
+  openvdb_check_python_version(Python::NumPy
+    "${Python_NumPy_VERSION}"
+    "${Python_NumPy_INCLUDE_DIRS}"
+    "${MINIMUM_NUMPY_VERSION}"
+    "${FUTURE_MINIMUM_NUMPY_VERSION}")
+  list(APPEND OPENVDB_PYTHON_DEPS Python::NumPy)
 endif()
 
 if(TARGET openvdb_shared AND NOT Boost_USE_STATIC_LIBS)
@@ -230,17 +236,6 @@ elseif(WIN32)
   set_target_properties(pyopenvdb PROPERTIES SUFFIX ".pyd") # .pyd on windows
 endif()
 
-if(TARGET Python::Module)
-  list(APPEND OPENVDB_PYTHON_DEPS Python::Module)
-else()
-  if(APPLE)
-    target_include_directories(pyopenvdb SYSTEM PUBLIC ${Python_INCLUDE_DIRS})
-    target_link_options(pyopenvdb PUBLIC -undefined dynamic_lookup)
-  else()
-    list(APPEND OPENVDB_PYTHON_DEPS Python::Python)
-  endif()
-endif()
-
 target_link_libraries(pyopenvdb PUBLIC
   ${OPENVDB_LIB}
   ${OPENVDB_PYTHON_DEPS}