diff --git a/libc/cmake/modules/LLVMLibCArchitectures.cmake b/libc/cmake/modules/LLVMLibCArchitectures.cmake index 6ace3b55ee37d..b78e20403871d 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)