[clang] [compiler-rt] [llvm] [CMake] Use Clang to infer the target triple (PR #89425)

Petr Hosek via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 3 01:54:05 PDT 2024


================
@@ -368,14 +368,22 @@ macro(construct_compiler_rt_default_triple)
           "Default triple for which compiler-rt runtimes will be built.")
   endif()
 
-  if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
+  if(CMAKE_C_COMPILER_ID MATCHES "Clang")
     set(option_prefix "")
     if (CMAKE_C_SIMULATE_ID MATCHES "MSVC")
       set(option_prefix "/clang:")
     endif()
-    execute_process(COMMAND ${CMAKE_C_COMPILER} ${option_prefix}--target=${COMPILER_RT_DEFAULT_TARGET_TRIPLE} ${option_prefix}-print-target-triple
-                    OUTPUT_VARIABLE COMPILER_RT_DEFAULT_TARGET_TRIPLE
-                    OUTPUT_STRIP_TRAILING_WHITESPACE)
+    set(print_target_triple ${CMAKE_C_COMPILER} ${option_prefix}--target=${COMPILER_RT_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(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${output})
+    else()
+      string(REPLACE ";" " " print_target_triple "${print_target_triple}")
+      message(WARNING "Failed to execute `${print_target_triple}` to normalize target triple.")
----------------
petrhosek wrote:

Currently we ignore any errors so my preference would be to start with a warning and change it to an error in a follow up change after we verify there are no issues.

https://github.com/llvm/llvm-project/pull/89425


More information about the cfe-commits mailing list