Compiling CUDA through CMAKE in my project?

HI guys,

Im trying to add cuda to my project though CMAKE.

but first ive created a small test cuda file to see if i can get things compiled, to which im having problems

The main cuda calls that im using are

Using the CUDA_COMPILE macro


CUDA_COMPILE(CUDA_FILES …/blender/modifiers/ )

add_executable(blender {EXETYPE} {SRC} ${CUDA_FILES} …/blender/modifiers/intern/MOD_particlesurface.c)

The error that im getting is

1>------ Build started: Project: blender, Configuration: Debug Win32 ------

1>Building NVCC (Device) object source/creator/Debug/

1>-- Removing D:/blender/cmake/source/creator/Debug/

1>"C:/Program Files (x86)/CMake 2.8/bin/cmake.exe" -E remove D:/blender/cmake/source/creator/Debug/

1>-- Generating dependency file: D:/blender/cmake/source/creator/CMakeFiles/

1>"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v3.2/bin/nvcc.exe" -M -D__CUDACC__ D:/blender/blender/source/creator/../blender/modifiers/ -o D:/blender/cmake/source/creator/CMakeFiles/ -m32 -DWIN32 -D__SSE__ -D__MMX__ -DWITH_OPENEXR -DWITH_TIFF -DWITH_DDS -DWITH_CINEON -DWITH_HDR -DWITH_PYTHON -DWITH_GAMEENGINE -DBUILD_DATE= Thu 10/02/2011\" -DBUILD_TIME=\"02:57 PM\" -DBUILD_REV=\"unknown\" -DBUILD_PLATFORM=\"Windows\" -DBUILD_TYPE=\"\" -DBUILD_CFLAGS=\"/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /we4013 /wd4018 /wd4800 /wd4244 /wd4305 /wd4065 /wd4267 -DBUILD_CXXFLAGS= /D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /we4013 /wd4018 /wd4800 /wd4244 /wd4305 /wd4065 /wd4267 -DBUILD_LINKFLAGS= /NODEFAULTLIB:libc.lib -DBUILD_SYSTEM= CMake\"\" -Xcompiler ,\"/D_CRT_NONSTDC_NO_DEPRECATE\",\"/D_CRT_SECURE_NO_DEPRECATE\",\"/D_SCL_SECURE_NO_DEPRECATE\",\"/we4013\",\"/wd4018\",\"/wd4800\",\"/wd4244\",\"/wd4305\",\"/wd4065\",\"/wd4267\",\"/D_DEBUG\",\"/Od\",\"/Gm\",\"/EHsc\",\"/RTC1\",\"/MTd\",\"/W3\",\"/nologo\",\"/ZI\",\"/J\" -DNVCC -ID:/blender/blender/source/creator "-IC:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v3.2/include" -ID:/blender/lib/windows/pthreads/include -ID:/blender/blender/intern/guardedalloc -ID:/blender/blender/source/blender/blenlib -ID:/blender/blender/source/blender/blenkernel -ID:/blender/blender/source/blender/editors/include -ID:/blender/blender/source/blender/makesrna -ID:/blender/blender/source/blender/imbuf -ID:/blender/blender/source/blender/render/extern/include -ID:/blender/blender/source/blender/makesdna -ID:/blender/blender/source/blender/gpu -ID:/blender/blender/source/blender/windowmanager -ID:/blender/blender/source/blender/python -ID:/blender/blender/source/kernel/gen_messaging -ID:/blender/blender/source/kernel/gen_system

1>CMake Error at CMakeFiles/ (message):

1>  Error generating

1>  D:/blender/cmake/source/creator/Debug/

1>Project : error PRJ0019: A tool returned an error code from "Building NVCC (Device) object source/creator/Debug/"

1>Build log was saved at "file://d:\blender\cmake\source\creator\blender.dir\Debug\BuildLog.htm"

1>blender - 1 error(s), 0 warning(s)

2>------ Skipped Build: Project: ALL_BUILD, Configuration: Debug Win32 ------

2>Project not selected to build for this solution configuration 

========== Build: 0 succeeded, 1 failed, 96 up-to-date, 1 skipped ==========

Can anyone give me some hints as to whats going wrong?

Hello, I’m the author of FindCUDA.cmake. Sorry to hear about your problem. Let’s see if we can get to the bottom of this problem and get you a fix.

First off, you can use the cuda_add_executable in place of cuda_compile and add_executable. You should also add both CUDA_FILES and …/blender/modifiers/ to add_executable in order to get the build rules to work.

That’s not your problem, though.

What version of CMake are you using? The latest version is 2.8.3 (2.8.4 Release Candidate 2 is also available).

I think the issue you are having is related to some funny quoting action:

-DBUILD_DATE= Thu 10/02/2011"

It’s missing some quotes.

FindCUDA is designed to grab all the preprocessor definitions and host compiler flags and pass them along through nvcc to the host compiler. Could you tell me what this flag is supposed to look like when compiling regular C files?

Also, in your build directory there should be a file called This is the script that is generated by CMake at configure time that is used at compile time to invoke nvcc. If you could, could you please attach that file to the forum? You can also reach me via a private message.

HI jBigler,

Thankyou so much for taking the time to answer my question.

THe version of cmake that im using is 2.8.3 however i have tried doing this with your latest commit from svn

IM not sure i understand what you mean i am a little new to this.

the forum wont let me attach the file so ive uploaded it to my website … I think this is the file you are after…

Thanks for the file. Yeah, this looks like a known issue that should hopefully be fixed in CMake 2.8.5 (missed the deadline for 2.8.4). You can fix it yourself by patching your CMake installation:

Edit run_nvcc.cmake found in Modules/FindCUDA/run_nvcc.cmake in the installation location.

Take the quotes off the @nvcc_flags@.

< set(nvcc_flags “@nvcc_flags@”)

set(nvcc_flags @nvcc_flags@)

thankyou for the solution, I made those changes and have moved onto the next bug :)