Cannot use a CMake-exported static library containing CUDA code in another C++-only CMake project.
CMake version: 3.13.0-rc3
Platform: GNU/Linux
Generators: Unix Makefiles
Summary
Consider the scenario where we configure, build and install a static library which may or may not include CUDA kernels for GPU-acceleration of some functionality (a configure-time decision). This library does not employ separable CUDA compilation, and offers a purely C++ interface to its functionality.
A C++ application is a consumer of this library, and contains no CUDA code.
The library has languages CXX and CUDA enabled, and uses install(EXPORT ...)
to produce a CMake script for use by a supplied CMake module. The CXX-only application then uses find_package
to add the library via target_link_libraries
.
Configuring the application emits the error:
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_CUDA_DEVICE_LINK_EXECUTABLE
and if one then continues to build, we get at link time:
c++: error: CMakeFiles/app.dir/cmake_device_link: No such file or directory
Expected behaviour
If a static library is built without any CUDA relocatable device code, then it does not require a device-link pass, and any application that uses it will neither need a device-link pass on the basis of this library dependency.
A CMake project for a C++-only application should be able to use the CMake-generated module for such a library without it itself enabling CUDA as a language; the library module should export a requirement for the CUDA runtime library in its interface.
It is quite possible that the environment in which the library is built and installed, with a dependency on the CUDA toolkit, is not the same in which the application is built and linked, where only a dependency on the CUDA runtime library should be required.
More generally, I would not expect CMake to attempt to invoke a device-link pass when it is in a position to know that the object files in question do not contain relocatable CUDA code.
Example
A minimal working example is attached example.tar, with a README.md
and supplied demo build script build.sh
.