From 5cad467a4925b34b8c927e8b7116978ac804fff3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 11 Sep 2023 22:02:51 +0200 Subject: [PATCH] Python: use the vendored pybind11 Add a target that resembles what you would get from "normal" use of pybind11 when following the examples. Link with it. Drop Boost:Python sources from libcalamares. --- 3rdparty/pybind11/CMakeLists.txt | 16 ++++++++++++++++ CMakeLists.txt | 31 +++++++++++++++++++++---------- src/libcalamares/CMakeLists.txt | 9 +++++++-- 3 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 3rdparty/pybind11/CMakeLists.txt diff --git a/3rdparty/pybind11/CMakeLists.txt b/3rdparty/pybind11/CMakeLists.txt new file mode 100644 index 000000000..4e89c6e46 --- /dev/null +++ b/3rdparty/pybind11/CMakeLists.txt @@ -0,0 +1,16 @@ +# === This file is part of Calamares - === +# +# SPDX-FileCopyrightText: 2023 Adriaan de Groot +# SPDX-License-Identifier: BSD-2-Clause +# +### +# +# This is a very-stripped-down way of getting the bundled pybind11 + +add_library(pybind11_headers INTERFACE) +add_library(pybind11::headers ALIAS pybind11_headers) + +target_include_directories(pybind11_headers INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) +target_link_libraries(pybind11_headers INTERFACE Python::Python) # Was searched-for at top-level + + diff --git a/CMakeLists.txt b/CMakeLists.txt index f0cd401c2..7112b8023 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,8 +23,9 @@ # WITH_ : try to enable (these usually default to ON). For # a list of WITH_ grep CMakeCache.txt after running # CMake once. These affect the ABI offered by Calamares. -# - PYTHON (enable Python Job modules) -# - QML (enable QML UI View modules) +# - PYBIND11 (use bundled pybind11, default ON, needs WITH_PYTHON) +# - PYTHON (enable Python Job modules, default ON if Python is found) +# - QML (enable QML UI View modules, default ON) # - QT6 (use Qt6 rather than Qt5, default to OFF) # The WITH_* options affect the ABI of Calamares: you must # build (C++) modules for Calamares with the same WITH_* @@ -80,7 +81,8 @@ option(INSTALL_POLKIT "Install Polkit configuration" ON) option(INSTALL_COMPLETION "Install shell completions" OFF) # When adding WITH_* that affects the ABI offered by libcalamares, # also update libcalamares/CalamaresConfig.h.in -option(WITH_PYTHON "Enable Python modules API (requires Boost.Python)." ON) +option(WITH_PYBIND11 "Use bundled pybind11 instead o Boost::Python" ON) +option(WITH_PYTHON "Enable Python modules API." ON) option(WITH_QML "Enable QML UI options." ON) option(WITH_QT6 "Use Qt6 instead of Qt5" OFF) # @@ -446,25 +448,30 @@ else() endif() add_feature_info(yaml-schema BUILD_SCHEMA_TESTING "Validate YAML (config files) with schema.${_schema_explanation}") -if(Python_Development_FOUND) +if(NOT Python_Development_FOUND) + message(STATUS "Disabling Python modules") + set(WITH_PYTHON OFF) + set(WITH_PYBIND11 OFF) +endif() + +if(WITH_PYTHON AND NOT WITH_PYBIND11) find_package(boost_python) if(NOT TARGET Boost::python) find_package(Boost ${BOOSTPYTHON_VERSION} COMPONENTS python) - set_package_properties(Boost PROPERTIES PURPOSE "Boost.Python is used for Python job modules.") + set_package_properties(Boost PROPERTIES + PURPOSE "Boost.Python is used for Python job modules (because WITH_PYBIND11 is OFF)." + TYPE REQUIRED + ) else() message(STATUS "Found boost_python with target Boost::python") set(Boost_FOUND ON) endif() endif() -if(NOT Python_Development_FOUND OR NOT Boost_FOUND) - message(STATUS "Disabling Boost::Python modules") - set(WITH_PYTHON OFF) -endif() - # Now we know the state of the ABI-options, copy them into "Calamares_" # prefixed variables, to match how the variables would-be-named # when building out-of-tree. +set(Calamares_WITH_PYBIND11 ${WITH_PYBIND11}) set(Calamares_WITH_PYTHON ${WITH_PYTHON}) set(Calamares_WITH_QML ${WITH_QML}) set(Calamares_WITH_QT6 ${WITH_QT6}) @@ -595,9 +602,13 @@ include(GNUInstallDirs) set(Calamares_LIBRARIES calamares) add_subdirectory(3rdparty/kdsingleapplication) +if(WITH_PYBIND11) + add_subdirectory(3rdparty/pybind11) +endif() add_subdirectory(src) add_feature_info(Python ${WITH_PYTHON} "Python job modules") +add_feature_info(Pybind11 ${WITH_PYBIND11} "Python using bundled pybind11") add_feature_info(Qml ${WITH_QML} "QML UI support") add_feature_info(Polkit ${INSTALL_POLKIT} "Install Polkit files") add_feature_info(KCrash ${BUILD_CRASH_REPORTING} "Crash dumps via KCrash") diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 2a3d9f641..ce821b967 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -115,8 +115,13 @@ endif() # # if(WITH_PYTHON) - target_sources(calamares PRIVATE PythonHelper.cpp PythonJob.cpp PythonJobApi.cpp) - target_link_libraries(calamares PRIVATE Python::Python Boost::python) + if(WITH_PYBIND11) + target_sources(calamares PRIVATE python/Api.cpp python/PythonJob.cpp) + target_link_libraries(calamares PRIVATE Python::Python pybind11::headers) + else() + target_sources(calamares PRIVATE PythonHelper.cpp PythonJob.cpp PythonJobApi.cpp) + target_link_libraries(calamares PRIVATE Python::Python Boost::python) + endif() endif() ### OPTIONAL GeoIP XML support