[CMake] CMake specify using either NVCC or host compilers with add_executable

Quang Ha quang.t.ha.20 at gmail.com
Mon Aug 27 11:39:54 EDT 2018


Hi all,

With the new way CMake is treating CUDA codes, now we can do:

project(foo LANGUAGES CXX CUDA)

and can do:

add_executable(foo_cuda foo.cu) # will use NVCC
add_executable(foo_cpp foo.cpp) # will use host compilers

Now since CUDA can take *.cpp files as extension (see
https://stackoverflow.com/questions/26208784/cuda-cpp-files), is there a
away to flip the compiler using one single source files? Something along
the line of:

if(CUDA_FOUND)
  add_executable_with_nvcc(foo_cuda foo.cpp) # of course this doesn't exist
else(CUDA_FOUND)
  add_executable_with_cpp(foo_cpp foo.cpp) # neither does this
endif(CUDA_FOUND)

Or would anyone suggest a work-around? With the help of add_definitions, I
can manually compile a host and device executable - just need to integrate
this final step into the project.

Thanks,
Quang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180827/1612ffc9/attachment.html>


More information about the CMake mailing list