So, in the project I’m currently involved with, it looks like this:
project
|--CMakeLists.txt
|--app
| |--CMakeLists.txt
| |--app_to_cuda
| |--CMakeLists.txt
| |--app_to_cuda.cc
| |--app_to_cuda.h
|--src
|--CMakeLists.txt
|--<source_files>
Inside project/app/CMakeLists.txt, I have done the following:
add_subdirectory(app_to_cuda)
And then inside project/app/app_to_cuda/CMakeLists.txt:
add_executable(app_to_cuda app_to_cuda.cc)
target_link_libraries(app_to_cuda ${SRC_LIBS} ${OTHER_LIBS})
Now, I want to introduce a new file in project/app/app_to_cuda to allow CUDA porting, if possible, only for app_to_cuda. To be specific, I’m changing the source tree into this:
project
|--CMakeLists.txt
|--app
| |--CMakeLists.txt
| |--app_to_cuda
| |--CMakeLists.txt
| |--app_to_cuda.cc
| |--app_to_cuda.h
| |--app_to_cuda.cu <--- Written with CUDA Kernel and stuff
|--src
|--CMakeLists.txt
|--<source_files>
So in order to do this, I have edited project/app/app_to_cuda/CMakeLists.txt into:
if (ENABLE_CUDA_APP)
find_package(CUDA REQUIRED)
include(FindCUDA)
list(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_70,code=sm_70)
cuda_add_executable(app_to_cuda app_to_cuda.cu)
target_link_libraries(app_to_cuda ${OTHER_LIBS})
else (ENABLE_CUDA_APP)
add_executable(app_to_cuda app_to_cuda.cc)
target_link_libraries(app_to_cuda ${OTHER_LIBS})
endif (ENABLE_CUDA_APP)
But it doesn’t seem to be working. First, it complains about the warning:
[...]
warning: "THRUST_CUB_NS_POSTFIX" redefined
#define THRUST_CUB_NS_POSTFIX } }
[...]
And then the error:
[...]
error: statement may not appear in a constexpr function
[...]
error: a constexpr function must contain exactly one return statement
[...]
I’m kinda lost at this point. Any suggestions on how I could resolve this?