[llvm] [CrossCompile] pass HOST_CC/CXX to CMAKE_<C/CXX>_COMPILER when CMAKE_CROSSCOMPILING=True (PR #120728)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 20 04:52:07 PST 2024
https://github.com/valord577 created https://github.com/llvm/llvm-project/pull/120728
* Top CMake Command
```shell
CMAKE_EXTRA="-D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache \
-D CMAKE_TOOLCHAIN_FILE=${CROSS_TOOLCHAIN}/linux310-gcc7/toolchain-cmake-template.aarch64-unknown-linux-gnu"
# ^^^^ Just a note on the variables `CMAKE_EXTRA` ^^^^
CMAKE_COMMAND=$(cat <<- EOF
cmake -G Ninja \
-S "${SUBPROJ_SRC}/llvm" -B "${PKG_BULD_DIR}" \
-D CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON \
-D CMAKE_INSTALL_PREFIX="${PKG_INST_DIR}" \
-D CMAKE_INSTALL_LIBDIR:PATH=lib \
${PKG_BULD_TYPE} ${PKG_TYPE_FLAG} ${CMAKE_EXTRA} \
-D LLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lldb" \
-D CLANG_PLUGIN_SUPPORT:BOOL=0 \
-D LLVM_APPEND_VC_REV:BOOL=0 \
-D LLVM_ENABLE_BINDINGS:BOOL=0 \
-D LLVM_INCLUDE_BENCHMARKS:BOOL=0 \
-D LLVM_INCLUDE_EXAMPLES:BOOL=0 \
-D LLVM_INCLUDE_TESTS:BOOL=0 \
-D LLVM_INCLUDE_DOCS:BOOL=0 \
-D LLVM_INCLUDE_UTILS:BOOL=0 \
-D LLVM_TARGETS_TO_BUILD="AArch64;ARM;RISCV;WebAssembly;X86" \
-D LLDB_USE_SYSTEM_DEBUGSERVER:BOOL=1
EOF
)
if [ "${CROSS_BUILD_ENABLED}" == "1" ]; then
[ "${PKG_ARCH}" == "amd64" ] && { LLVM_ARCH="X86"; }
[ "${PKG_ARCH}" == "arm64" ] && { LLVM_ARCH="AArch64"; }
[ "${PKG_ARCH}" == "armv7" ] && { LLVM_ARCH="ARM"; }
CMAKE_COMMAND="${CMAKE_COMMAND} -D LLVM_HOST_TRIPLE=${TARGET_TRIPLE} -D LLVM_TARGET_ARCH=${LLVM_ARCH} \
-D CMAKE_C_HOST_COMPILER='${HOSTCC}' -D CMAKE_CXX_HOST_COMPILER='${HOSTCXX}'"
# ^^^^ Pass HOST_CC/CXX to CMAKE_<C/CXX>_COMPILER ^^^^
fi
printf "\e[1m\e[36m%s\e[0m\n" "${CMAKE_COMMAND}"; eval ${CMAKE_COMMAND}
```
* Error message shows when building with original code
<img width="1349" alt="Screenshot 2024-12-20 at 20 45 40" src="https://github.com/user-attachments/assets/cc970c03-5602-4cdd-894b-79fa3c824152" />
>From 2ee4f7888da3d4975cae2465bbcd6d08191abf86 Mon Sep 17 00:00:00 2001
From: valord577 <30427460+valord577 at users.noreply.github.com>
Date: Fri, 20 Dec 2024 20:34:35 +0800
Subject: [PATCH] [CrossCompile] set HOST_CC/CXX to CMAKE_<C/CXX>_COMPILER when
CMAKE_CROSSCOMPILING=True
---
llvm/cmake/modules/CrossCompile.cmake | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/cmake/modules/CrossCompile.cmake b/llvm/cmake/modules/CrossCompile.cmake
index c2cc84bec15217..72ea1c6c6c0060 100644
--- a/llvm/cmake/modules/CrossCompile.cmake
+++ b/llvm/cmake/modules/CrossCompile.cmake
@@ -15,10 +15,10 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype)
if (EXISTS ${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake)
set(CROSS_TOOLCHAIN_FLAGS_INIT
-DCMAKE_TOOLCHAIN_FILE=\"${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake\")
- elseif (NOT CMAKE_CROSSCOMPILING)
+ elseif (CMAKE_CROSSCOMPILING)
set(CROSS_TOOLCHAIN_FLAGS_INIT
- -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
- -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
+ -DCMAKE_C_COMPILER=${CMAKE_C_HOST_COMPILER}
+ -DCMAKE_CXX_COMPILER=${CMAKE_CXX_HOST_COMPILER}
)
endif()
set(CROSS_TOOLCHAIN_FLAGS_${target_name} ${CROSS_TOOLCHAIN_FLAGS_INIT}
More information about the llvm-commits
mailing list