Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace CMake Python variables with new ones from FindPython3 module #402

Merged
merged 14 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,24 @@ endif()
if (SKIP_PYBIND11)
message(STATUS "SKIP_PYBIND11 set - disabling python bindings")
else()
include(IgnPython)
find_package(PythonLibs QUIET)
if (NOT PYTHONLIBS_FOUND)
IGN_BUILD_WARNING("Python is missing: Python interfaces are disabled.")
message (STATUS "Searching for Python - not found.")
#include(IgnPython) TODO: allow to specify for what it should search and then
# the code below can be removed; e.g. pybind needs Interpreter and Development components
# see https://pybind11.readthedocs.io/en/stable/cmake/index.html#new-findpython-mode
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
find_package(PythonLibs QUIET)
set(Python3_FOUND ${PYTHONLIBS_FOUND})
Bi0T1N marked this conversation as resolved.
Show resolved Hide resolved
set(Python3_VERSION ${PYTHONLIBS_VERSION_STRING})
else()
message (STATUS "Searching for Python - found version ${PYTHONLIBS_VERSION_STRING}.")
find_package(Python3 QUIET COMPONENTS Interpreter Development)
endif()

if (NOT Python3_FOUND)
IGN_BUILD_WARNING("Python3 is missing: Python interfaces are disabled.")
message (STATUS "Searching for Python3 - not found.")
else()
message (STATUS "Searching for Python3 - found version ${Python3_VERSION}.")

set(PYBIND11_PYTHON_VERSION 3)
find_package(Python3 QUIET COMPONENTS Interpreter Development)
find_package(pybind11 2.2 QUIET)

if (${pybind11_FOUND})
Expand Down
21 changes: 11 additions & 10 deletions src/python_pybind11/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug")
Bi0T1N marked this conversation as resolved.
Show resolved Hide resolved
# pybind11 logic for setting up a debug build when both a debug and release
# python interpreter are present in the system seems to be pretty much broken.
# This works around the issue.
set(PYTHON_LIBRARIES "${PYTHON_DEBUG_LIBRARIES}")
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
# TODO: remove once the minimum CMake version is increased
if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug")
# pybind11 logic for setting up a debug build when both a debug and release
# python interpreter are present in the system seems to be pretty much broken.
# This works around the issue.
set(PYTHON_LIBRARIES "${PYTHON_DEBUG_LIBRARIES}")
endif()
endif()

message(STATUS "Building pybind11 interfaces")
Expand Down Expand Up @@ -56,17 +59,15 @@ target_link_libraries(math PRIVATE
)

if(USE_SYSTEM_PATHS_FOR_PYTHON_INSTALLATION)
# Get install variable from Python3 module
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
# Python3_SITEARCH is available via FindPython3 from 3.12 on, workaround if needed
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c "if True:
COMMAND "${Python3_EXECUTABLE}" -c "if True:
from distutils import sysconfig as sc
print(sc.get_python_lib(plat_specific=True))"
OUTPUT_VARIABLE Python3_SITEARCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
# Get install variable from Python3 module
# Python3_SITEARCH is available from 3.12 on, workaround if needed:
find_package(Python3 COMPONENTS Interpreter)
endif()

if(USE_DIST_PACKAGES_FOR_PYTHON)
Expand Down