Skip to content

Commit 9301054

Browse files
committed
[CMake] Don't pass CMAKE_C(XX)_COMPILER to the nested NATIVE build when cross compiling
Originally, the nested build was set up with the CMake command `execute_process` which implicitly passes CC/CXX variables for the configured compiler, which then was picked up by the nested CMake. (This CMake behaviour, to implicitly pass such variables is up for discussion and might change in the future; see https://gitlab.kitware.com/cmake/cmake/-/issues/21378.) How the nested cmake build is set up was changed in aa7d6db / D40229 - the old behaviour was brought along by manually passing -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} to the nested cmake configuration. This was then later made optional in f5f0fff / D40947. But still, the default if the user doesn't pass CROSS_TOOLCHAIN_FLAGS_${target_name} (e.g. CROSS_TOOLCHAIN_FLAGS_NATIVE) is to pass in the surrounding build's compiler - which usually doesn't work, and is quite non-obvious to figure out. Just drop the default passing of the outer compiler, when cross compiling. This should avoid surprising cases of using the cross compiler for the native build for essentially all new users trying to cross compile, until they've discovered CROSS_TOOLCHAIN_FLAGS_NATIVE. Keep passing these when not cross compiling, e.g. if building with optimized tablegen. This was already suggested at the end in D40229, but apparently never acted upon. Differential Revision: https://reviews.llvm.org/D126313
1 parent f44bf38 commit 9301054

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

llvm/cmake/modules/CrossCompile.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype)
1515
if (EXISTS ${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake)
1616
set(CROSS_TOOLCHAIN_FLAGS_INIT
1717
-DCMAKE_TOOLCHAIN_FILE=\"${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake\")
18-
else()
18+
elseif (NOT CMAKE_CROSSCOMPILING)
1919
set(CROSS_TOOLCHAIN_FLAGS_INIT
2020
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
2121
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}

0 commit comments

Comments
 (0)