aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmake/modules/FindPython.cmake12
-rw-r--r--cmake/modules/buildtools/FindPythonInterpreter.cmake56
-rw-r--r--cmake/scripts/linux/Install.cmake1
3 files changed, 57 insertions, 12 deletions
diff --git a/cmake/modules/FindPython.cmake b/cmake/modules/FindPython.cmake
index 8258f92f0b..56d320e1a9 100644
--- a/cmake/modules/FindPython.cmake
+++ b/cmake/modules/FindPython.cmake
@@ -20,7 +20,6 @@
#
# PYTHON_FOUND - system has PYTHON
# PYTHON_VERSION - Python version number (Major.Minor)
-# PYTHON_EXECUTABLE - Python interpreter binary
# PYTHON_INCLUDE_DIRS - the python include directory
# PYTHON_LIBRARIES - The python libraries
# PYTHON_LDFLAGS - Python provided link options
@@ -76,23 +75,12 @@ if(KODI_DEPENDSBUILD)
endif()
list(APPEND Python3_LIBRARIES ${LZMA_LIBRARY} ${FFI_LIBRARY} ${EXPAT_LIBRARY} ${INTL_LIBRARY} ${GMP_LIBRARY} ${PYTHON_DEP_LIBRARIES})
-else()
- if(CORE_SYSTEM_NAME STREQUAL linux)
- if(HOST_CAN_EXECUTE_TARGET)
- find_package(Python3 ${VERSION} ${EXACT_VER} COMPONENTS Interpreter)
- else()
- find_package(Python3 COMPONENTS Interpreter)
- endif()
- endif()
endif()
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})
- if(NOT PYTHON_EXECUTABLE)
- set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE} CACHE FILEPATH "Python interpreter" FORCE)
- endif()
set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
set(PYTHON_LIBRARIES ${Python3_LIBRARIES})
set(PYTHON_VERSION "${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}" CACHE INTERNAL "" FORCE)
diff --git a/cmake/modules/buildtools/FindPythonInterpreter.cmake b/cmake/modules/buildtools/FindPythonInterpreter.cmake
new file mode 100644
index 0000000000..1aced21952
--- /dev/null
+++ b/cmake/modules/buildtools/FindPythonInterpreter.cmake
@@ -0,0 +1,56 @@
+# FindPython
+# --------
+# Finds Python3 Interpreter
+#
+# This module will search for a Python3 Interpreter
+#
+# --------
+#
+# the following variables influence behaviour:
+#
+# PYTHON_INTERPRETER_PATH - use external python not found in system paths
+# usage: -DPYTHON_INTERPRETER_PATH=/path/to/python3
+#
+# --------
+#
+# This will define the following variable:
+#
+# PYTHON_EXECUTABLE - The HOST python executable
+#
+
+# We limit search paths to rule out TARGET paths that will populate the default cmake/package paths
+# Note: we do not do a find_package call as it will populate targets based on HOST
+# information and pollute the TARGET python searches when required for actual target platform.
+find_program(PYTHON3_INTERPRETER_EXECUTABLE NAMES python3 python
+ HINTS ${PYTHON_INTERPRETER_PATH} ${NATIVEPREFIX}/bin
+ NO_CACHE
+ NO_PACKAGE_ROOT_PATH
+ NO_CMAKE_PATH
+ NO_CMAKE_ENVIRONMENT_PATH
+ NO_CMAKE_INSTALL_PREFIX)
+
+if(PYTHON3_INTERPRETER_EXECUTABLE)
+ execute_process(COMMAND "${PYTHON3_INTERPRETER_EXECUTABLE}" --version
+ OUTPUT_VARIABLE PYTHON3_INTERPRETER_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(REGEX REPLACE "^Python (.*)" "\\1" PYTHON3_INTERPRETER_VERSION "${PYTHON3_INTERPRETER_VERSION}")
+
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(PythonInterpreter
+ REQUIRED_VARS PYTHON3_INTERPRETER_EXECUTABLE PYTHON3_INTERPRETER_VERSION
+ VERSION_VAR PYTHON3_INTERPRETER_VERSION)
+
+ if(PythonInterpreter_FOUND)
+ # We explicitly use a CACHE variable instead of a TARGET as execute_command is not
+ # able to use a TARGET - https://gitlab.kitware.com/cmake/cmake/-/issues/18364
+ set(PYTHON_EXECUTABLE ${PYTHON3_INTERPRETER_EXECUTABLE} CACHE FILEPATH "Host Python interpreter" FORCE)
+ else()
+ if(PythonInterpreter_FIND_REQUIRED)
+ message(FATAL_ERROR "A python3 interpreter was not found. Consider providing path using -DPYTHON_INTERPRETER_PATH=<path/to/python3>")
+ endif()
+ endif()
+else()
+ if(PythonInterpreter_FIND_REQUIRED)
+ message(FATAL_ERROR "A python3 interpreter was not found. Consider providing path using -DPYTHON_INTERPRETER_PATH=<path/to/python3>")
+ endif()
+endif()
diff --git a/cmake/scripts/linux/Install.cmake b/cmake/scripts/linux/Install.cmake
index addb040894..fd73bea9ed 100644
--- a/cmake/scripts/linux/Install.cmake
+++ b/cmake/scripts/linux/Install.cmake
@@ -194,6 +194,7 @@ install(FILES ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/scripts/${APP_NAME}Config.cm
COMPONENT kodi-addon-dev)
if(ENABLE_EVENTCLIENTS)
+ find_package(PythonInterpreter REQUIRED)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(prefix=''))"
OUTPUT_VARIABLE PYTHON_LIB_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
# Install kodi-eventclients-common BT python files