ld flags is not used when probing compiler
In CMakeDetermineCompilerId.cmake only c/cxx flags is used. My case is using clang+lld to cross compile raspberry pi apps. with clang + lld linker, the gcc toolchain is not required, sysroot is enough. I have successfully build and run ffmpeg using clang+lld without gcc toolchain. So I try it in cmake. My toolchain file
CMAKE_SYSTEM_NAME=Linux
CMAKE_SYSTEM_PROCESSOR=armv6
CMAKE_SYSROOT=$RPI_SYSROOT
CMAKE_C_COMPILER=clang-5.0
CMAKE_CXX_COMPILER=clang++-5.0
CMAKE_C_FLAGS=-target arm-linux-gnueabihf -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -marm
CMAKE_CXX_FLAGS=-target arm-linux-gnueabihf -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -marm
CMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld
CMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld
...
cmake reports The C compiler "/usr/local/bin/clang-5.0" is not able to compile a simple test program
because -fuse-ld=lld
is not used but host linker is used. Adding -fuse-ld=lld
to CMAKE_C_COMPILER can be a workaround, but obviously it's ugly, and you will get a warning when running make
: clang-5.0: warning: argument unused during compilation: '-fuse-ld=lld' [-Wunused-command-line-argument]
Edited by WangBin