[libc++] Set the target triple by default in the standalone build
Even though the standalone build is deprecated, some people are still
relying on it (including libc++ itself for some configurations). Setting
the target triple will ensure that the build and the test suite behaves
consistently in the standalone and normal builds.
Differential Revision: https://reviews.llvm.org/D106800
NOKEYCHECK=True
GitOrigin-RevId: 069428b6f73bdfb7bba13d461a2f57beb86b6aa7
diff --git a/cmake/Modules/HandleOutOfTreeLLVM.cmake b/cmake/Modules/HandleOutOfTreeLLVM.cmake
index a355fdf..ad2820b 100644
--- a/cmake/Modules/HandleOutOfTreeLLVM.cmake
+++ b/cmake/Modules/HandleOutOfTreeLLVM.cmake
@@ -26,6 +26,12 @@
message(STATUS "Configuring for standalone build.")
+# By default, we target the host, but this can be overridden at CMake invocation time.
+include(GetHostTriple)
+get_host_triple(LLVM_INFERRED_HOST_TRIPLE)
+set(LLVM_HOST_TRIPLE "${LLVM_INFERRED_HOST_TRIPLE}" CACHE STRING "Host on which LLVM binaries will run")
+set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING "Target triple used by default.")
+
# Add LLVM Functions --------------------------------------------------------
if (WIN32)
set(LLVM_ON_UNIX 0)