2019-04-06 21:08:09 +08:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2021-12-17 00:13:54 +08:00
|
|
|
include_guard(GLOBAL)
|
|
|
|
|
2019-07-25 17:37:32 +08:00
|
|
|
# On Windows, instruct Python to output UTF-8 even when not
|
|
|
|
# interacting with a terminal. This is required since Python scripts
|
|
|
|
# are invoked by CMake code and, on Windows, standard I/O encoding defaults
|
|
|
|
# to the current code page if not connected to a terminal, which is often
|
|
|
|
# not what we want.
|
|
|
|
if (WIN32)
|
|
|
|
set(ENV{PYTHONIOENCODING} "utf-8")
|
|
|
|
endif()
|
|
|
|
|
2024-09-19 14:54:01 +08:00
|
|
|
set(PYTHON_MINIMUM_REQUIRED 3.10)
|
2020-04-15 04:24:32 +08:00
|
|
|
|
2023-06-28 17:40:51 +08:00
|
|
|
find_package(Deprecated COMPONENTS PYTHON_PREFER)
|
|
|
|
|
|
|
|
if(NOT DEFINED Python3_EXECUTABLE AND DEFINED WEST_PYTHON)
|
|
|
|
set(Python3_EXECUTABLE "${WEST_PYTHON}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT Python3_EXECUTABLE)
|
|
|
|
# We are using foreach here, instead of
|
|
|
|
# find_program(PYTHON_EXECUTABLE_SYSTEM_DEFAULT "python" "python3")
|
|
|
|
# cause just using find_program directly could result in a python2.7 as python,
|
|
|
|
# and not finding a valid python3.
|
|
|
|
foreach(candidate "python" "python3")
|
2024-09-04 00:32:23 +08:00
|
|
|
find_program(Python3_EXECUTABLE ${candidate} PATHS ENV VIRTUAL_ENV NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH)
|
2023-06-28 17:40:51 +08:00
|
|
|
if(Python3_EXECUTABLE)
|
|
|
|
execute_process (COMMAND "${Python3_EXECUTABLE}" -c
|
|
|
|
"import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:2]]))"
|
|
|
|
RESULT_VARIABLE result
|
|
|
|
OUTPUT_VARIABLE version
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
|
|
|
if(version VERSION_LESS PYTHON_MINIMUM_REQUIRED)
|
|
|
|
set(Python3_EXECUTABLE "Python3_EXECUTABLE-NOTFOUND" CACHE INTERNAL "Path to a program")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_package(Python3 ${PYTHON_MINIMUM_REQUIRED} REQUIRED)
|
|
|
|
|
|
|
|
# Zephyr internally used Python variable.
|
2020-04-13 19:53:41 +08:00
|
|
|
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
|