[CMake] FindCUDA: Specify nvcc language in cuda_add_executable

James Bigler jamesbigler at gmail.com
Mon Nov 24 12:54:18 EST 2014


cuda_add_executable(mytarget foo.cc OPTIONS -x cu)

Unfortunately, FindCUDA is setup to ignore any files that aren't .cu files.

CUDA_WRAP_SRCS()
...
  foreach(file ${ARGN})
    # Ignore any file marked as a HEADER_FILE_ONLY
    get_source_file_property(_is_header ${file} HEADER_FILE_ONLY)
    if(${file} MATCHES ".*\\.cu$" AND NOT _is_header)


On Fri, Nov 14, 2014 at 10:26 AM, Joan Puigcerver <joapuipe at gmail.com>
wrote:

> 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.
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141124/071677c3/attachment.html>


More information about the CMake mailing list