Building CUDA object files using cmake

20,777

It is possible to compile object files with the CUDA support that comes with newer versions of cmake. You use the cuda_compile command. See below.

# CMakeLists.txt for G4CU project                                                                                                                                                                          
project(test-cuda-thrust-gdb)

# required cmake version                                                                                                                                                                                   
cmake_minimum_required(VERSION 2.8)

# packages                                                                                                                                                                                                 
find_package(CUDA)

# nvcc flags                                                                                                                                                                                               
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode arch=compute_20,code=sm_20)

cuda_compile(HELPER_O helper.cu)
cuda_compile(DRIVER_O driver.cu OPTIONS -G)

cuda_add_executable(driver ${HELPER_O} ${DRIVER_O})

If you need more information have a look at the FindCUDA.cmake file.

Share:
20,777
soriak
Author by

soriak

Updated on November 06, 2020

Comments

  • soriak
    soriak over 3 years

    I got the following setup. I'm going to extend a framework written in C++ using MPI and other Stuff using CUDA. The Project uses cmake for building. I would like to avoid using a library for my extensions and build object files from my cuda sources. Afterwards I would like to link these object object files and some other files compiled with other compilers. Does anyone have a clue on hwo to achieve that?

    I had a look at http://code.google.com/p/cudpp/wiki/BuildingCUDPPwithCMake for getting an overview on how to use CUDA with cmake but this solution uses a library as well.

  • soriak
    soriak over 11 years
    thanks for your answer. I decided to go for the library version after all, thank you anyway