I have a working C++ project that uses OpenCV. I am creating a CMakeLists.txt file to help people compile it, and everything works fine.
In short : How do I use CMake to create a makefile to compile a ".cu" file into a ".o" with NVCC and link it with the rest of the ".o" files ?
The long version : I want to add a CUDA file that has to be compiled with NVCC. I manage to compile it by hand, but I can't figure out how to use CMake to create a makefile for doing so:
- Make NVCC compile my .cu file into a .o file if CUDA toolkit is installed, in CMake
- Use this .o file with the g++ created ones
- Not use NVCC to compile all the projects (if there is no CUDA support my project can still be compiled)
For now, I have something like this:
IF(CUDA_FOUND)
MESSAGE( STATUS "I found CUDA !" )
SET(HAVE_CUDA ${CUDA_FOUND} CACHE BOOL "Set to TRUE if CUDA is found, FALSE otherwise")
cuda_compile(CudaKernel CudaKernels.cu)
ENDIF(CUDA_FOUND)
This creates a .o file, but I don't know where/how to use it.
I then plan to add a flag like:
if(HAVE_CUDA)
set (CMAKE_CXX_FLAGS "-DGPU_OPENCV_ENABLE=1")
endif(HAVE_CUDA)
And test that flag in a MACRO in my C++ code to call the good function.
Any idea?
See Question&Answers more detail:os