I previously asked: How to compile C++ as CUDA using CMake which was super helpful. But then realised I had a follow-on question.
What I want to do is compile one file twice, using different compilers. eg:
cmake_minimum_required(VERSION 3.9)
project(cuda_test LANGUAGES CUDA CXX)
add_executable(cuda_test_host test.cpp) # build with GCC for host
set_source_files_properties(test.cpp PROPERTIES LANGUAGE CUDA)
add_executable(cuda_test_cuda test.cpp) # build with NVCC for CUDA
But of course, the set_source_files_properties
is not specific to a particular target, so both cuda_test_host
and cuda_test_cuda
end up being built by NVCC.
I've seen similar questions on StackOverflow suggesting making sub-directories with different CMake files in, but I'd like to avoid that if at all possible.