Linker error when cross-compiling CUDA code to aarch64-linux
A regression was introduced by cmake-3.17 where cross-compilation of CUDA code ends up with a linker error:
/usr/libexec/gcc/aarch64-linux-gnu/ld: cannot find -lcudadevrt /usr/libexec/gcc/aarch64-linux-gnu/ld: cannot find -lcudart_static
cmake isn't passing to the linker the directory that contains these libraries, and error ensues.
I suspect that the problem might be around this code: https://gitlab.kitware.com/cmake/cmake/-/blob/v3.19.2/Modules/CMakeDetermineCUDACompiler.cmake#L502
It excludes these libraries from the implicit library list used with cuda, but the target library path still remains in CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES, and cmake thus doesn't pass them to the linker.
This regression is presented in cmake-3.19.2 as well. It doesn't happen in cmake-3.16.9