[cmake-developers] FindCUDA.cmake regression in 3.5.0-rc2

Sorley, Stephen L. Stephen.Sorley at jhuapl.edu
Wed Feb 17 14:53:53 EST 2016


FindCUDA.cmake from 3.5.0-rc2 is failing for me when creating solution files for Visual Studio on Windows (VS 2013 update 4, to be specific).  The ninja generator on Windows is unaffected.

When I attempt to build a cuda target, the compile step for each .cu file fails with the following message:

Building NVCC (Device) object utils/CMakeFiles/utils_cu.dir/Release/utils_cu_generated_cudaarray.cu.obj
3>  cudaarray.cu
3>
3>  '$' is not recognized as an internal or external command,
3>
3>  operable program or batch file.
3>
3>  CMake Error at utils_cu_generated_cudaarray.cu.obj.cmake:207 (message):
3>    Error generating
3>    C:/Users/sorlesl1/Desktop/testproj/build/utils/CMakeFiles/utils_cu.dir//Release/utils_cu_generated_cudaarray.cu.obj

I've traced the problem to this commit<https://github.com/Kitware/CMake/commit/6ccc307053f03c4c48a2cb9d5795f91d341a5c39>, which added VERBATIM to the add_custom_command() call in CUDA_WRAP_SRCS.

Adding the VERBATIM flag changes how the escaped double-quotes in the ccbin_flags variable are interpreted:

Without verbatim, ${ccbin_flags} expands to the following in the generated VS project:
   -D "CCBIN:PATH=$(VCInstallDir)bin"

With verbatim, the double quotes are escaped in the generated project, causing the error:
   -D \"CCBIN:PATH=$(VCInstallDir)bin\"

If the escaped quotes are omitted entirely when ccbin_flags is set, the custom command still fails, this time due to VCInstallDir expanding at compile time to a path containing spaces.

According to bug 15001<https://cmake.org/Bug/view.php?id=15001>, there isn't any way in CMake to correctly quote Visual Studio placeholder variables that expand to values containing spaces - you'll always get either no quotes, or escaped quotes.  However, I was able to work around this problem by getting the compiler path directly from CMake instead of using the placeholder.  Please see the attached patch (it's based on master) - with this patch, compiling CUDA code with Visual Studio works again.

Thanks,
Stephen Sorley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160217/6d25a403/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fixed-Visual-Studio-CUDA-compile-failure.patch
Type: application/octet-stream
Size: 1054 bytes
Desc: 0001-Fixed-Visual-Studio-CUDA-compile-failure.patch
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160217/6d25a403/attachment.obj>


More information about the cmake-developers mailing list