| From 52f44ec5c7b728a6afaca867e8d815fced2012ec Mon Sep 17 00:00:00 2001 |
| From: fuzzard <fuzzard@kodi.tv> |
| Date: Sat, 31 Jul 2021 19:22:08 +1000 |
| Subject: [PATCH] [cmake] findpython |
| |
| use cmakes (3.12+) FindPython3 module. |
| Provide cmake vars for user to overide specific version, and search path |
| |
| Backport of https://github.com/xbmc/xbmc/pull/20045 |
| |
| Patch sent upstream: https://github.com/xbmc/xbmc/pull/20989 |
| |
| Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de> |
| --- |
| CMakeLists.txt | 4 +- |
| cmake/modules/FindPython.cmake | 71 ++++++++++++++++++++++++++-------- |
| 2 files changed, 56 insertions(+), 19 deletions(-) |
| |
| diff --git a/CMakeLists.txt b/CMakeLists.txt |
| index 2d5369798d..9bed54ef40 100644 |
| --- a/CMakeLists.txt |
| +++ b/CMakeLists.txt |
| @@ -1,4 +1,4 @@ |
| -cmake_minimum_required(VERSION 3.4) |
| +cmake_minimum_required(VERSION 3.12) |
| if(WIN32) |
| # Version 3.15 is required to use "PREPEND" for dependencies |
| cmake_minimum_required(VERSION 3.15) |
| @@ -187,8 +187,6 @@ core_require_dep(${required_deps}) |
| find_package(TexturePacker REQUIRED) |
| find_package(JsonSchemaBuilder REQUIRED) |
| |
| -SET(PYTHON_VERSION 3.8) |
| - |
| if(ENABLE_MARIADBCLIENT AND NOT ENABLE_MARIADBCLIENT STREQUAL AUTO AND ENABLE_MYSQLCLIENT AND NOT ENABLE_MYSQLCLIENT STREQUAL AUTO) |
| MESSAGE(FATAL_ERROR "You can not use MySql and MariaDB at the same time. Disable one by adding -DENABLE_MYSQLCLIENT=OFF or -DENABLE_MARIADBCLIENT=OFF.") |
| elseif(ENABLE_MYSQLCLIENT AND NOT ENABLE_MYSQLCLIENT STREQUAL AUTO) |
| diff --git a/cmake/modules/FindPython.cmake b/cmake/modules/FindPython.cmake |
| index c40e12d551..35220b5426 100644 |
| --- a/cmake/modules/FindPython.cmake |
| +++ b/cmake/modules/FindPython.cmake |
| @@ -1,17 +1,56 @@ |
| -# - Try to find python |
| -# Once done this will define |
| +# FindPython |
| +# -------- |
| +# Finds Python3 libraries |
| +# |
| +# This module will search for the required python libraries on the system |
| +# If multiple versions are found, the highest version will be used. |
| +# |
| +# -------- |
| +# |
| +# the following variables influence behaviour: |
| +# |
| +# PYTHON_PATH - use external python not found in system paths |
| +# usage: -DPYTHON_PATH=/path/to/python/lib |
| +# PYTHON_VER - use exact python version, fail if not found |
| +# usage: -DPYTHON_VER=3.8 |
| +# |
| +# -------- |
| +# |
| +# This module will define the following variables: |
| # |
| # PYTHON_FOUND - system has PYTHON |
| +# PYTHON_VERSION - Python version number (Major.Minor) |
| # PYTHON_INCLUDE_DIRS - the python include directory |
| # PYTHON_LIBRARIES - The python libraries |
| +# PYTHON_LDFLAGS - Python provided link options |
| +# |
| +# -------- |
| +# |
| + |
| +# for Depends builds, set search root dir to depends path |
| +if(KODI_DEPENDSBUILD) |
| + set(Python3_USE_STATIC_LIBS TRUE) |
| + set(Python3_ROOT_DIR ${DEPENDS_PATH}/lib) |
| +endif() |
| + |
| +# Provide root dir to search for Python if provided |
| +if(PYTHON_PATH) |
| + set(Python3_ROOT_DIR ${PYTHON_PATH}) |
| + |
| + # unset cache var so we can generate again with a different dir (or none) if desired |
| + unset(PYTHON_PATH CACHE) |
| +endif() |
| + |
| +# Set specific version of Python to find if provided |
| +if(PYTHON_VER) |
| + set(VERSION ${PYTHON_VER}) |
| + set(EXACT_VER "EXACT") |
| |
| -if(PKG_CONFIG_FOUND) |
| - pkg_check_modules(PC_PYTHON python3>=3.5 QUIET) |
| + # unset cache var so we can generate again with a different ver (or none) if desired |
| + unset(PYTHON_VER CACHE) |
| endif() |
| |
| -find_program(PYTHON_EXECUTABLE python3 ONLY_CMAKE_FIND_ROOT_PATH) |
| -find_library(PYTHON_LIBRARY NAMES python3.9 python3.8 python3.7 python3.6 python3.5 PATHS ${PC_PYTHON_LIBDIR}) |
| -find_path(PYTHON_INCLUDE_DIR NAMES Python.h PATHS ${PC_PYTHON_INCLUDE_DIRS} PATH_SUFFIXES python3.9 python3.8 python3.7 python3.6 python3.5) |
| +find_package(Python3 ${VERSION} ${EXACT_VER} COMPONENTS Development) |
| |
| if(KODI_DEPENDSBUILD) |
| find_library(FFI_LIBRARY ffi REQUIRED) |
| @@ -27,17 +66,17 @@ if(KODI_DEPENDSBUILD) |
| endif() |
| endif() |
| |
| - set(PYTHON_LIBRARIES ${PYTHON_LIBRARY} ${FFI_LIBRARY} ${EXPAT_LIBRARY} ${INTL_LIBRARY} ${GMP_LIBRARY} ${PYTHON_DEP_LIBRARIES}) |
| -else() |
| - find_package(PythonLibs 3.5 REQUIRED) |
| - list(APPEND PYTHON_LIBRARIES ${PC_PYTHON_STATIC_LIBRARIES}) |
| + list(APPEND Python3_LIBRARIES ${FFI_LIBRARY} ${EXPAT_LIBRARY} ${INTL_LIBRARY} ${GMP_LIBRARY} ${PYTHON_DEP_LIBRARIES}) |
| endif() |
| |
| -include(FindPackageHandleStandardArgs) |
| -find_package_handle_standard_args(Python REQUIRED_VARS PYTHON_INCLUDE_DIR PYTHON_LIBRARY PYTHON_LIBRARIES) |
| -if(PYTHON_FOUND) |
| - set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIR}) |
| +if(Python3_FOUND) |
| list(APPEND PYTHON_DEFINITIONS -DHAS_PYTHON=1) |
| + # These are all set for easy integration with the rest of our build system |
| + set(PYTHON_FOUND ${Python3_FOUND}) |
| + set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS}) |
| + set(PYTHON_LIBRARIES ${Python3_LIBRARIES}) |
| + set(PYTHON_VERSION "${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}" CACHE INTERNAL "" FORCE) |
| + set(PYTHON_LDFLAGS ${Python3_LINK_OPTIONS}) |
| endif() |
| |
| -mark_as_advanced(PYTHON_EXECUTABLE PYTHON_INCLUDE_DIRS PYTHON_INCLUDE_DIR PYTHON_LIBRARY PYTHON_LIBRARIES PYTHON_LDFLAGS FFI_LIBRARY EXPAT_LIBRARY INTL_LIBRARY GMP_LIBRARY) |
| +mark_as_advanced(PYTHON_EXECUTABLE PYTHON_VERSION PYTHON_INCLUDE_DIRS PYTHON_LDFLAGS FFI_LIBRARY EXPAT_LIBRARY INTL_LIBRARY GMP_LIBRARY) |
| -- |
| 2.30.2 |
| |