-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reoganize pybind11 cmake configuration (#434)
This reconfigures the new pybind11 implementation so it can be built in parallel with the existing Boost.Python bindings, and arranges so that the Boost.Python bindings can be deprecated and removed once with new bindings are functional. It's now possible to build the pybind11-based bindings without requiring Boost.Python to be installed. The CMake option ``PYTHON`` specifies whether to build the Boost.Python-based bindings, same as always. The Boost.Python binding source code is under src/python. The new CMake optin ``PYBIND11`` specifies whether to build the pybind11-based bindings. The pybind11 binding source code is under src/pybind11. The bindings build into a module called "pybindimath" and a library called "libPyBindImath.so". These are temporary names until these bindings become official, at which time they'll be renamed to "imath". The new pybind11-based CMake configuration is simplfied, with all the setup inline in src/pybind11/PyBindImath/CMakeLists.txt. It does not rely on any of the sort of CMake functions or setups that the Boost.Python bindings pull from src/python/config. That code is overly complicated, and overly general since it's only used for two libraries (PyImathand PyImathNumpy). Signed-off-by: Cary Phillips <[email protected]>
- Loading branch information
Showing
12 changed files
with
218 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright Contributors to the OpenEXR Project. | ||
|
||
set(PYBINDIMATH_OVERRIDE_PYTHON_INSTALL_DIR "" CACHE STRING "Override the install location for imath.so and imathnumpy.so modules") | ||
|
||
######################## | ||
## Build related options | ||
|
||
# Suffix to append to root name, this helps with version management | ||
# but can be turned off if you don't care, or otherwise customized | ||
# | ||
set(PYBINDIMATH_LIB_SUFFIX "-${IMATH_VERSION_API}" CACHE STRING "String added to the end of all the libraries") | ||
# This provides a root for the unique name of the library based on | ||
# the version of python being compiled for | ||
set(PYBINDIMATH_LIB_PYTHONVER_ROOT "_Python" CACHE STRING "String added as a root to the identifier of the python version in the libraries") | ||
|
||
add_subdirectory(PyBindImath) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright Contributors to the OpenEXR Project. | ||
|
||
find_package(Python3 REQUIRED COMPONENTS Interpreter Development) | ||
find_package(pybind11 REQUIRED) | ||
|
||
# | ||
# Source/headers | ||
# | ||
|
||
set(PYBINDIMATH_SOURCES | ||
PyBindImathBox.cpp | ||
PyBindImathVec.cpp | ||
) | ||
|
||
set(PYBINDIMATH_HEADERS | ||
PyBindImathExport.h | ||
PyBindImath.h | ||
) | ||
|
||
# | ||
# shared library, e.g. libPyBindImath_Python3_11-3_2.so.30.3.2.0 | ||
# | ||
|
||
set(PYBINDIMATH_LIBRARY PyBindImath) | ||
|
||
add_library(${PYBINDIMATH_LIBRARY} SHARED ${PYBINDIMATH_SOURCES}) | ||
|
||
target_link_libraries(${PYBINDIMATH_LIBRARY} PRIVATE Imath::Imath pybind11::module) | ||
|
||
# Set include directories | ||
target_include_directories(${PYBINDIMATH_LIBRARY} PRIVATE ${Python3_INCLUDE_DIRS} ${Imath_INCLUDE_DIRS}) | ||
|
||
if(NOT "${PYBINDIMATH_LIB_PYTHONVER_ROOT}" STREQUAL "") | ||
set(pythonver_root "${PYBINDIMATH_LIB_PYTHONVER_ROOT}${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR}") | ||
message("pythonver_root ${PYBINDIMATH_LIB_PYTHONVER_ROOT}${Python3_VERSION_MAJOR}_${Python3_VERSION_MINOR}") | ||
endif() | ||
|
||
if(BUILD_SHARED_LIBS) | ||
# This creates the so-versioned library symlinks | ||
set_target_properties(${PYBINDIMATH_LIBRARY} PROPERTIES | ||
SOVERSION ${IMATH_LIB_SOVERSION} | ||
VERSION ${IMATH_LIB_VERSION} | ||
OUTPUT_NAME "${PYBINDIMATH_CURLIB_OUTROOT}${PYBINDIMATH_LIBRARY}${pythonver_root}${PYBINDIMATH_LIB_SUFFIX}" | ||
) | ||
endif() | ||
|
||
# | ||
# python module, e.g. pybindimath.cpython-311-x86_64-linux-gnu.so | ||
# | ||
|
||
set(PYBINDIMATH_MODULE pybindimath) | ||
|
||
pybind11_add_module(pybindimath MODULE pybindimathmodule.cpp $<TARGET_OBJECTS:${PYBINDIMATH_LIBRARY}>) | ||
|
||
target_link_libraries(${PYBINDIMATH_MODULE} PRIVATE Imath::Imath pybind11::module) | ||
|
||
if(SKBUILD) | ||
set(PYTHON_INSTALL_DIR ${SKBUILD_PLATLIB_DIR}) | ||
else() | ||
set(PYTHON_INSTALL_DIR "lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages") | ||
endif() | ||
|
||
if (IMATH_INSTALL) | ||
|
||
# module | ||
|
||
install(TARGETS ${PYBINDIMATH_MODULE} DESTINATION ${PYTHON_INSTALL_DIR} COMPONENT python) | ||
|
||
# shared library | ||
|
||
install(TARGETS ${PYBINDIMATH_LIBRARY} | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | ||
|
||
if(BUILD_SHARED_LIBS AND (NOT "${IMATH_LIB_SUFFIX}" STREQUAL "") AND IMATH_INSTALL_SYM_LINK) | ||
|
||
# create symlinks for the shared object so versions | ||
|
||
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) | ||
set(verlibname ${CMAKE_SHARED_LIBRARY_PREFIX}${PYBINDIMATH_LIBRARY}${pythonver_root}${IMATH_LIB_SUFFIX}${CMAKE_${uppercase_CMAKE_BUILD_TYPE}_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}) | ||
set(baselibname ${CMAKE_SHARED_LIBRARY_PREFIX}${PYBINDIMATH_LIBRARY}${pythonver_root}${CMAKE_${uppercase_CMAKE_BUILD_TYPE}_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}) | ||
file(CREATE_LINK ${verlibname} ${CMAKE_CURRENT_BINARY_DIR}/${baselibname} SYMBOLIC) | ||
if(WIN32) | ||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${baselibname} DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}) | ||
install(CODE "message(STATUS \"Creating symlink ${CMAKE_INSTALL_FULL_BINDIR}/${baselibname} -> ${verlibname}\")") | ||
else() | ||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${baselibname} DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) | ||
install(CODE "message(STATUS \"Creating symlink ${CMAKE_INSTALL_FULL_LIBDIR}/${baselibname} -> ${verlibname}\")") | ||
endif() | ||
endif() | ||
|
||
# pkgconfig | ||
|
||
set(pcinfile PyBindImath.pc.in) | ||
set(prefix ${CMAKE_INSTALL_PREFIX}) | ||
set(exec_prefix "\${prefix}") | ||
set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") | ||
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") | ||
string(REPLACE ".in" "" pcout ${pcinfile}) | ||
configure_file(${pcinfile} ${CMAKE_CURRENT_BINARY_DIR}/${pcout} @ONLY) | ||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${pcout} DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) | ||
|
||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## | ||
## SPDX-License-Identifier: BSD-3-Clause | ||
## Copyright Contributors to the OpenEXR Project. | ||
## | ||
|
||
prefix=@prefix@ | ||
exec_prefix=@exec_prefix@ | ||
libdir=@libdir@ | ||
includedir=@includedir@ | ||
pythonver=@pythonver_root@ | ||
|
||
Name: PyBindImath | ||
Description: pybind11-based python bindings for the Imath libraries | ||
Version: @IMATH_VERSION@ | ||
Libs: -L${libdir} -lImath${libsuffix} -lPyBindImath${pythonver$}${libsuffix} | ||
|
||
Cflags: -I${includedir} -I${includedir}/Imath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.