From cbe7c0d8847b06f125b0aa854a678e34d83322ac Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Wed, 22 May 2024 16:11:15 -0700 Subject: [PATCH] Find python directly instead of using GzPython (#588) Part of gazebosim/gz-cmake#350. Signed-off-by: Steve Peters --- CMakeLists.txt | 14 ++++++-------- src/python_pybind11/CMakeLists.txt | 7 ++++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2526df88..f9fc1f82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,16 +99,14 @@ endif() if (SKIP_PYBIND11) message(STATUS "SKIP_PYBIND11 set - disabling python bindings") else() - include(GzPython) - find_package(PythonLibs QUIET) - if (NOT PYTHONLIBS_FOUND) - GZ_BUILD_WARNING("Python is missing: Python interfaces are disabled.") - message (STATUS "Searching for Python - not found.") + find_package(Python3 REQUIRED + COMPONENTS Interpreter + OPTIONAL_COMPONENTS Development + ) + if (NOT Python3_Development_FOUND) + GZ_BUILD_WARNING("Python development libraries are missing: Python interfaces are disabled.") else() - message (STATUS "Searching for Python - found version ${PYTHONLIBS_VERSION_STRING}.") - set(PYBIND11_PYTHON_VERSION 3) - find_package(Python3 QUIET COMPONENTS Interpreter Development) find_package(pybind11 2.2 QUIET) if (${pybind11_FOUND}) diff --git a/src/python_pybind11/CMakeLists.txt b/src/python_pybind11/CMakeLists.txt index 6f9fb755..27b5cfa3 100644 --- a/src/python_pybind11/CMakeLists.txt +++ b/src/python_pybind11/CMakeLists.txt @@ -73,9 +73,10 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") endif() if(USE_SYSTEM_PATHS_FOR_PYTHON_INSTALLATION) - # Get install variable from Python3 module - # Python3_SITEARCH is available from 3.12 on, workaround if needed: - find_package(Python3 COMPONENTS Interpreter) + if(NOT Python3_SITEARCH) + # Get install variable from Python3 module + find_package(Python3 COMPONENTS Interpreter) + endif() if(USE_DIST_PACKAGES_FOR_PYTHON) string(REPLACE "site-packages" "dist-packages" GZ_PYTHON_INSTALL_PATH ${Python3_SITEARCH})