diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -672,16 +672,25 @@ include(HandleLLVMOptions) -include(FindPythonInterp) -if( NOT PYTHONINTERP_FOUND ) - message(FATAL_ERROR -"Unable to find Python interpreter, required for builds and testing. +if(CMAKE_VERSION VERSION_LESS 3.12) + include(FindPythonInterp) + if( NOT PYTHONINTERP_FOUND ) + message(FATAL_ERROR + "Unable to find Python interpreter, required for builds and testing. -Please install Python or specify the PYTHON_EXECUTABLE CMake variable.") -endif() + Please install Python or specify the PYTHON_EXECUTABLE CMake variable.") + endif() -if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 ) - message(FATAL_ERROR "Python 2.7 or newer is required") + if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 ) + message(FATAL_ERROR "Python 2.7 or newer is required") + endif() + + add_executable(Python3::Interpreter IMPORTED) + set_target_properties(Python3::Interpreter PROPERTIES + IMPORTED_LOCATION ${PYTHON_EXECUTABLE}) + set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE}) +else() + find_package(Python3 COMPONENTS Interpreter REQUIRED) endif() ###### @@ -717,7 +726,7 @@ message(STATUS "Constructing LLVMBuild project information") execute_process( - COMMAND ${PYTHON_EXECUTABLE} -B ${LLVMBUILDTOOL} + COMMAND "${Python3_EXECUTABLE}" -B ${LLVMBUILDTOOL} --native-target "${LLVM_NATIVE_ARCH}" --enable-targets "${LLVM_TARGETS_TO_BUILD}" --enable-optional-components "${LLVMOPTIONALCOMPONENTS}" diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake --- a/llvm/cmake/config-ix.cmake +++ b/llvm/cmake/config-ix.cmake @@ -639,7 +639,7 @@ return() endif() - execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "import ${module}" + execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "import ${module}" RESULT_VARIABLE status ERROR_QUIET) diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -117,7 +117,7 @@ set(native_export_file "${target_name}.def") add_custom_command(OUTPUT ${native_export_file} - COMMAND ${PYTHON_EXECUTABLE} -c "import sys;print(''.join(['EXPORTS\\n']+sys.stdin.readlines(),))" + COMMAND "${Python3_EXECUTABLE}" -c "import sys;print(''.join(['EXPORTS\\n']+sys.stdin.readlines(),))" < ${export_file} > ${native_export_file} DEPENDS ${export_file} VERBATIM @@ -1001,7 +1001,7 @@ set(mangling itanium) endif() add_custom_command(OUTPUT ${exported_symbol_file} - COMMAND ${PYTHON_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/extract_symbols.py --mangling=${mangling} ${static_libs} -o ${exported_symbol_file} + COMMAND "${Python3_EXECUTABLE}" ${LLVM_MAIN_SRC_DIR}/utils/extract_symbols.py --mangling=${mangling} ${static_libs} -o ${exported_symbol_file} WORKING_DIRECTORY ${LLVM_LIBRARY_OUTPUT_INTDIR} DEPENDS ${LLVM_MAIN_SRC_DIR}/utils/extract_symbols.py ${static_libs} VERBATIM @@ -1402,7 +1402,7 @@ # empty list entries. So escape the ;s in the list and do the splitting # ourselves. cmake has no relpath function, so use Python for that. string(REPLACE ";" "\\;" pathlist_escaped "${pathlist}") - execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "\n + execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "\n import os, sys\n base = sys.argv[1] def haslink(p):\n @@ -1477,7 +1477,6 @@ # SHLIBDIR points the build tree. string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" SHLIBDIR "${LLVM_SHLIB_OUTPUT_INTDIR}") - set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}) # FIXME: "ENABLE_SHARED" doesn't make sense, since it is used just for # plugins. We may rename it. if(LLVM_ENABLE_PLUGINS) @@ -1635,7 +1634,7 @@ ALLOW_EXTERNAL ) - set(LIT_COMMAND "${PYTHON_EXECUTABLE};${lit_base_dir}/${lit_file_name}") + set(LIT_COMMAND "${Python3_EXECUTABLE};${lit_base_dir}/${lit_file_name}") list(APPEND LIT_COMMAND ${LIT_ARGS}) foreach(param ${ARG_PARAMS}) list(APPEND LIT_COMMAND --param ${param}) diff --git a/llvm/test/lit.site.cfg.py.in b/llvm/test/lit.site.cfg.py.in --- a/llvm/test/lit.site.cfg.py.in +++ b/llvm/test/lit.site.cfg.py.in @@ -12,7 +12,7 @@ config.llvm_shlib_ext = "@SHLIBEXT@" config.llvm_exe_ext = "@EXEEXT@" config.lit_tools_dir = path(r"@LLVM_LIT_TOOLS_DIR@") -config.python_executable = "@PYTHON_EXECUTABLE@" +config.python_executable = "@Python3_EXECUTABLE@" config.gold_executable = "@GOLD_EXECUTABLE@" config.ld64_executable = "@LD64_EXECUTABLE@" config.ocamlfind_executable = "@OCAMLFIND@"