[PATCH] D79151: build: use `find_package(Python3)` if available (llvm runtimes).
Vlad Vereschaka via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 29 17:18:05 PDT 2020
vvereschaka created this revision.
vvereschaka added reviewers: compnerd, phosek.
vvereschaka added a project: LLVM.
Herald added subscribers: llvm-commits, mgorny.
vvereschaka added a comment.
Hi @compnerd,
here is one more place, which needs a proper detection for Python3/Python2.
I just copied a part of your changes accordingly.
This is primarily motivated by the desire to move from Python2 to
Python3. `PYTHON_EXECUTABLE` is ambiguous. This explicitly identifies
the python interpreter in use. Since the LLVM build seems to be able to
completed successfully with python3, use that across the build. The old
path aliases `PYTHON_EXECUTABLE` to be treated as Python3.
Based on commit cd84bfb8142bc7ff3a07a188ffb809f1d86d1fd7 <https://reviews.llvm.org/rGcd84bfb8142bc7ff3a07a188ffb809f1d86d1fd7>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D79151
Files:
llvm/runtimes/CMakeLists.txt
Index: llvm/runtimes/CMakeLists.txt
===================================================================
--- llvm/runtimes/CMakeLists.txt
+++ llvm/runtimes/CMakeLists.txt
@@ -112,7 +112,40 @@
# Handle common options used by all runtimes.
include(AddLLVM)
include(HandleLLVMOptions)
- include(FindPythonInterp)
+
+ 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()
+
+ 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)
+ if(NOT Python3_Interpreter_FOUND)
+ message(WARNING "Python3 not found, using python2 as a fallback")
+ find_package(Python2 COMPONENTS Interpreter REQUIRED)
+ if(Python2_VERSION VERSION_LESS 2.7)
+ message(SEND_ERROR "Python 2.7 or newer is required")
+ endif()
+
+ # Treat python2 as python3
+ add_executable(Python3::Interpreter IMPORTED)
+ set_target_properties(Python3::Interpreter PROPERTIES
+ IMPORTED_LOCATION ${Python2_EXECUTABLE})
+ set(Python3_EXECUTABLE ${Python2_EXECUTABLE})
+ endif()
+ endif()
# Remove the -nostdlib++ option we've added earlier.
string(REPLACE "-nostdlib++" "" CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79151.261097.patch
Type: text/x-patch
Size: 1731 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200430/1e6a0f01/attachment.bin>
More information about the llvm-commits
mailing list