-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
307 lines (253 loc) · 9.17 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# Copyright (C) The DDC development team, see COPYRIGHT.md file
#
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.22)
project(DDC VERSION 0.1.0 LANGUAGES CXX)
# List of options
option(DDC_BUILD_BENCHMARKS "Build DDC benchmarks." OFF)
option(DDC_BUILD_DOCUMENTATION "Build DDC documentation/website" OFF)
option(
DDC_BUILD_DOUBLE_PRECISION
"Build DDC with double precision support, float is used otherwise"
ON
)
option(DDC_BUILD_EXAMPLES "Build DDC examples" ON)
option(DDC_BUILD_KERNELS_FFT "Build DDC kernels for FFT" ON)
option(DDC_BUILD_KERNELS_SPLINES "Build DDC kernels for splines" ON)
option(DDC_BUILD_PDI_WRAPPER "Build DDC PDI wrapper" ON)
option(DDC_BUILD_TESTS "Build DDC tests if BUILD_TESTING is enabled" ON)
# Dependencies
set(DDC_DEPENDENCY_POLICIES "AUTO" "EMBEDDED" "INSTALLED" "SUBPROJECT")
## CMake modules
include(CMakePackageConfigHelpers)
include(CTest)
## Custom cmake modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(DDCVendorConfiguration)
## 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 4.4...4.5 QUIET)
if(NOT Kokkos_FOUND)
ddc_configure_kokkos()
endif()
endif()
elseif("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
ddc_configure_kokkos()
elseif("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(Kokkos 4.4...4.5 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}" AND "${DDC_BUILD_TESTS}")
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})
if("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "AUTO")
if(NOT TARGET GTest::GTest AND NOT TARGET GTest::gtest)
find_package(GTest QUIET)
if(NOT GTest_FOUND)
ddc_configure_googletest()
endif()
endif()
elseif("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
ddc_configure_googletest()
elseif("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(GTest REQUIRED)
endif()
include(GoogleTest)
endif()
## Google Benchmark
if("${DDC_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})
if("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "AUTO")
if(NOT TARGET benchmark::benchmark)
find_package(benchmark QUIET)
if(NOT benchmark_FOUND)
ddc_configure_benchmark()
endif()
endif()
elseif("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
ddc_configure_benchmark()
elseif("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(benchmark REQUIRED)
endif()
endif()
## Doxygen
if("${DDC_BUILD_DOCUMENTATION}")
find_package(Doxygen 1.8.13 REQUIRED OPTIONAL_COMPONENTS dot)
endif()
# Our project
## The library itself
### DDC legacy target
add_library(DDC INTERFACE)
add_library(DDC::DDC ALIAS DDC)
install(TARGETS DDC EXPORT DDCTargets)
add_library(ddc_core INTERFACE)
add_library(DDC::core ALIAS ddc_core)
install(TARGETS ddc_core EXPORT DDCTargets)
if("${DDC_BUILD_DOUBLE_PRECISION}")
target_compile_definitions(ddc_core INTERFACE DDC_BUILD_DOUBLE_PRECISION)
endif()
target_compile_features(ddc_core INTERFACE cxx_std_17)
target_include_directories(
ddc_core
INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>"
)
target_link_libraries(ddc_core INTERFACE Kokkos::kokkos)
### DDC legacy target
target_link_libraries(DDC INTERFACE DDC::core)
# Link library to DDC
if("${DDC_BUILD_KERNELS_FFT}")
# Kokkos-fft
set(DDC_KokkosFFT_DEPENDENCY_POLICY
"AUTO"
CACHE STRING
"Policy to find the `Kokkos-fft` package. Options: ${DDC_DEPENDENCY_POLICIES}"
)
set_property(
CACHE DDC_KokkosFFT_DEPENDENCY_POLICY
PROPERTY STRINGS "${DDC_DEPENDENCY_POLICIES}"
)
if("${DDC_KokkosFFT_DEPENDENCY_POLICY}" STREQUAL "AUTO")
if(NOT TARGET KokkosFFT::fft)
find_package(KokkosFFT 0.2.1...<1 QUIET)
if(NOT KokkosFFT_FOUND)
ddc_configure_kokkos_fft()
endif()
endif()
elseif("${DDC_KokkosFFT_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
ddc_configure_kokkos_fft()
elseif("${DDC_KokkosFFT_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(KokkosFFT 0.2.1...<1 REQUIRED)
endif()
add_library(ddc_fft INTERFACE)
add_library(DDC::fft ALIAS ddc_fft)
install(TARGETS ddc_fft EXPORT DDCTargets)
target_compile_definitions(ddc_fft INTERFACE "DDC_BUILD_KERNELS_FFT")
target_link_libraries(ddc_fft INTERFACE DDC::core Kokkos::kokkos KokkosFFT::fft)
### DDC legacy target
target_link_libraries(DDC INTERFACE DDC::fft)
endif()
if("${DDC_BUILD_KERNELS_SPLINES}")
# Ginkgo
find_package(Ginkgo 1.8.0 EXACT REQUIRED)
# Lapacke
find_package(LAPACKE REQUIRED)
# Kokkos-kernels
set(DDC_KokkosKernels_DEPENDENCY_POLICY
"AUTO"
CACHE STRING
"Policy to find the `KokkosKernels` package. Options: ${DDC_DEPENDENCY_POLICIES}"
)
set_property(
CACHE DDC_KokkosKernels_DEPENDENCY_POLICY
PROPERTY STRINGS "${DDC_DEPENDENCY_POLICIES}"
)
if("${DDC_KokkosKernels_DEPENDENCY_POLICY}" STREQUAL "AUTO")
if(NOT TARGET Kokkos::kokkoskernels)
find_package(KokkosKernels QUIET)
if(NOT KokkosKernels_FOUND)
ddc_configure_kokkos_kernels()
endif()
endif()
elseif("${DDC_KokkosKernels_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
ddc_configure_kokkos_kernels()
elseif("${DDC_KokkosKernels_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(KokkosKernels REQUIRED)
endif()
add_library(ddc_splines INTERFACE)
add_library(DDC::splines ALIAS ddc_splines)
install(FILES cmake/FindLAPACKE.cmake DESTINATION lib/cmake/DDC)
install(TARGETS ddc_splines EXPORT DDCTargets)
target_compile_definitions(ddc_splines INTERFACE "DDC_BUILD_KERNELS_SPLINES")
target_include_directories(ddc_splines SYSTEM INTERFACE ${LAPACKE_INCLUDE_DIRS})
target_link_libraries(
ddc_splines
INTERFACE DDC::core Ginkgo::ginkgo Kokkos::kokkos Kokkos::kokkoskernels ${LAPACKE_LIBRARIES}
)
### DDC legacy target
target_link_libraries(DDC INTERFACE DDC::splines)
endif()
## The PDI wrapper
if("${DDC_BUILD_PDI_WRAPPER}")
add_library(ddc_pdi INTERFACE)
add_library(DDC::pdi ALIAS ddc_pdi)
install(TARGETS ddc_pdi EXPORT DDCTargets)
target_compile_definitions(ddc_pdi INTERFACE "DDC_BUILD_PDI_WRAPPER")
target_compile_features(ddc_pdi INTERFACE cxx_std_17)
target_include_directories(
ddc_pdi
INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>"
)
target_link_libraries(ddc_pdi INTERFACE DDC::core PDI::PDI_C)
### PDI_Wrapper legacy target
add_library(PDI_Wrapper INTERFACE)
set_target_properties(PDI_Wrapper PROPERTIES DEPRECATION "Use DDC::pdi instead")
add_library(DDC::PDI_Wrapper ALIAS PDI_Wrapper)
install(TARGETS PDI_Wrapper EXPORT DDCTargets)
target_link_libraries(PDI_Wrapper INTERFACE DDC::pdi)
### DDC legacy target
target_link_libraries(DDC INTERFACE DDC::pdi)
endif()
## if examples are enabled, build them
if("${DDC_BUILD_EXAMPLES}")
add_subdirectory(examples/)
endif()
## if tests are enabled, build them
if("${BUILD_TESTING}" AND "${DDC_BUILD_TESTS}")
add_subdirectory(tests/)
endif()
## if benchmarks are enabled, build them
if("${DDC_BUILD_BENCHMARKS}")
add_subdirectory(benchmarks/)
endif()
## if documentation is enabled, build it
if("${DDC_BUILD_DOCUMENTATION}")
add_subdirectory(docs/)
endif()
## installation
install(EXPORT DDCTargets NAMESPACE DDC::impl:: 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
)
# We use SameMinorVersion until major version 1
if(PROJECT_VERSION VERSION_GREATER_EQUAL 1)
message(FATAL_ERROR "DDC must switch COMPATIBILITY mode to SameMajorVersion")
endif()
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/DDCConfigVersion.cmake
COMPATIBILITY SameMinorVersion
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/DDCConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/DDCConfigVersion.cmake
DESTINATION lib/cmake/DDC
)