[CUDA] [Linux] [CMake 3.8] [QT5] [fPIC] - CUDA builds break when linking in Qt libraries
I've been trying to get some stuff to compile and was pretty excited for the new additional support for CUDA natively, however I've ran into quite the "perfect mix" of things not working together quite right.
I haven't gone to try this on Windows to see if the problem will be the same. Will do and update this if that is confirmed
EDIT: Just booted windows to see how this looks there and issue does not show up as the line in Qt5CoreConfigExtras resolves to basically "append <nothing>"
This MIGHT be more on Qt's side and I'm reporting it directly to them, as well as pointing them here as well, but I also thought it'd be interesting to have you guys look at it since one could also look at it being a problem regarding how CMake forwards flags to nvcc.
Issue:
When compiling a CUDA application that target_link_library(Qt5::Core)
the compilation will fail with the following message:
nvcc fatal : Unknown option 'fPIC'
Steps to reproduce:
- Create a CMake Project, make sure to enable CUDA as a native language:
cmake_minimum_required(VERSION 3.8)
project(oopsie LANGUAGE CUDA)
[....]
add_executable(oopsie ${SOME_CUDA_SOURCES})
find_package(Qt5Core)
target_link_libraries(oopsie Qt5::Core)
alternatively
enable_language(CUDA)
All Qt libs depend on core, so the problem will show with other components as well
- Attempt to build the project
Cause
Reading through Qt's config.cmake files I've found where the problem lies. From lines 69 to 87 of Qt5CoreConfigExtras.cmake.in You'll find a line that resolves, when installed to
set_property(TARGET Qt5::Core APPEND PROPERTY INTERFACE_COMPILE_OPTIONS -fPIC)
This flag gets applied directly to the NVCC command line, instead of being forwarded to the host compiler. Such that the call looks like:
-isystem=/usr/include/qt/QtCore -isystem=/usr/lib/qt/mkspecs/linux-g++ -O3 -DNDEBUG -fPIC -x cu [...]
when the correct would be something along the lines of
-isystem=/usr/include/qt/QtCore -isystem=/usr/lib/qt/mkspecs/linux-g++ -O3 -DNDEBUG -Xcompiler -fPIC -x cu [...]
How much of the "blame" for this relies on:
nVidia
Seriously? you just have your tool crash if it sees -fPIC?
Qt
For strapping that in such a brute force manner
Cmake
For not forwarding the flags for the host compiler
Is something that could be fruitlessly argued if so desired. My take is that perhaps that's a problem that might show itself in other situations, with other flags and that maybe CMake shouldn't pass on those flags to nvcc directly but, yeah. Like I said, I guess I stumbled upon quite the nasty cocktail of things being just in the right place to blow up in my face (and send me chasing after my own tail for an afternoon while I desperately looked for where I had placed that flag in an interface).
As mentioned, I'll also report this to the Qt people and will link them to this issue. Good luck trying to find out what is the good answer to this