-
Notifications
You must be signed in to change notification settings - Fork 14
/
CMakeLists.txt
282 lines (223 loc) · 8.7 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# Copyright (c) 2021, SBEL GPU Development Team
# Copyright (c) 2021, University of Wisconsin - Madison
#
# SPDX-License-Identifier: BSD-3-Clause
# ---------------------------------------------------------------------------- #
# CMake Project Settings
# ---------------------------------------------------------------------------- #
cmake_minimum_required(VERSION 3.18)
# Version information
set(DEME_VERSION_MAJOR 0)
set(DEME_VERSION_MINOR 0)
set(DEME_VERSION_PATCH 0)
project(
Simulator-MUlti-Gpu
VERSION ${DEME_VERSION_MAJOR}.${DEME_VERSION_MINOR}.${DEME_VERSION_PATCH}
LANGUAGES CXX CUDA
)
# ---------------------------------------------------------------------------- #
# Additional Packages
# ---------------------------------------------------------------------------- #
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(FetchContent)
include(cmake/FixNinjaColors.cmake)
fix_ninja_colors()
find_package(CUDAToolkit REQUIRED)
# Find CUB library (this might need to be done in source-level config)
find_package(
CUB REQUIRED
HINTS ${CUDAToolkit_ROOT}/lib64/cmake/cub
)
# Find NVIDIA's Jitify library
find_path(
NVIDIAJitifyPath
NAMES jitify.hpp
PATHS "${CMAKE_CURRENT_LIST_DIR}/thirdparty/jitify"
)
# nvidia_helper_math doesn't require any extra configuration, so just set the path
set(NVIDIAMathDir ${CMAKE_CURRENT_LIST_DIR}/thirdparty/nvidia_helper_math)
# Let the user decide if they want to use ChPF
option(USE_CHPF "Toggle the use of ChPF for outputting" OFF)
if(USE_CHPF)
# Find ChPF, else fetch it
find_package(ChPF 3.0 QUIET)
if (NOT ChPF_FOUND)
FetchContent_Declare(
ChPF
GIT_REPOSITORY https://gitlab.com/uwsbel/chpf.git
GIT_TAG 0699f01e720cecf58719a1651ab797c6a62a1897
)
FetchContent_MakeAvailable(ChPF)
endif()
# Based on whether ChPF was found or fetched, set the target name CMake can use to find it
if (ChPF_FOUND)
set(ChPF_IMPORTED_NAME "ChPF::ChPF")
elseif (chpf_POPULATED)
set(ChPF_IMPORTED_NAME "ChPF")
endif()
endif()
# ---------------------------------------------------------------------------- #
# Global Configuration
# ---------------------------------------------------------------------------- #
include(cmake/CxxStdAutodetect.cmake)
# The compiler will build against this C++ standard, if available.
set(TargetCXXStandard "STD_AUTODETECT" CACHE STRING "The C++ standard used by the compiler")
set_property(
CACHE TargetCXXStandard
PROPERTY
STRINGS STD_AUTODETECT STD_CXX11 STD_CXX14 STD_CXX17 STD_CXX20
)
# Convert the standard into something CMake will understand
if(TargetCXXStandard STREQUAL STD_CXX11)
set(CXXSTD_MAX 11)
elseif(TargetCXXStandard STREQUAL STD_CXX14)
set(CXXSTD_MAX 14)
elseif(TargetCXXStandard STREQUAL STD_CXX17)
set(CXXSTD_MAX 17)
elseif(TargetCXXStandard STREQUAL STD_CXX20)
set(CXXSTD_MAX 20)
else()
set(CXXSTD_MAX 17)
endif()
cxx_std_autodetect()
# Allow the use of #include <> for project headers (allowing cleaner better relative pathing)
set(ProjectIncludeSource "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(ProjectIncludeGenerated "${CMAKE_BINARY_DIR}/src")
# Global fix for CUDA language bug
include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
#------------------------------------------------------------
# Install destinations for data and demo programs
#------------------------------------------------------------
set(DEME_INSTALL_DEMO "bin")
# ---------------------------------------------------------------------------- #
# Source-level configuration
# ---------------------------------------------------------------------------- #
add_subdirectory(src/core)
add_subdirectory(src/DEM)
add_subdirectory(src/algorithms)
# ---------------------------------------------------------------------------- #
# Final Library Generation
# ---------------------------------------------------------------------------- #
add_library(
simulator_multi_gpu
STATIC
$<TARGET_OBJECTS:core>
$<TARGET_OBJECTS:DEM>
$<TARGET_OBJECTS:algorithms>
)
# Extract include directories from the object bundles
get_target_property(CORE_INTERFACE core INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(DEM_INTERFACE DEM INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(ALGORITHMS_INTERFACE algorithms INTERFACE_INCLUDE_DIRECTORIES)
# All targets use the same include directories, so we can cheat and just export one of them
target_include_directories(simulator_multi_gpu
PUBLIC ${CORE_INTERFACE}
)
# If use ChPF, inform the source
if(USE_CHPF)
target_compile_definitions(simulator_multi_gpu PUBLIC DEME_USE_CHPF)
set(USE_CHPF_STR "ON")
target_link_libraries(simulator_multi_gpu
PUBLIC CUDA::cudart
PUBLIC CUDA::nvrtc
PUBLIC CUDA::cuda_driver
PUBLIC ${ChPF_IMPORTED_NAME}
PUBLIC DEMERuntimeDataHelper
)
else()
set(USE_CHPF_STR "OFF")
target_link_libraries(simulator_multi_gpu
PUBLIC CUDA::cudart
PUBLIC CUDA::nvrtc
PUBLIC CUDA::cuda_driver
PUBLIC DEMERuntimeDataHelper
)
endif()
# Specific to Windows...
if(WIN32)
target_link_libraries(simulator_multi_gpu
PUBLIC dbghelp)
endif()
# Attach include directories to the top-level library target
set_target_properties(simulator_multi_gpu
PROPERTIES
LINKER_LANGUAGE CUDA
)
# ---------------------------------------------------------------------------- #
# Export and Install The Generated Targets
# ---------------------------------------------------------------------------- #
set(config_directory ${CMAKE_INSTALL_LIBDIR}/cmake/DEME)
# Install the library, creating an export target for it as well
install(
TARGETS simulator_multi_gpu DEMERuntimeDataHelper
EXPORT DEMETargets
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(CODE "message(\"Removing build-tree libraries from installation target...\")")
install(CODE "file(REMOVE \"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libDEMERuntimeDataHelper.so\")")
install(
TARGETS DEMERuntimeDataHelper_install
EXPORT DEMETargets
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
# Export the generated library target
export(EXPORT DEMETargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/DEME/DEMETargets.cmake"
NAMESPACE DEME::
)
# Set the install location for the exported target file
install(
EXPORT DEMETargets
DESTINATION
${config_directory}
NAMESPACE DEME::
)
# These macros aid in the generation of the installable config files
# Generate the **Build Tree** version of DEMEConfig.cmake from the base file
set(CONF_INCLUDE_DIRS "${ProjectIncludeSource}" "${ProjectIncludeGenerated}")
configure_file(cmake/DEMEConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/DEME/DEMEConfig.cmake"
@ONLY
)
# Generate the _Install Tree_ version of DEMEConfig.cmake from the base file
file(RELATIVE_PATH REL_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/${config_directory} ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
set(CONF_INCLUDE_DIRS "\${DEMECMakeDir}/${REL_INCLUDE_DIR}")
set(CONF_SHARE_DATA_DIRS "\${DEMECMakeDir}/${REL_INCLUDE_DIR}/../share/DEME/data")
# NOTE: This is placed in CMAKE_FILES_DIRECTORY to keep it out of the build tree
configure_file(cmake/DEMEConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DEMEConfig.cmake"
@ONLY
)
# Automatically generate a DEMEConfigVersion.cmake file
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/DEME/DEMEConfigVersion.cmake
VERSION ${DEME_VERSION_MAJOR}.${DEME_VERSION_MINOR}.${DEME_VERSION_PATCH}
COMPATIBILITY AnyNewerVersion
)
# Install the generated config files
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DEMEConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/DEME/DEMEConfigVersion.cmake"
DESTINATION
${config_directory}
)
# ---------------------------------------------------------------------------- #
# Copy data directory over
# ---------------------------------------------------------------------------- #
file(COPY ${CMAKE_CURRENT_LIST_DIR}/data/ DESTINATION ${CMAKE_BINARY_DIR}/data/)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/data/ DESTINATION ${CMAKE_INSTALL_DATADIR}/DEME/data/)
# ---------------------------------------------------------------------------- #
# Copy kernels over
# ---------------------------------------------------------------------------- #
file(COPY ${CMAKE_CURRENT_LIST_DIR}/src/kernel/ DESTINATION ${CMAKE_BINARY_DIR}/kernel/)
file(COPY ${CMAKE_CURRENT_LIST_DIR}/src/DEM/Defines.h DESTINATION ${CMAKE_BINARY_DIR}/DEM)
file(COPY ${CMAKE_CURRENT_LIST_DIR}/src/DEM/VariableTypes.h DESTINATION ${CMAKE_BINARY_DIR}/DEM)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/src/kernel/ DESTINATION ${CMAKE_INSTALL_DATADIR}/DEME/kernel/)
# ---------------------------------------------------------------------------- #
# Build embedded demos
# ---------------------------------------------------------------------------- #
add_subdirectory(src/demo)