[libc-commits] [libc] 12b65a6 - [libc] Use a more general way to determine the compiler's target triple.
Siva Chandra Reddy via libc-commits
libc-commits at lists.llvm.org
Mon Jan 30 08:34:46 PST 2023
Author: Siva Chandra Reddy
Date: 2023-01-30T16:34:21Z
New Revision: 12b65a66fc20ddeed88df0c5d74a7ab3e9a0a382
URL: https://github.com/llvm/llvm-project/commit/12b65a66fc20ddeed88df0c5d74a7ab3e9a0a382
DIFF: https://github.com/llvm/llvm-project/commit/12b65a66fc20ddeed88df0c5d74a7ab3e9a0a382.diff
LOG: [libc] Use a more general way to determine the compiler's target triple.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D142788
Added:
Modified:
libc/cmake/modules/LLVMLibCArchitectures.cmake
Removed:
################################################################################
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)
More information about the libc-commits
mailing list