Suppose I have a file, let's call it foo.cpp
, my goal is to compile this file with nvcc in cuda mode. From the command-line this can be easily accomplished by invoking:
nvcc --x=cu foo.cpp
What I'm struggling with, is to get CMake to do this exact same thing. It turns out that the CMake command cuda_add_executable(foo foo.cpp)
will filter the *.cpp files and use the c++-compiler (instead of nvcc).
Note that renaming all the files to *.cu is not an option as the codebase has to also support non-cuda builds.
In the FindCUDA source code I found an option to activate CUDA compilation for specific non-.cu
files. Though it seems documentation is lacking (outside of the source code).
You can set CUDA compilation on a per file level with
set_source_files_properties( foo.cpp PROPERTIES CUDA_SOURCE_PROPERTY_FORMAT OBJ )
in CMAKE 3.3 or later.
The rest works as usual:
cuda_add_executable(foo foo.cpp)
Actually, I expected there should be an easy solution like using CUDA_NVCC_FLAGS
or cuda_add_executable( ... OPTIONS --x=cu )
to pass the --x=cu
flag in. Unfortunately, it does not work. The reason is probably that the scope for a setting at that level would not be useful, since it would affect all files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With