forked from CExA-project/ddc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
263 lines (211 loc) · 8.07 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
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.15)
project(DDC VERSION 0.0.0 LANGUAGES CXX)
# List of options
option(BUILD_BENCHMARKS "Build DDC benchmarks." OFF)
option(BUILD_DOCUMENTATION "Build DDC documentation/website" OFF)
option(BUILD_EXAMPLES "Build DDC examples" ON)
option(DDC_BUILD_PDI_WRAPPER "Build DDC PDI wrapper" ON)
# Dependencies
set(DDC_DEPENDENCY_POLICIES "AUTO" "EMBEDDED" "INSTALLED" "SUBPROJECT")
## CMake modules
include(CMakePackageConfigHelpers)
include(CTest)
## mdspan
set(DDC_mdspan_DEPENDENCY_POLICY "AUTO" CACHE STRING "Policy to find the `mdspan` package. Options: ${DDC_DEPENDENCY_POLICIES}")
set_property(CACHE DDC_mdspan_DEPENDENCY_POLICY PROPERTY STRINGS "${DDC_DEPENDENCY_POLICIES}")
if("${DDC_mdspan_DEPENDENCY_POLICY}" STREQUAL "AUTO")
if(NOT TARGET std::mdspan)
find_package(mdspan CONFIG QUIET)
if(NOT mdspan_FOUND)
add_subdirectory(vendor/mdspan)
endif()
endif()
elseif("${DDC_mdspan_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
add_subdirectory(vendor/mdspan)
elseif("${DDC_mdspan_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(mdspan CONFIG REQUIRED)
endif()
## kokkos
set(DDC_Kokkos_DEPENDENCY_POLICY "AUTO" CACHE STRING "Policy to find the `Kokkos` package. Options: ${DDC_DEPENDENCY_POLICIES}")
set_property(CACHE DDC_Kokkos_DEPENDENCY_POLICY PROPERTY STRINGS "${DDC_DEPENDENCY_POLICIES}")
if("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "AUTO")
if(NOT TARGET Kokkos::kokkos)
find_package(Kokkos CONFIG QUIET)
if(NOT Kokkos_FOUND)
if("${Kokkos_ENABLE_CUDA}")
option(Kokkos_ENABLE_CUDA_CONSTEXPR "Whether to activate experimental relaxed constexpr functions" ON)
if(NOT "${Kokkos_ENABLE_CUDA_CONSTEXPR}")
message(SEND_ERROR "Kokkos_ENABLE_CUDA_CONSTEXPR must be enabled, currently it is not")
endif()
option(Kokkos_ENABLE_CUDA_LAMBDA "Whether to activate experimental lambda features" ON)
if(NOT "${Kokkos_ENABLE_CUDA_LAMBDA}")
message(SEND_ERROR "Kokkos_ENABLE_CUDA_LAMBDA must be 17 at least, currently it is not")
endif()
option(Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE "Whether to enable relocatable device code (RDC) for CUDA" ON)
if(NOT "${Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE}")
message(SEND_ERROR "Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE must be enabled, currently it is not")
endif()
endif()
if("${Kokkos_ENABLE_HIP}")
option(Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE "Whether to enable relocatable device code (RDC) for HIP" ON)
if(NOT "${Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE}")
message(SEND_ERROR "Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE must be enabled, currently it is not")
endif()
endif()
add_subdirectory(vendor/kokkos)
endif()
endif()
elseif("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
if("${Kokkos_ENABLE_CUDA}")
option(Kokkos_ENABLE_CUDA_CONSTEXPR "Whether to activate experimental relaxed constexpr functions" ON)
if(NOT "${Kokkos_ENABLE_CUDA_CONSTEXPR}")
message(SEND_ERROR "Kokkos_ENABLE_CUDA_CONSTEXPR must be enabled, currently it is not")
endif()
option(Kokkos_ENABLE_CUDA_LAMBDA "Whether to activate experimental lambda features" ON)
if(NOT "${Kokkos_ENABLE_CUDA_LAMBDA}")
message(SEND_ERROR "Kokkos_ENABLE_CUDA_LAMBDA must be 17 at least, currently it is not")
endif()
option(Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE "Whether to enable relocatable device code (RDC) for CUDA" ON)
if(NOT "${Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE}")
message(SEND_ERROR "Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE must be enabled, currently it is not")
endif()
endif()
if("${Kokkos_ENABLE_HIP}")
option(Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE "Whether to enable relocatable device code (RDC) for HIP" ON)
if(NOT "${Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE}")
message(SEND_ERROR "Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE must be enabled, currently it is not")
endif()
endif()
add_subdirectory(vendor/kokkos)
elseif("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(Kokkos CONFIG REQUIRED)
endif()
## PDI
if("${DDC_BUILD_PDI_WRAPPER}")
if(NOT TARGET PDI::PDI_C)
find_package(PDI REQUIRED COMPONENTS C)
endif()
endif()
## GoogleTest
if("${BUILD_TESTING}")
set(DDC_GTest_DEPENDENCY_POLICY "AUTO" CACHE STRING "Policy to find the `GTest` package. Options: ${DDC_DEPENDENCY_POLICIES}")
set_property(CACHE DDC_GTest_DEPENDENCY_POLICY PROPERTY STRINGS ${DDC_DEPENDENCY_POLICIES})
set(GOOGLETEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/vendor/googletest" CACHE PATH "Path to the googletest library source")
if("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "AUTO")
if(NOT TARGET GTest::GTest AND NOT TARGET GTest::gtest)
find_package(GTest)
if(NOT GTest_FOUND)
add_subdirectory("${GOOGLETEST_PATH}")
endif()
endif()
if(NOT TARGET GTest::gtest_main)
if(TARGET GTest::GTest)
add_library(GTest::gtest_main ALIAS GTest::GTest)
else()
add_library(GTest::gtest_main ALIAS GTest::gtest)
endif()
endif()
elseif("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
add_subdirectory("${GOOGLETEST_PATH}")
elseif("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(GTest REQUIRED)
if(NOT TARGET GTest::gtest_main)
add_library(GTest::gtest_main ALIAS GTest::GTest)
endif()
endif()
include(GoogleTest)
endif()
## Google Benchmark
if("${BUILD_BENCHMARKS}")
set(DDC_benchmark_DEPENDENCY_POLICY "AUTO" CACHE STRING "Policy to find the `benchmark` package. Options: ${DDC_DEPENDENCY_POLICIES}")
set_property(CACHE DDC_benchmark_DEPENDENCY_POLICY PROPERTY STRINGS ${DDC_DEPENDENCY_POLICIES})
option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." OFF)
option(BENCHMARK_ENABLE_INSTALL "Enable installation of benchmark. (Projects embedding benchmark may want to turn this OFF.)" OFF)
if("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "AUTO")
if(NOT TARGET benchmark::benchmark)
find_package(benchmark QUIET)
if(NOT benchmark_FOUND)
add_subdirectory(vendor/benchmark)
endif()
endif()
elseif("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
add_subdirectory(vendor/benchmark)
elseif("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(benchmark REQUIRED)
endif()
endif()
## Doxygen
if("${BUILD_DOCUMENTATION}")
find_package(Doxygen 1.8.13 REQUIRED OPTIONAL_COMPONENTS dot)
endif()
# Our project
## The library itself
add_library(DDC INTERFACE)
target_compile_features(DDC INTERFACE cxx_std_17)
target_include_directories(DDC
INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
)
target_include_directories(DDC
SYSTEM INTERFACE
"$<INSTALL_INTERFACE:include>"
)
target_link_libraries(DDC
INTERFACE std::mdspan Kokkos::kokkos)
add_library(DDC::DDC ALIAS DDC)
install(
TARGETS DDC
EXPORT DDCTargets)
## The PDI wrapper
if("${DDC_BUILD_PDI_WRAPPER}")
add_library(PDI_Wrapper INTERFACE)
target_compile_features(PDI_Wrapper INTERFACE cxx_std_17)
target_include_directories(PDI_Wrapper
INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
)
target_include_directories(PDI_Wrapper
SYSTEM INTERFACE
"$<INSTALL_INTERFACE:include>"
)
target_link_libraries(PDI_Wrapper
INTERFACE
DDC::DDC
PDI::PDI_C)
target_compile_definitions(PDI_Wrapper INTERFACE "DDC_BUILD_PDI_WRAPPER")
add_library(DDC::PDI_Wrapper ALIAS PDI_Wrapper)
install(
TARGETS PDI_Wrapper
EXPORT DDCTargets)
endif()
## if examples are enabled, build them
if("${BUILD_EXAMPLES}")
add_subdirectory(examples/)
endif()
## if tests are enabled, build them
if("${BUILD_TESTING}")
add_subdirectory(tests/)
endif()
## if benchmarks are enabled, build them
if("${BUILD_BENCHMARKS}")
add_subdirectory(benchmarks/)
endif()
## if documentation is enabled, build it
if("${BUILD_DOCUMENTATION}")
add_subdirectory(docs/)
endif()
## installation
install(
EXPORT DDCTargets
NAMESPACE DDC::
DESTINATION lib/cmake/DDC)
install(
DIRECTORY include/
TYPE INCLUDE)
configure_package_config_file(cmake/DDCConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/DDCConfig.cmake
INSTALL_DESTINATION lib/cmake/DDC)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/DDCConfig.cmake
DESTINATION lib/cmake/DDC)