From 9a9a262ea171c1092fcab560db57bb8cc4e65ac9 Mon Sep 17 00:00:00 2001 From: Albert Lee Date: Mon, 19 May 2025 04:47:57 +0000 Subject: [PATCH] python: use built-in CMake FindPython module from CMake 3.12 or higher --- cmake/FindPython.cmake | 36 ------------------------------- src/plugins/CMakeLists.txt | 8 +++++-- src/plugins/python/CMakeLists.txt | 6 ++++-- 3 files changed, 10 insertions(+), 40 deletions(-) delete mode 100644 cmake/FindPython.cmake diff --git a/cmake/FindPython.cmake b/cmake/FindPython.cmake deleted file mode 100644 index 9b92bb2fe..000000000 --- a/cmake/FindPython.cmake +++ /dev/null @@ -1,36 +0,0 @@ -# -# SPDX-FileCopyrightText: 2003-2025 Sébastien Helleu -# SPDX-FileCopyrightText: 2009 Julien Louis -# -# SPDX-License-Identifier: GPL-3.0-or-later -# -# This file is part of WeeChat, the extensible chat client. -# -# WeeChat is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# WeeChat is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with WeeChat. If not, see . -# - -# - Find Python -# This module finds if Python is installed and determines where the include files -# and libraries are. It also determines what the name of the library is. This -# code sets the following variables: -# -# PYTHON_EXECUTABLE = full path to the python binary -# PYTHON_INCLUDE_DIRS = path to where python.h can be found -# PYTHON_LIBRARIES = path to where libpython.so* can be found -# PYTHON_LDFLAGS = python compiler options for linking - -pkg_check_modules(PYTHON python3-embed IMPORTED_TARGET GLOBAL) -if(NOT PYTHON_FOUND) - pkg_check_modules(PYTHON python3 IMPORTED_TARGET GLOBAL) -endif() diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 9facd9dbd..0b7196cb8 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -124,8 +124,12 @@ else() endif() if(ENABLE_SCRIPTS AND ENABLE_PYTHON) - find_package(Python) - if(PYTHON_FOUND) + if(CMAKE_VERSION VERSION_LESS "3.18.0") + find_package(Python 3.0 COMPONENTS Development) + else() + find_package(Python 3.0 COMPONENTS Development.Embed) + endif() + if(Python_FOUND) add_subdirectory(python) else() message(SEND_ERROR "Python not found") diff --git a/src/plugins/python/CMakeLists.txt b/src/plugins/python/CMakeLists.txt index 98030452f..1e1bfc6e2 100644 --- a/src/plugins/python/CMakeLists.txt +++ b/src/plugins/python/CMakeLists.txt @@ -25,8 +25,10 @@ add_library(python MODULE ) set_target_properties(python PROPERTIES PREFIX "") -if(PYTHON_FOUND) - target_link_libraries(python PkgConfig::PYTHON weechat_plugins_scripts coverage_config) +if(Python_FOUND) + include_directories(${Python_INCLUDE_DIRS}) + add_definitions(${Python_DEFINITIONS}) + target_link_libraries(python ${Python_LIBRARIES} weechat_plugins_scripts coverage_config) endif() install(TARGETS python LIBRARY DESTINATION "${WEECHAT_LIBDIR}/plugins")