[libc++abi] Make sure we can run the tests in Standalone mode
The tests would previously fail if the `python` executable wasn't found,
because we were missing the mandatory find_package.
GitOrigin-RevId: b888463f8d6b1a0b003fa329c28e7348356787b5
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3f37dbf..d9ed55a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,6 +48,23 @@
include(HandleOutOfTreeLLVM)
endif()
+if (LIBCXXABI_STANDALONE_BUILD)
+ 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()
+
# Require out of source build.
include(MacroEnsureOutOfSourceBuild)
MACRO_ENSURE_OUT_OF_SOURCE_BUILD(