[CMake] FindCUDA: Specify nvcc language in cuda_add_executable

Joan Puigcerver joapuipe at gmail.com
Fri Nov 14 12:26:27 EST 2014


Hi,

I'm trying to use CMake with FindCUDA to compile a C++/CUDA code, and
I am having a small issue with cuda_add_executable.

One of my files has the .cc extension, but it may import headers which
contain CUDA kernels definitions (depending on wheather I want to use
CUDA or not). So, I need to compile it as a CUDA file. You can tell
nvcc to ignore the file extension and use a particular language with
the -x option. For instance:

nvcc -x cu foo.cc

Will force to compile foo.cc as a CUDA file.

However, I don't know how to pass that compilation option to nvcc
through cuda_add_executable. I tried to set it in the CUDA_NVCC_FLAGS
variable, but it never gets passed to nvcc, since CMake calls directly
the C++ compiler.

Can anyone suggest how to force the -x option?

PS: One dirty fix is to create a symlink from foo.cc to foo.cu, and
compile foo.cu if CUDA is enable, or foo.cc if it is not. CMake works
fine with this workaround, but I'd rather pass the -x option and keep
my code base clean.


More information about the CMake mailing list