-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCMakeLists.txt
139 lines (113 loc) · 4.29 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Root CMake file for CUDA/CMake example project.
#
# # # # # # # # # # # #
# The MIT License (MIT)
#
# Copyright (c) 2019 Stephen Sorley
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# # # # # # # # # # # #
cmake_minimum_required(VERSION 3.14)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(ProjectSetup)
project(CudaExample
VERSION 0.1
LANGUAGES CXX CUDA
)
include(IDESetup)
include(InstallDeps)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set up compiler and linker options.
include(AddFlags)
include(CUDASetup)
# Require C++14, and disable compiler-specific extensions (if possible).
foreach(lang CXX CUDA)
set(CMAKE_${lang}_STANDARD 14)
set(CMAKE_${lang}_STANDARD_REQUIRED ON)
set(CMAKE_${lang}_EXTENSIONS OFF)
endforeach()
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Find third-party dependencies.
find_package(OpenMP QUIET COMPONENTS CXX)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Build rules.
add_executable(cudatest
main.cpp
test.cu
)
add_executable(test_cublas
test_cublas.cpp
)
target_link_libraries(test_cublas PRIVATE
CUDA::cublas
CUDA::cudart_static
)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Install rules.
install(TARGETS
cudatest
test_cublas
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
install_deps(lib bin
CUDA::cublas
)
install_deps_system(lib bin)
if(WIN32)
configure_file(LICENSE LICENSE.txt NEWLINE_STYLE WIN32)
configure_file(README.md README.txt NEWLINE_STYLE WIN32)
set(license_file "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt")
set(readme_file "${CMAKE_CURRENT_BINARY_DIR}/README.txt")
else()
set(license_file "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(readme_file "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
endif()
install(FILES "${license_file}" "${readme_file}"
DESTINATION .
)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Packaging rules.
set(CPACK_GENERATOR ZIP) # Always generate a ZIP archive (at least).
set(CPACK_VERBATIM_VARIABLES TRUE)
# Don't include version number in default installation directory.
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}")
set(CPACK_PACKAGE_VENDOR "Stephen Sorley")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "CUDA/CMake Example")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_RESOURCE_FILE_README "${readme_file}")
set(CPACK_RESOURCE_FILE_LICENSE "${license_file}")
if(WIN32)
# If targeting windows, also use WiX to create an MSI, if available.
if(EXISTS "$ENV{WIX}" OR EXISTS "${CPACK_WIX_ROOT}")
set(def TRUE)
else()
set(def FALSE)
endif()
option(PKG_WIX "Use WiX Toolset to create installer?" ${def})
if(PKG_WIX)
list(APPEND CPACK_GENERATOR WIX)
set(CPACK_WIX_UPGRADE_GUID 78BF12A8-7691-45D2-818E-7BABF777E49C)
set(CPACK_WIX_PROPERTY_ARPHELPLINK https://github.com/stephen-sorley/cuda-cmake/)
endif()
else()
# If targeting *nix, also create a self-extracting gzipped tar file.
list(APPEND CPACK_GENERATOR STGZ)
endif()
include(CPack)