summaryrefslogtreecommitdiff
path: root/runtimes
diff options
context:
space:
mode:
authorPetr Hosek <phosek@google.com>2024-07-05 22:56:15 -0700
committerGitHub <noreply@github.com>2024-07-05 22:56:15 -0700
commit9cb9a97e44130e17e96f994c3e594aba69ea1ad5 (patch)
treef0b186b136b8c94703b6eeff24ed3ac4dc6d9813 /runtimes
parentccf357ff643c6af86bb459eba5a00f40f1dcaf22 (diff)
[CMake] Use Clang to infer the target triple (#89425)
When using Clang as a compiler, use Clang to normalize the triple that's used to construct path for runtime library build and install paths. This ensures that paths are consistent and avoids the issue where the build uses a different triple spelling. Differential Revision: https://reviews.llvm.org/D140925
Diffstat (limited to 'runtimes')
-rw-r--r--runtimes/CMakeLists.txt19
1 files changed, 19 insertions, 0 deletions
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index 24f485116959..830165c799c2 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -183,6 +183,25 @@ message(STATUS "LLVM default target triple: ${LLVM_DEFAULT_TARGET_TRIPLE}")
set(LLVM_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
+if(CMAKE_C_COMPILER_ID MATCHES "Clang")
+ set(option_prefix "")
+ if (CMAKE_C_SIMULATE_ID MATCHES "MSVC")
+ set(option_prefix "/clang:")
+ endif()
+ set(print_target_triple ${CMAKE_C_COMPILER} ${option_prefix}--target=${LLVM_DEFAULT_TARGET_TRIPLE} ${option_prefix}-print-target-triple)
+ execute_process(COMMAND ${print_target_triple}
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE output
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ if(result EQUAL 0)
+ set(LLVM_DEFAULT_TARGET_TRIPLE ${output})
+ else()
+ string(REPLACE ";" " " print_target_triple "${print_target_triple}")
+ # TODO(#97876): Report an error.
+ message(WARNING "Failed to execute `${print_target_triple}` to normalize target triple.")
+ endif()
+endif()
+
option(LLVM_INCLUDE_TESTS "Generate build targets for the runtimes unit tests." ON)
option(LLVM_INCLUDE_DOCS "Generate build targets for the runtimes documentation." ON)
option(LLVM_ENABLE_SPHINX "Use Sphinx to generate the runtimes documentation." OFF)