CMAKE_LINKER_TYPE when cross-compiling not passing correct options

Cross-compiling for CMAKE_SYSTEM_NAME Darwin using CMAKE_LINKER_TYPE LLD does not provide valid command-line options to the linker. Is this expected?

Can you specify your environment (platform, CMake version, compiler, CMake command line)?

Platform Ubuntu 22.04, CMake 3.30, LLVM 18.1.8

CMake toolchain:
set( CMAKE_SYSTEM_NAME Darwin )
set( CMAKE_SYSTEM_VERSION 11.0 )
set( CMAKE_OSX_ARCHITECTURES arm64 )
set( CMAKE_OSX_SYSROOT /opt/apple/sdks/Xcode15.4/MacOSX.platform/Developer/SDKs/MacOSX.sdk )
set( CMAKE_C_COMPILER /opt/llvm/18.1.8/release/bin/clang )
set( CMAKE_CXX_COMPILER /opt/llvm/18.1.8/release/bin/clang++ )
set( CMAKE_ASM_COMPILER /opt/llvm/18.1.8/release/bin/clang )
set( CMAKE_LIBTOOL /opt/llvm/18.1.8/release/bin/llvm-libtool-darwin )
set( CMAKE_LINKER_TYPE LLD )
cmake -G Ninja
-D CMAKE_BUILD_TYPE=Release 
-D CMAKE_INSTALL_PREFIX=/build/dist/build.llvm.macosx.arm.release 
-D CMAKE_VERBOSE_MAKEFILE=on 
-D CMAKE_TOOLCHAIN_FILE=/build/builddir/macosx/toolchain.cmake 
-D LLVM_HOST_TRIPLE=arm64-apple-darwin 
-D CMAKE_SYSTEM_IGNORE_PREFIX_PATH=/Library/Developer/CommandLineTools;/Applications/Xcode.app 
-D LLVM_ENABLE_TERMINFO=off 
-D TERMINFO_LIB=-lcurses 
-D LLVM_ENABLE_FFI=on 
-D LLVM_TARGETS_TO_BUILD=X86;ARM;AArch64 
-D LLVM_ENABLE_RUNTIMES=libcxx;libcxxabi;libunwind 
-D LLVM_ENABLE_LIBCXX=on 
-D BUILD_SHARED_LIBS=off 
-D LLVM_ENABLE_PIC=off 
-D LLVM_ENABLE_EH=off 
-D LLVM_ENABLE_RTTI=off
-D LLVM_ENABLE_Z3_SOLVER=off 
-D LLVM_INSTALL_CCTOOLS_SYMLINKS=on 
-D LLVM_BUILD_EXTERNAL_COMPILER_RT=on 
-D LLVM_BUILD_TESTS=off 
-D LLVM_BUILD_TOOLS=on
-D LLVM_INSTALL_UTILS=on 
-D LLVM_OPTIMIZED_TABLEGEN=on 
-D LLVM_INCLUDE_DOCS=off 
-D LLVM_ENABLE_DOXYGEN=off 
-D LLVM_INCLUDE_EXAMPLES=off 
-D LLVM_INCLUDE_TESTS=off 
-D LLVM_ENABLE_PROJECTS=clang;lld
-D CLANG_INCLUDE_TESTS=off 
-D LLVM_ENABLE_LLD=on /build/llvm
../path/to/src

My current thinking is that specifying LLD has some consequences that I need to dig into, namely, that TryCompile vs. cross-compile need two different flavors of LLD, ld64.lld (macOS) and ld.lld (linux) and either I’m specifying this fact incorrectly or cmake doesn’t support this.

I don’t think TryCompile needs a different linker than the cross-compile one. TryCompile is used to check usability of the cross-compiler, so the target linker must be used, not the host one.

Moreover, specifying CMAKE_LINKER_TYPE result in the option -fuse-ld=lld passed to the cross-compiler which, in turn, will select the linker.

Did-you check that using directly the cross-compiler with option -fuse-ld=lld is OK?

I have looked at this for so long I’ve lost perspective :slight_smile:

I think I will cut this down to a simpler problem and compile just LibreSSL (my favorite toy CMake project) and see if I can compile it in the pipeline

By the way, are you sure that a target specification is not required? From the CMake documentation regarding cross-compiling with clang, variable CMAKE_<LANG>_COMPILER_TARGET should be defined to let clang know how to compile for the needed target.