cmake_minimum_required(VERSION 2.6.2) project (prog1) find_package(CUDA REQUIRED) if( CUDA_CUDA_LIBRARY) message(STATUS " CUDA found on this system") #this block sets up the shared library called prog1 set (CUDA_NVCC_FLAGS --shared --compiler-options;'-fPIC' ) include_directories(${CUDA_INCLUDE_DIRS}) cuda_add_library(prog1 SHARED cu_lib.cu) target_link_libraries(prog1 ${CUDA_LIBRARIES}) #this compiles and links the binary, which is called eg include_directories(${CMAKE_SOURCE_DIR}) add_executable(eg driver.c) set (libs_to_link prog1 ${CUDA_LIBRARIES}) target_link_libraries(eg ${libs_to_link}) else( CUDA_CUDA_LIBRARY) message(STATUS "oops CUDA not found on this system") endif(CUDA_CUDA_LIBRARY)