From 0ecd4f6c55c0cb4e9ba0e03758925da8cef66088 Mon Sep 17 00:00:00 2001 From: David Spickett Date: Wed, 5 Apr 2023 09:00:54 +0000 Subject: [PATCH] [compiler-rt] Check for missing CMAKE_C_COMPILER_TARGET when using COMPILER_RT_DEFAULT_TARGET_ONLY COMPILER_RT_DEFAULT_TARGET_ONLY is the goto workaround for building only one of a multilib setup while still being able to autodetect the native target. For example only building 64 bit libraries on Intel instead of 32 and 64 bit. Which may fail without 32 bit compatibility libs installed. As reported in https://discourse.llvm.org/t/configuring-compiler-rt-to-use-default-target-only-does-not-work/62727 this build config hasn't worked in a while. It relies on a variable usually set during cross compliation, though my testing shows you can set it in other scenarios too. https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_TARGET.html So the options you need to provide are: -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON -DCMAKE_C_COMPILER_TARGET="aarch64-unknown-linux-gnu" And we should error if CMAKE_C_COMPILER_TARGET isn't set. Reviewed By: glaubitz Differential Revision: https://reviews.llvm.org/D147598 --- compiler-rt/cmake/Modules/CompilerRTUtils.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake index eefc466..f15917f 100644 --- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake @@ -358,6 +358,10 @@ macro(construct_compiler_rt_default_triple) if(DEFINED COMPILER_RT_DEFAULT_TARGET_TRIPLE) message(FATAL_ERROR "COMPILER_RT_DEFAULT_TARGET_TRIPLE isn't supported when building for default target only") endif() + if ("${CMAKE_C_COMPILER_TARGET}" STREQUAL "") + message(FATAL_ERROR "CMAKE_C_COMPILER_TARGET must also be set when COMPILER_RT_DEFAUT_TARGET_ONLY is ON") + endif() + message(STATUS "cmake c compiler target: ${CMAKE_C_COMPILER_TARGET}") set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${CMAKE_C_COMPILER_TARGET}) else() set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${LLVM_TARGET_TRIPLE} CACHE STRING -- 2.7.4