I have a CMake based Windows library project that only links successfully with the MSVC link.exe due to some obscure third party library dependencies. However, I want to compile the project using the LLVM 21 toolchain.
This succeeds when building it from the command line like this
cmake.exe "-DCMAKE_C_COMPILER=C:/Program Files/LLVM/bin/clang.exe" "-DCMAKE_CXX_COMPILER=C:/Program Files/LLVM/bin/clang++.exe" -D CMAKE_CXX_FLAGS=-fuse-ld=link.exe -G Ninja -B C:\path\to\buildfolder
cmake.exe --build C:\path\to\buildfolder
However, when attempting to configure the same build in CLion by adding -D CMAKE_CXX_FLAGS=-fuse-ld=link.exe in the CMake Options field the linking stage fails because lld-link is invoked. The link command that is displayed in the build output starts like this
C:\Windows\system32\cmd.exe /C "cd . && C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE -nostartfiles -nostdlib -fuse-ld=link.exe -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -fuse-ld=lld-link -shared
So the -fuse-ld=link.exe flag is passed through but another second -fuse-ld=lld-link flag seems to be added automatically by CLion which overrides the manually specified flag. I found no option to avoid that or explicitly set up another linker for the toolchain. Is there any way to do this?
CMAKE_LINKER_TYPEvariable?