Reputation: 1296
In cmake you can use add_dependencies
to make sure that one library is up to date and built before another one. This works perfectly fine for a library with C++ sources (myLib in the example code), however it doesn't work for a library with CUDA sources (myCudaLib in the example code).
First I made sure that all libraries are build. When I now change a file of myLib and build mainExec
, myLib
is automatically rebuild before it. If I try the same thing with myCudaLib
it only tells me that all projects are up to date.
Does anyone know why the changes are not detected and the lib is not rebuild with CUDA files?
cmake_minimum_required(VERSION 3.13)
project(cmakeTest LANGUAGES CXX CUDA)
add_executable(mainExec main.cpp)
add_library(myLib foo.h foo.cpp)
add_dependencies(mainExec myLib)
target_link_libraries(mainExec PRIVATE myLib)
add_library(myCudaLib foo.cuh foo.cu)
add_dependencies(mainExec myCudaLib)
target_link_libraries(mainExec PRIVATE myCudaLib)
The source files contain nothing significant, only a function void foo() with an empty body (or a single variable when I change them to see if the libs are rebuild).
In case it matters: Windows 10, Visual Studio 2017, Cmake 3.13, Cuda 10.0
Upvotes: 0
Views: 666
Reputation: 1296
The behavior of Visual Studio not detecting changes in CUDA files is caused by a bug in the interaction of CUDA 10.0 (and apparently some of the previous versions) with Visual Studio 2017 (2015 works fine). It doesn't occure if your project is located in certain folders (C:\ProgramData
and C:\Users\userName\AppData\Local
). The full discussion on the NVIDIA forum can be found here.
CUDA 10.1 fixes the bug (not yet confirmed by NVIDIA but seems to work for some people on the forum and it also worked for me).
Upvotes: 1