CUDA Object Linking and CMake

Hi! Right now I am working on a project that uses the object linking capabilities of Cuda 5.0. Since the project is starting to get complex, I wanted to switch to using cmake to compile the code. I wanted to know if this was possible.

I’ve been trying to figure this out on my own, but I haven’t had much luck. I understand that a separate object file needs to be compiled using “nvcc -dlink” and then included with the final compilation since cmake does the final compilation using g++. Not really sure how to make this part happen though.

I’m currently attempting to do this using a toy version of the project which is structured similarly the original project. The toy project consists of a main file (TextureMain.cu) that calls a kernel function to run on the GPU. In each GPU thread an instance of a user-defined class (TextureFunc) is referenced, where the class exists in a separate folder from the main file. The class consists of a TextureFunc.cu and TextureFunc.h file in that folder. I have been able to get this code to compile using Makefiles.

Here are the CMakeList.txt files I have been working with:

In the project directory (contains src directory):

project(TextureMain)
cmake_minimum_required(VERSION 2.8)
find_package(CUDA REQUIRED)

#-------------------------------------------------------------------------------
set(CUDA_NVCC_FLAGS "-arch=sm_20; -rdc=true")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lm -L/opt/cuda/lib64")
include_directories(src/TextureFunc)
include_directories(src)

#-------------------------------------------------------------------------------
#add subdirectories
add_subdirectory(src/TextureFunc)
add_subdirectory(src)

In the src directory (contains TextureMain.cu and TextureFunc directory):

cuda_add_executable(TextureMain TextureMain.cu)
target_link_libraries(TextureMain TextureFunc)
install(TARGETS TextureMain DESTINATION bin)

In TextureFunc directory (contains TextureFunc.h and TextureFunc.cu):

cuda_add_library(TextureFunc TextureFunc.cu )
target_link_libraries(TextureFunc)

Obviously when I try to use these files, I get a linking error since I haven’t included the separately compiled linking file. I don’t really know how to have this file created using cmake though. Any help would be greatly appreciated.