@@ -95,7 +95,7 @@ set(OPENVDB_PYTHON_DEPS)
9595
9696# @note explicitly only search for Development.Module from 3.18 as searching
9797# Development.Embed can cause issues on linux systems where it doesn't exist
98- set (OPENVDB_PYTHON_REQUIRED_COMPONENTS Development.Module)
98+ set (OPENVDB_PYTHON_REQUIRED_COMPONENTS Development.Module Interpreter )
9999
100100if (NOT DEFINED PYOPENVDB_INSTALL_DIRECTORY)
101101 list (APPEND OPENVDB_PYTHON_REQUIRED_COMPONENTS Interpreter)
@@ -107,6 +107,7 @@ endif()
107107
108108# Make sure find_package(Python) is only ever invoked once with all required components
109109find_package (Python COMPONENTS ${OPENVDB_PYTHON_REQUIRED_COMPONENTS} )
110+ find_package (pybind11 REQUIRED)
110111
111112openvdb_check_python_version(Python::Module
112113 "${Python_VERSION} "
@@ -124,110 +125,13 @@ if(USE_NUMPY)
124125 list (APPEND OPENVDB_PYTHON_DEPS Python::NumPy)
125126endif ()
126127
127- if (TARGET openvdb_shared AND NOT Boost_USE_STATIC_LIBS)
128- # @note Both of these must be set for Boost 1.70 (VFX2020) to link against
129- # boost shared libraries (more specifically libraries built with -fPIC).
130- # http://boost.2283326.n4.nabble.com/CMake-config-scripts-broken-in-1-70-td4708957.html
131- # https://github.com/boostorg/boost_install/commit/160c7cb2b2c720e74463865ef0454d4c4cd9ae7c
132- set (BUILD_SHARED_LIBS ON )
133- set (Boost_USE_STATIC_LIBS OFF )
134- endif ()
135-
136- # Boost python cmake is a mess. Implementations provided by boost's config
137- # cmake and kitware's module differ significantly and different cmake versions
138- # also do slightly different things regarding the major/minor suffixing. We
139- # previously attempted to handle all these cases by searching for boost_python
140- # three times, prioritize the version suffixed library and falling back such:
141- # - boost_python{Python_VERSION_MAJOR}${Python_VERSION_MINOR}
142- # - boost_python{Python_VERSION_MAJOR}
143- # - boost_python
144- # This unfortunately fails as CMake sometimes creates an empty Boost::python
145- # target on failed searches which stops subsequent searches. CMake also
146- # sometimes just fails to find the suffixed versions regardless.
147- #
148- # Newer boost versions now seems to say that the suffixing is only required if
149- # you have multiple boost installations, however the CMake implementation still
150- # requires it. Boost specifically reads from Boost_PYTHON_VERSION and
151- # Boost_PYTHON_VERSION_MAJOR variables. If the user has set these we just
152- # search for the non suffixed versions. Note that users can also provide
153- # Boost_NO_BOOST_CMAKE to skip the CMake implementation of FindBoost, though
154- # this will impact other boost components.
155- #
156- # @todo just get rid of boost python and migrate to pybind asap.
157-
158- set (_REQUIRED_BOOST_COMPONENTS python)
159- if (USE_NUMPY)
160- list (APPEND _REQUIRED_BOOST_COMPONENTS numpy)
161- endif ()
162-
163- if (Boost_PYTHON_VERSION OR
164- Boost_PYTHON_VERSION_MAJOR)
165- # Search for non-suffixed boost libraries
166- find_package (Boost ${MINIMUM_BOOST_VERSION} COMPONENTS ${_REQUIRED_BOOST_COMPONENTS} REQUIRED)
167- else ()
168- # Try to find matching boost components to the version of python detected
169- list (TRANSFORM _REQUIRED_BOOST_COMPONENTS APPEND ${Python_VERSION_MAJOR}${Python_VERSION_MINOR} )
170-
171- # Explicitly don't pass REQUIRED so we can provide the user a message with
172- # instructions to circumvent the major/minor requirement.
173- find_package (Boost ${MINIMUM_BOOST_VERSION} COMPONENTS ${_REQUIRED_BOOST_COMPONENTS} )
174-
175- # See if we found the target. If we didn't and CMake/Boost created a broken
176- # aliased target, we can't try another search. Build an error message and stop.
177- set (_BOOST_ERROR "" )
178- if (NOT TARGET Boost::python${Python_VERSION_MAJOR}${Python_VERSION_MINOR} AND TARGET Boost::python)
179- list (APPEND _BOOST_ERROR "boost_python${Python_VERSION_MAJOR}${Python_VERSION_MINOR} " )
180- endif ()
181- if (USE_NUMPY AND NOT TARGET Boost::numpy${Python_VERSION_MAJOR}${Python_VERSION_MINOR} AND TARGET Boost::numpy)
182- list (APPEND _BOOST_ERROR "boost_numpy${Python_VERSION_MAJOR}${Python_VERSION_MINOR} " )
183- endif ()
184-
185- if (_BOOST_ERROR)
186- message (FATAL_ERROR "Unable to find versioned boost python libraries (${_BOOST_ERROR} ). It's "
187- "recommended that your installation of boost_python/boost_numpy match your python version "
188- "exactly.\n "
189- "Alternatively, you can try to search for boost python versions explicitly with either:\n "
190- " 'Boost_PYTHON_VERSION=XY'\n "
191- " 'Boost_PYTHON_VERSION_MAJOR=X'" )
192- endif ()
193-
194- # If we didn't create the target but CMake didn't create a broken alias, try another search
195- if (NOT TARGET Boost::python${Python_VERSION_MAJOR}${Python_VERSION_MINOR} AND NOT TARGET Boost::python)
196- find_package (Boost ${MINIMUM_BOOST_VERSION} COMPONENTS python REQUIRED)
197- message (STATUS "Found non-suffixed boost_python, assuming to be python version "
198- "\" ${Python_VERSION_MAJOR} .${Python_VERSION_MINOR} \" compatible" )
199- endif ()
200- if (USE_NUMPY AND
201- NOT TARGET Boost::numpy${Python_VERSION_MAJOR}${Python_VERSION_MINOR} AND NOT TARGET Boost::numpy)
202- find_package (Boost ${MINIMUM_BOOST_VERSION} COMPONENTS numpy REQUIRED)
203- message (STATUS "Found non-suffixed boost_numpy, assuming to be python version "
204- "\" ${Python_VERSION_MAJOR} .${Python_VERSION_MINOR} \" compatible" )
205- endif ()
206- endif ()
207-
208- if (TARGET Boost::python${Python_VERSION_MAJOR}${Python_VERSION_MINOR} )
209- list (APPEND OPENVDB_PYTHON_DEPS Boost::python${Python_VERSION_MAJOR}${Python_VERSION_MINOR} )
210- elseif (TARGET Boost::python)
211- list (APPEND OPENVDB_PYTHON_DEPS Boost::python)
212- message (STATUS "Found non-suffixed boost_python, assuming to be python version "
213- "\" ${Python_VERSION_MAJOR} .${Python_VERSION_MINOR} \" compatible" )
214- endif ()
215-
216- if (TARGET Boost::numpy${Python_VERSION_MAJOR}${Python_VERSION_MINOR} )
217- list (APPEND OPENVDB_PYTHON_DEPS Boost::numpy${Python_VERSION_MAJOR}${Python_VERSION_MINOR} )
218- elseif (TARGET Boost::numpy)
219- list (APPEND OPENVDB_PYTHON_DEPS Boost::numpy)
220- message (STATUS "Found non-suffixed boost_numpy, assuming to be python version "
221- "\" ${Python_VERSION_MAJOR} .${Python_VERSION_MINOR} \" compatible" )
222- endif ()
223-
224128##########################################################################
225129
226130set (OPENVDB_PYTHON_MODULE_SOURCE_FILES
227131 pyFloatGrid.cc
132+ pyGridBase.cc
228133 pyIntGrid.cc
229134 pyMetadata.cc
230- pyPointGrid.cc
231135 pyOpenVDBModule.cc
232136 pyPointGrid.cc
233137 pyTransform.cc
@@ -242,21 +146,7 @@ if(NOT DEFINED PYOPENVDB_INSTALL_DIRECTORY)
242146 )
243147endif ()
244148
245- # @todo pyopenvdb is currently advertised as "linkable" by extension libraries
246- # so we have to mark it as SHARED. Really it should be MODULE, as the
247- # amount of manipulation required for native python support nullifies
248- # the ability for compilers to link against it (suffix/prefix renaming).
249- # A proper shared lib should be built with the functions required for
250- # extension (pyopenvdb.h) and a further module lib should be added
251- # that can be imported.
252-
253- add_library (pyopenvdb SHARED ${OPENVDB_PYTHON_MODULE_SOURCE_FILES} )
254- set_target_properties (pyopenvdb PROPERTIES PREFIX "" ) # no 'lib' prefix
255- if (UNIX )
256- set_target_properties (pyopenvdb PROPERTIES SUFFIX ".so" ) # must be .so (not .dylib)
257- elseif (WIN32 )
258- set_target_properties (pyopenvdb PROPERTIES SUFFIX ".pyd" ) # .pyd on windows
259- endif ()
149+ pybind11_add_module(pyopenvdb ${OPENVDB_PYTHON_MODULE_SOURCE_FILES} )
260150
261151target_link_libraries (pyopenvdb PUBLIC
262152 ${OPENVDB_LIB}
@@ -274,44 +164,12 @@ if(USE_AX)
274164 target_compile_definitions (pyopenvdb PUBLIC "-DPY_OPENVDB_USE_AX" )
275165endif ()
276166
277- # Configure static boost linkage
278- # @note This is usually undesirable. pyopenvdb should ideally be built
279- # against dynamic libs/runtime
280- # @note For some reason vcpkg decides to turn Boost_USE_STATIC_LIBS off
281- # when calling find_package(Boost), so we have to manually query the
282- # triplet to see if we're using boost static libs.
283- set (_BUILDING_STATIC_TRIPLET OFF )
284- if (VCPKG_TARGET_TRIPLET)
285- string (FIND ${VCPKG_TARGET_TRIPLET} "static" _BUILDING_STATIC_TRIPLET)
286- if (NOT (_BUILDING_STATIC_TRIPLET EQUAL -1))
287- set (_BUILDING_STATIC_TRIPLET ON )
288- else ()
289- set (_BUILDING_STATIC_TRIPLET OFF )
290- endif ()
291- endif ()
292-
293- if (Boost_USE_STATIC_LIBS OR _BUILDING_STATIC_TRIPLET)
294- message (WARNING "Building pyopenvdb against static variants of python/boost.python is not recommended." )
295- # Boost CMake should define these but doesn't...
296- target_compile_definitions (pyopenvdb PUBLIC "-DBOOST_PYTHON_STATIC_LIB" )
297- if (USE_NUMPY)
298- target_compile_definitions (pyopenvdb PUBLIC "-DBOOST_NUMPY_STATIC_LIB" )
299- endif ()
300- endif ()
301- unset (_BUILDING_STATIC_TRIPLET)
302-
303- set (PYTHON_PUBLIC_INCLUDE_NAMES
304- pyopenvdb.h
305- )
306-
307167install (TARGETS
308168 pyopenvdb
309169 DESTINATION
310170 ${PYOPENVDB_INSTALL_DIRECTORY}
311171)
312172
313- install (FILES ${PYTHON_PUBLIC_INCLUDE_NAMES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /openvdb/python)
314-
315173# pytest
316174if (OPENVDB_BUILD_PYTHON_UNITTESTS)
317175
0 commit comments