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

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Fri Jan 27 16:16:50 PST 2023


sivachandra created this revision.
sivachandra added reviewers: lntue, michaelrj.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
sivachandra requested review of this revision.

Repository:
  rG LLVM Github Monorepo

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.492943.patch
Type: text/x-patch
Size: 1999 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230128/59638887/attachment-0001.bin>


More information about the libc-commits mailing list