[cmake-developers] FindCUDA bug fixes

Sorley, Stephen L. Stephen.Sorley at jhuapl.edu
Wed Aug 31 10:50:50 EDT 2016


I've attached two patches that fix bugs in the CUDA_COMPILE{,_PTX,_FATBIN,_CUBIN} macros from FindCUDA.cmake.


First bug (fixed by patch #1)

Commit 7ded655 added generator expressions in CUDA_WRAP_SRCS to scrape include directories and compile definitions off of the target.  This works great when the target name passed to CUDA_WRAP_SRCS is an actual target (like in cuda_add_library and cuda_add_executable).  However, the CUDA_COMPILE* macros also use CUDA_WRAP_SRCS, and they pass in a hardcoded name that doesn't represent a real target.  This breaks the generator expressions, causing CMake to abort during generation.

I fixed this by teaching CUDA_WRAP_SRCS to check for "PHONY" in its argument list.  When CUDA_WRAP_SRCS sees "PHONY", it queries the appropriate directory properties (INCLUDE_DIRECTORIES and COMPILE_DEFINITIONS) instead of using the generator expressions.  I then modified cuda_compile_base (which is used internally by all the CUDA_COMPILE* macros) to pass PHONY to CUDA_WRAP_SRCS.


Second bug (fixed by patch #2)

In a couple spots, CUDA_WRAP_SRCS assumes that the passed-in target name is unique - for example, the name of the directory containing the intermediate output is built from the target name.  However, the CUDA_COMPILE* macros always pass the same hardcoded target name.  So, if you call the same macro twice in a directory, some of the generated files from the second call will silently overwrite those from the first call.

I fixed this by adding a counter (_cuda_internal_phony_counter) as a directory property.  The counter gets incremented every time cuda_compile_base is called, and the value of the counter is appended to the hardcoded target name that gets passed to CUDA_WRAP_SRCS.  This ensures that each call to the macro has its own unique target name.


Thanks!
Stephen Sorley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160831/a188a806/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-FindCUDA-Fix-for-broken-cuda_compile-commands.patch
Type: application/octet-stream
Size: 5044 bytes
Desc: 0001-FindCUDA-Fix-for-broken-cuda_compile-commands.patch
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160831/a188a806/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-FindCUDA-Allow-cuda_compile-macros-to-be-called-more.patch
Type: application/octet-stream
Size: 2002 bytes
Desc: 0002-FindCUDA-Allow-cuda_compile-macros-to-be-called-more.patch
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160831/a188a806/attachment-0001.obj>


More information about the cmake-developers mailing list