CMake编译CUDA

CMake编译CUDA

首先要有CUDA环境。
下面简单介绍一下CMakeLists.txt:

# CMakeLists.txt for G4CU project

project(project)

# required cmake version
cmake_minimum_required(VERSION 2.8)


# packages
find_package(CUDA)

#include_directories ("${PROJECT_SOURCE_DIR}")

# nvcc flags
set(CUDA_NVCC_FLAGS -arch=compute_30;-G;-g)

#set(CUDA_NVCC_FLAGS -gencode arch=compute_20,code=sm_20;-G;-g)
#set(CUDA_NVCC_FLAGS -gencode arch=compute_52,code=sm_52;-G;-g)

file(GLOB_RECURSE CURRENT_HEADERS  *.h *.hpp *.cuh)
file(GLOB CURRENT_SOURCES  *.cpp *.cu)

source_group("Include" FILES ${CURRENT_HEADERS}) 
source_group("Source" FILES ${CURRENT_SOURCES}) 

CUDA_ADD_EXECUTABLE(project ${CURRENT_HEADERS} ${CURRENT_SOURCES})

简单介绍:
- find_package(CUDA)是寻找CUDA包,这个功能是CMake本身带有的,CMake保存了很多的第三方库的find_Model文件,CUDA对应的是FindCUDA.cmake。
- set(CUDA_NVCC_FLAGS -arch=compute_30;-G;-g)
是设置编译的编译参数,此处我用了30带的计算能力。(详细可看nvcc编译器参数)

你可能感兴趣的:(CUDA,CMake)