From 12b65a66fc20ddeed88df0c5d74a7ab3e9a0a382 Mon Sep 17 00:00:00 2001 From: Siva Chandra Reddy Date: Sat, 28 Jan 2023 00:14:14 +0000 Subject: [PATCH] [libc] Use a more general way to determine the compiler's target triple. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D142788 --- libc/cmake/modules/LLVMLibCArchitectures.cmake | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/libc/cmake/modules/LLVMLibCArchitectures.cmake b/libc/cmake/modules/LLVMLibCArchitectures.cmake index 6ace3b5..b78e204 100644 --- a/libc/cmake/modules/LLVMLibCArchitectures.cmake +++ b/libc/cmake/modules/LLVMLibCArchitectures.cmake @@ -74,20 +74,22 @@ function(get_arch_and_system_from_triple triple arch_var sys_var) 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) -- 2.7.4