0002-cmake-findpython.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. From 52f44ec5c7b728a6afaca867e8d815fced2012ec Mon Sep 17 00:00:00 2001
  2. From: fuzzard <fuzzard@kodi.tv>
  3. Date: Sat, 31 Jul 2021 19:22:08 +1000
  4. Subject: [PATCH] [cmake] findpython
  5. use cmakes (3.12+) FindPython3 module.
  6. Provide cmake vars for user to overide specific version, and search path
  7. Backport of https://github.com/xbmc/xbmc/pull/20045
  8. Patch sent upstream: https://github.com/xbmc/xbmc/pull/20989
  9. Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
  10. ---
  11. CMakeLists.txt | 4 +-
  12. cmake/modules/FindPython.cmake | 71 ++++++++++++++++++++++++++--------
  13. 2 files changed, 56 insertions(+), 19 deletions(-)
  14. diff --git a/CMakeLists.txt b/CMakeLists.txt
  15. index 2d5369798d..9bed54ef40 100644
  16. --- a/CMakeLists.txt
  17. +++ b/CMakeLists.txt
  18. @@ -1,4 +1,4 @@
  19. -cmake_minimum_required(VERSION 3.4)
  20. +cmake_minimum_required(VERSION 3.12)
  21. if(WIN32)
  22. # Version 3.15 is required to use "PREPEND" for dependencies
  23. cmake_minimum_required(VERSION 3.15)
  24. @@ -187,8 +187,6 @@ core_require_dep(${required_deps})
  25. find_package(TexturePacker REQUIRED)
  26. find_package(JsonSchemaBuilder REQUIRED)
  27. -SET(PYTHON_VERSION 3.8)
  28. -
  29. if(ENABLE_MARIADBCLIENT AND NOT ENABLE_MARIADBCLIENT STREQUAL AUTO AND ENABLE_MYSQLCLIENT AND NOT ENABLE_MYSQLCLIENT STREQUAL AUTO)
  30. 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.")
  31. elseif(ENABLE_MYSQLCLIENT AND NOT ENABLE_MYSQLCLIENT STREQUAL AUTO)
  32. diff --git a/cmake/modules/FindPython.cmake b/cmake/modules/FindPython.cmake
  33. index c40e12d551..35220b5426 100644
  34. --- a/cmake/modules/FindPython.cmake
  35. +++ b/cmake/modules/FindPython.cmake
  36. @@ -1,17 +1,56 @@
  37. -# - Try to find python
  38. -# Once done this will define
  39. +# FindPython
  40. +# --------
  41. +# Finds Python3 libraries
  42. +#
  43. +# This module will search for the required python libraries on the system
  44. +# If multiple versions are found, the highest version will be used.
  45. +#
  46. +# --------
  47. +#
  48. +# the following variables influence behaviour:
  49. +#
  50. +# PYTHON_PATH - use external python not found in system paths
  51. +# usage: -DPYTHON_PATH=/path/to/python/lib
  52. +# PYTHON_VER - use exact python version, fail if not found
  53. +# usage: -DPYTHON_VER=3.8
  54. +#
  55. +# --------
  56. +#
  57. +# This module will define the following variables:
  58. #
  59. # PYTHON_FOUND - system has PYTHON
  60. +# PYTHON_VERSION - Python version number (Major.Minor)
  61. # PYTHON_INCLUDE_DIRS - the python include directory
  62. # PYTHON_LIBRARIES - The python libraries
  63. +# PYTHON_LDFLAGS - Python provided link options
  64. +#
  65. +# --------
  66. +#
  67. +
  68. +# for Depends builds, set search root dir to depends path
  69. +if(KODI_DEPENDSBUILD)
  70. + set(Python3_USE_STATIC_LIBS TRUE)
  71. + set(Python3_ROOT_DIR ${DEPENDS_PATH}/lib)
  72. +endif()
  73. +
  74. +# Provide root dir to search for Python if provided
  75. +if(PYTHON_PATH)
  76. + set(Python3_ROOT_DIR ${PYTHON_PATH})
  77. +
  78. + # unset cache var so we can generate again with a different dir (or none) if desired
  79. + unset(PYTHON_PATH CACHE)
  80. +endif()
  81. +
  82. +# Set specific version of Python to find if provided
  83. +if(PYTHON_VER)
  84. + set(VERSION ${PYTHON_VER})
  85. + set(EXACT_VER "EXACT")
  86. -if(PKG_CONFIG_FOUND)
  87. - pkg_check_modules(PC_PYTHON python3>=3.5 QUIET)
  88. + # unset cache var so we can generate again with a different ver (or none) if desired
  89. + unset(PYTHON_VER CACHE)
  90. endif()
  91. -find_program(PYTHON_EXECUTABLE python3 ONLY_CMAKE_FIND_ROOT_PATH)
  92. -find_library(PYTHON_LIBRARY NAMES python3.9 python3.8 python3.7 python3.6 python3.5 PATHS ${PC_PYTHON_LIBDIR})
  93. -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)
  94. +find_package(Python3 ${VERSION} ${EXACT_VER} COMPONENTS Development)
  95. if(KODI_DEPENDSBUILD)
  96. find_library(FFI_LIBRARY ffi REQUIRED)
  97. @@ -27,17 +66,17 @@ if(KODI_DEPENDSBUILD)
  98. endif()
  99. endif()
  100. - set(PYTHON_LIBRARIES ${PYTHON_LIBRARY} ${FFI_LIBRARY} ${EXPAT_LIBRARY} ${INTL_LIBRARY} ${GMP_LIBRARY} ${PYTHON_DEP_LIBRARIES})
  101. -else()
  102. - find_package(PythonLibs 3.5 REQUIRED)
  103. - list(APPEND PYTHON_LIBRARIES ${PC_PYTHON_STATIC_LIBRARIES})
  104. + list(APPEND Python3_LIBRARIES ${FFI_LIBRARY} ${EXPAT_LIBRARY} ${INTL_LIBRARY} ${GMP_LIBRARY} ${PYTHON_DEP_LIBRARIES})
  105. endif()
  106. -include(FindPackageHandleStandardArgs)
  107. -find_package_handle_standard_args(Python REQUIRED_VARS PYTHON_INCLUDE_DIR PYTHON_LIBRARY PYTHON_LIBRARIES)
  108. -if(PYTHON_FOUND)
  109. - set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIR})
  110. +if(Python3_FOUND)
  111. list(APPEND PYTHON_DEFINITIONS -DHAS_PYTHON=1)
  112. + # These are all set for easy integration with the rest of our build system
  113. + set(PYTHON_FOUND ${Python3_FOUND})
  114. + set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
  115. + set(PYTHON_LIBRARIES ${Python3_LIBRARIES})
  116. + set(PYTHON_VERSION "${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}" CACHE INTERNAL "" FORCE)
  117. + set(PYTHON_LDFLAGS ${Python3_LINK_OPTIONS})
  118. endif()
  119. -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)
  120. +mark_as_advanced(PYTHON_EXECUTABLE PYTHON_VERSION PYTHON_INCLUDE_DIRS PYTHON_LDFLAGS FFI_LIBRARY EXPAT_LIBRARY INTL_LIBRARY GMP_LIBRARY)
  121. --
  122. 2.30.2