[libc-commits] [PATCH] D142788: [libc] Use a more general way to determine the compiler's target triple.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Jan 30 08:34:49 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG12b65a66fc20: [libc] Use a more general way to determine the compiler's target triple. (authored by sivachandra).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142788/new/

https://reviews.llvm.org/D142788

Files:
  libc/cmake/modules/LLVMLibCArchitectures.cmake


Index: libc/cmake/modules/LLVMLibCArchitectures.cmake
===================================================================
--- libc/cmake/modules/LLVMLibCArchitectures.cmake
+++ libc/cmake/modules/LLVMLibCArchitectures.cmake
@@ -74,20 +74,22 @@
   set(${sys_var} ${target_sys} PARENT_SCOPE)
 endfunction(get_arch_and_system_from_triple)
 
-# Query the default target triple of the compiler.
-set(target_triple_option "-print-target-triple")
-if(CMAKE_COMPILER_IS_GNUCXX)
-  # GCC does not support the "-print-target-triple" option but supports
-  # "-print-multiarch" which clang does not support for all targets.
-  set(target_triple_option "-print-multiarch")
+execute_process(COMMAND ${CMAKE_CXX_COMPILER} -v
+                RESULT_VARIABLE libc_compiler_info_result
+                OUTPUT_VARIABLE libc_compiler_info
+                ERROR_VARIABLE libc_compiler_info)
+if(NOT (libc_compiler_info_result EQUAL "0"))
+  message(FATAL_ERROR "libc build: error querying compiler info from the "
+                      "compiler: ${libc_compiler_info}")
 endif()
-execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${target_triple_option}
-                RESULT_VARIABLE libc_compiler_triple_check
-                OUTPUT_VARIABLE libc_compiler_triple)
-if(NOT (libc_compiler_triple_check EQUAL "0"))
-  message(FATAL_ERROR "libc build: error querying target triple from the "
-                      "compiler: ${libc_compiler_triple}")
+string(REGEX MATCH "Target: [-_a-z0-9]+[ \r\n]+"
+       libc_compiler_target_info ${libc_compiler_info})
+if(NOT libc_compiler_target_info)
+  message(FATAL_ERROR "libc build: could not read compiler target info from:\n"
+                      "${libc_compiler_info}")
 endif()
+string(STRIP ${libc_compiler_target_info} libc_compiler_target_info)
+string(SUBSTRING ${libc_compiler_target_info} 8 -1 libc_compiler_triple)
 get_arch_and_system_from_triple(${libc_compiler_triple}
                                 compiler_arch compiler_sys)
 if(NOT compiler_arch)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142788.493322.patch
Type: text/x-patch
Size: 1999 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230130/821c71f2/attachment-0001.bin>


More information about the libc-commits mailing list