Last active
April 15, 2024 17:17
-
-
Save erikzenker/713c4ff76949058d5d5d to your computer and use it in GitHub Desktop.
CMake CUDA + C++ in separate files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CMAKE FILE to separatly compile cuda and c++ files | |
# with the c++11 standard | |
# | |
# | |
# Folder structure: | |
# | |
# | | |
# +--main.cpp (with C++11 content) | |
# +--include/ | |
# | | | |
# | +--kernel.h | |
# | | |
# +--src/ | |
# | | | |
# | +--kernel.cu | |
# - | |
project(Cuda+C++11) | |
cmake_minimum_required(VERSION 2.8) | |
# CUDA PACKAGE | |
find_package(CUDA REQUIRED) | |
set(CUDA_SEPARABLE_COMPILATION ON) | |
set(CUDA_PROPAGATE_HOST_FLAGS OFF) | |
set(CUDA_HOST_COMPILER clang++) | |
# COMPILE CU FILES | |
file(GLOB CUDA_FILES "src/" *.cu) | |
list( APPEND CUDA_NVCC_FLAGS "-gencode arch=compute_30,code=sm_30; -std=c++11") | |
CUDA_COMPILE(CU_O ${CUDA_FILES}) | |
# SETUP FOR CPP FILES | |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | |
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) | |
# COMPILE AND LINK | |
cuda_add_executable(main ${CMAKE_CURRENT_SOURCE_DIR}/main.cc ${CU_O}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment