Cmake compile ". cpp" as "cu"

Is it possible compile “.cpp” as “.cu” in modern cmake(3.10~)

my project structure

  • non cuda code that uses kernel code(.cpp) with runtime api
  • cuda code library(.cpp)

and cmake script

enable_language(CUDA)
set(CMAKE_CUDA_FLAGS_DEBUG "-g -G")
add_library(CUDA_KERNELS OBJECT ${GPU_KERNELS})
set_property(TARGET CUDA_KERNELS PROPERTY CUDA_PTX_COMPILATION ON)

The cmake script was originally like above, and the things I tried to compile .cpp as .cu are as follows.

 set_source_files_properties(CUDA_KERNELS LANGUAGE CUDA)
 set(CMAKE_CUDA_FLAGS  "-x cu")
set(CMAKE_CXX_EXTENSIONS OFF)

none of them works, it is not handled as cuda code.
If I change .cpp to .cu, it works well obviously

what is the correct way to compile .cpp as .cu files ?

1 Like