CUDA: "warnings are errors" flag breaks ABI detection in CMake 3.18
With CMake 3.18.2, configuring a CUDA-enabled code with -DCMAKE_CUDA_FLAGS="-Werror all-warnings"
causes the CUDA compiler ABI detection to fail, which leads to pernicious failures when linking against CUDA::cudart
(from FindCUDAToolkit
). Even though CMake configures and generates successfully, and CUDA code compiles successfully, the necessary -L
library link paths are dropped from the link line:
/usr/bin/c++ -fPIC -shared -Wl,-soname,libmytest.so -o libmytest.so CMakeFiles/mytest.dir/derp.cc.o CMakeFiles/mytest.dir/derpcu.cu.o -Wl,-rpath,/usr/local/cuda-10.2/lib64 /usr/local/cuda-10.2/lib64/libcudart.so -lcudadevrt -lcudart_static -lrt -lpthread -ldl
/usr/bin/ld: cannot find -lcudadevrt
/usr/bin/ld: cannot find -lcudart_static
collect2: error: ld returned 1 exit status
whereas using an innocuous CMAKE cuda flag correctly includes the requisite link paths:
/usr/bin/c++ -fPIC -shared -Wl,-soname,libmytest.so -o libmytest.so CMakeFiles/mytest.dir/derp.cc.o CMakeFiles/mytest.dir/derpcu.cu.o -L/usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs -L/usr/local/cuda-10.2/targets/x86_64-linux/lib -Wl,-rpath,/usr/local/cuda-10.2/lib64 /usr/local/cuda-10.2/lib64/libcudart.so -lcudadevrt -lcudart_static -lrt -lpthread -ldl
Example project demonstrating the failure: https://gitlab.kitware.com/sethrj/cuda-failure
System info: RHEL 7; CUDA 10.2; GCC 8.3; CMake 3.18.2.