| 1 |
# SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 |
# SPDX-License-Identifier: Apache-2.0 |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
# you may not use this file except in compliance with the License. |
| 6 |
# You may obtain a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
# See the License for the specific language governing permissions and |
| 14 |
# limitations under the License. |
| 15 |
|
| 16 |
cmake_minimum_required(VERSION 3.14 FATAL_ERROR) |
| 17 |
|
| 18 |
project(CCCLDemo CUDA) |
| 19 |
|
| 20 |
# This example uses the CMake Package Manager (CPM) to simplify fetching CCCL from GitHub |
| 21 |
# For more information, see https://github.com/cpm-cmake/CPM.cmake |
| 22 |
include(cmake/CPM.cmake) |
| 23 |
|
| 24 |
|
| 25 |
# We define these as variables so they can be overriden in CI to pull from a PR instead of CCCL `main` |
| 26 |
# In your project, these variables are unncessary and you can just use the values directly |
| 27 |
set(CCCL_REPOSITORY "nvidia/cccl" CACHE STRING "GitHub repository to fetch CCCL from") |
| 28 |
set(CCCL_TAG "main" CACHE STRING "Git tag/branch to fetch from CCCL repository") |
| 29 |
|
| 30 |
# This will automatically clone CCCL from GitHub and make the exported cmake targets available |
| 31 |
CPMAddPackage( |
| 32 |
NAME CCCL |
| 33 |
GITHUB_REPOSITORY ${CCCL_REPOSITORY} |
| 34 |
GIT_TAG ${CCCL_TAG} |
| 35 |
) |
| 36 |
|
| 37 |
# Default to building for the GPU on the current system |
| 38 |
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES) |
| 39 |
set(CMAKE_CUDA_ARCHITECTURES native) |
| 40 |
endif() |
| 41 |
|
| 42 |
# Creates a cmake executable target for the main program |
| 43 |
add_executable(example_project example.cu) |
| 44 |
|
| 45 |
# "Links" the CCCL Cmake target to the `example_project` executable. This configures everything needed to use |
| 46 |
# CCCL headers, including setting up include paths, compiler flags, etc. |
| 47 |
target_link_libraries(example_project PRIVATE CCCL::CCCL) |
| 48 |
|
| 49 |
# This is only relevant for internal testing and not needed by end users. |
| 50 |
include(CTest) |
| 51 |
enable_testing() |
| 52 |
add_test(NAME example_project COMMAND example_project) |