forked from NVIDIA/stdexec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
456 lines (369 loc) · 16.3 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
cmake_minimum_required(VERSION 3.25.0)
if(POLICY CMP0135)
# make the timestamps of ExternalProject_ADD match the download time
# https://cmake.org/cmake/help/latest/policy/CMP0135.html
cmake_policy(SET CMP0135 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0135 NEW)
endif()
if(POLICY CMP0141)
# Enables the use of the MSVC_DEBUG_INFORMATION_FORMAT target property
# https://cmake.org/cmake/help/latest/policy/CMP0141.html
cmake_policy(SET CMP0141 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0141 NEW)
endif()
##############################################################################
# - Download and initialize RAPIDS CMake helpers -----------------------------
# Fetch rapids-cmake
if(NOT EXISTS ${CMAKE_BINARY_DIR}/RAPIDS.cmake)
file(DOWNLOAD https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-24.02/RAPIDS.cmake
${CMAKE_BINARY_DIR}/RAPIDS.cmake)
endif()
# Initialize rapids-cmake
include(${CMAKE_BINARY_DIR}/RAPIDS.cmake)
# utilities for generating export set package metadata
include(rapids-export)
# utilities for finding packages
include(rapids-find)
# utilities for defining project defaults
include(rapids-cmake)
# utilities for using CPM
include(rapids-cpm)
##############################################################################
# - Project definition -------------------------------------------------------
# Define the project and set the version and languages
if(NOT EXISTS ${CMAKE_BINARY_DIR}/execution.bs)
file(DOWNLOAD "https://raw.githubusercontent.com/cplusplus/sender-receiver/main/execution.bs"
${CMAKE_BINARY_DIR}/execution.bs)
endif()
file(STRINGS "${CMAKE_BINARY_DIR}/execution.bs" STD_EXECUTION_BS_REVISION_LINE REGEX "Revision: [0-9]+")
string(REGEX REPLACE "Revision: ([0-9]+)" "\\1" STD_EXECUTION_BS_REVISION ${STD_EXECUTION_BS_REVISION_LINE})
# nvc++ isn't supported by (s)ccache yet, so unset these before the `project()`
# call so CMake's CXX compiler detection doesn't throw attempting to use it
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/CompilerHelpers.cmake)
project(STDEXEC VERSION "0.${STD_EXECUTION_BS_REVISION}.0" LANGUAGES CXX)
# Print CMake configuration
message(STATUS "System : ${CMAKE_SYSTEM}")
message(STATUS "System name : ${CMAKE_SYSTEM_NAME}")
message(STATUS "System ver : ${CMAKE_SYSTEM_VERSION}")
message(STATUS)
# Set the version and current build date
set(STDEXEC_VERSION "${PROJECT_VERSION}")
set(STDEXEC_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
string(TIMESTAMP STDEXEC_BUILD_DATE "%Y-%m-%d")
string(TIMESTAMP STDEXEC_BUILD_YEAR "%Y")
message(STATUS "Library ver : ${STDEXEC_VERSION}")
message(STATUS "Build date : ${STDEXEC_BUILD_DATE}")
message(STATUS "Build year : ${STDEXEC_BUILD_YEAR}")
message(STATUS)
# Integrate with LLVM/clang tooling
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Write the version header
rapids_cmake_write_version_file(include/stdexec_version_config.hpp)
# Set CMAKE_BUILD_TYPE=Release the default if none provided
rapids_cmake_build_type(Release)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
# Don't build tests if configuring stdexec as a submodule of another
# CMake project, unless they explicitly set STDEXEC_BUILD_TESTS=TRUE,
# or they enabled CTest's BUILD_TESTING option
if ((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) OR BUILD_TESTING)
set(STDEXEC_BUILD_TESTS_DEFAULT ON)
else()
set(STDEXEC_BUILD_TESTS_DEFAULT OFF)
endif()
option(STDEXEC_BUILD_TESTS "Build stdexec tests" ${STDEXEC_BUILD_TESTS_DEFAULT})
# STDEXEC_BUILD_TESTS is used solely to configure CTest's BUILD_TESTING option,
# which is CMake's preferred option for enabling testing when using CTest.
set(BUILD_TESTING ${STDEXEC_BUILD_TESTS})
if (BUILD_TESTING)
# CTest automatically calls enable_testing() if BUILD_TESTING is ON
# https://cmake.org/cmake/help/latest/module/CTest.html#module:CTest
include(CTest)
endif()
##############################################################################
# - Dependencies -------------------------------------------------------------
# Initialize CPM
rapids_cpm_init(OVERRIDE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/versions.json)
if (BUILD_TESTING)
# Add Catch2
set(Catch2_VERSION 2.13.6)
# Always download it, don't attempt to do `find_package(Catch2)` first
set(CPM_DOWNLOAD_Catch2 TRUE)
rapids_cpm_find(Catch2 ${Catch2_VERSION}
GLOBAL_TARGETS Catch2::Catch2
BUILD_EXPORT_SET stdexec-exports
CPM_ARGS
URL https://github.com/catchorg/Catch2/archive/refs/tags/v${Catch2_VERSION}.zip
)
endif()
# Add ICM
set(icm_VERSION 1.5.0)
# Always download it, don't attempt to do `find_package(ICM)` first
set(CPM_DOWNLOAD_icm TRUE)
rapids_cpm_find(icm ${icm_VERSION}
CPM_ARGS
GITHUB_REPOSITORY iboB/icm
GIT_TAG v${icm_VERSION}
VERSION ${icm_VERSION}
PATCH_COMMAND git restore -- . && git apply ${CMAKE_CURRENT_LIST_DIR}/cmake/cpm/patches/icm/regex-build-error.diff
)
# Ensure that we link with the threading library
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
rapids_find_package(Threads REQUIRED
BUILD_EXPORT_SET stdexec-exports
INSTALL_EXPORT_SET stdexec-exports
)
##############################################################################
# - Main library targets -----------------------------------------------------
# Detect the compiler frontend (GNU, Clang, MSVC, etc.)
if(DEFINED CMAKE_CXX_COMPILER_FRONTEND_VARIANT)
set(stdexec_compiler_frontend ${CMAKE_CXX_COMPILER_FRONTEND_VARIANT})
else()
set(stdexec_compiler_frontend ${CMAKE_CXX_COMPILER_ID})
endif()
set(stdexec_export_targets)
# Define the main library
add_library(stdexec INTERFACE)
list(APPEND stdexec_export_targets stdexec)
# Set library version
set_target_properties(stdexec PROPERTIES
VERSION "${STDEXEC_VERSION}"
SOVERSION "${STDEXEC_VERSION_MAJOR}")
# Declare the public include directories
include(GNUInstallDirs)
target_include_directories(stdexec INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(stdexec INTERFACE Threads::Threads)
# Use C++20 standard
target_compile_features(stdexec INTERFACE cxx_std_20)
# # Enable GPU compilation when using NVHPC compiler
# target_compile_options(stdexec INTERFACE
# $<$<COMPILE_LANG_AND_ID:CXX,NVHPC>:-stdpar=gpu>
# )
# target_link_options(stdexec INTERFACE
# $<$<LINK_LANG_AND_ID:CXX,NVHPC>:-stdpar=gpu>
# )
# Enable coroutines for GCC
target_compile_options(stdexec INTERFACE
$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-fcoroutines>
)
# Increase the concepts diagnostics depth for GCC
target_compile_options(stdexec INTERFACE
$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-fconcepts-diagnostics-depth=10>
)
# Do you want a preprocessor that works? Picky, picky.
target_compile_options(stdexec INTERFACE
$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/Zc:__cplusplus /Zc:preprocessor>
)
option(STDEXEC_ENABLE_EXTRA_TYPE_CHECKING "Enable extra type checking that is costly at compile-time" OFF)
if (STDEXEC_ENABLE_EXTRA_TYPE_CHECKING)
target_compile_definitions(stdexec INTERFACE STDEXEC_ENABLE_EXTRA_TYPE_CHECKING)
endif()
add_library(STDEXEC::stdexec ALIAS stdexec)
# Don't require building everything when installing
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY ON)
# Support target for examples and tests
add_library(stdexec_executable_flags INTERFACE)
# Enable warnings
target_compile_options(stdexec_executable_flags INTERFACE
$<$<STREQUAL:${stdexec_compiler_frontend},GNU>:-Wall>
$<$<STREQUAL:${stdexec_compiler_frontend},AppleClang>:-Wall>
$<$<STREQUAL:${stdexec_compiler_frontend},MSVC>:/W4>)
# Increase the error limit with NVC++
target_compile_options(stdexec_executable_flags INTERFACE
$<$<CXX_COMPILER_ID:NVHPC>:-e1000>)
# Silence warnings
target_compile_options(stdexec_executable_flags INTERFACE
$<$<CXX_COMPILER_ID:GNU>:-Wno-non-template-friend>
$<$<CXX_COMPILER_ID:NVHPC>:--diag_suppress177,550,111,497,554>
$<$<CXX_COMPILER_ID:MSVC>:/wd4100 /wd4101 /wd4127 /wd4324 /wd4456 /wd4459>)
# Template backtrace limit
target_compile_options(stdexec_executable_flags INTERFACE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
$<$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},MSVC>:/clang:>-ferror-limit=0
$<$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},MSVC>:/clang:>-fmacro-backtrace-limit=0
$<$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},MSVC>:/clang:>-ftemplate-backtrace-limit=0>
$<$<AND:$<CXX_COMPILER_ID:NVHPC>,$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,23.3.0>>:
-ftemplate-backtrace-limit=0>)
# # Always enable colored output
# target_compile_options(stdexec_executable_flags INTERFACE
# $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
# -fcolor-diagnostics>
# $<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
# )
# Clang CUDA options
target_compile_options(stdexec_executable_flags INTERFACE
$<$<COMPILE_LANG_AND_ID:CUDA,Clang>:
-Wno-unknown-cuda-version
-Xclang=-fcuda-allow-variadic-functions
-D_GLIBCXX_USE_TBB_PAR_BACKEND=0
-include stdexec/__detail/__force_include.hpp>
)
target_compile_definitions(
stdexec_executable_flags INTERFACE
$<$<NOT:$<AND:$<CXX_COMPILER_ID:NVHPC>,$<COMPILE_LANGUAGE:CXX>>>:STDEXEC_ENABLE_EXTRA_TYPE_CHECKING>)
# Support target for examples and tests
add_library(nvexec_executable_flags INTERFACE)
target_compile_options(nvexec_executable_flags INTERFACE
$<$<AND:$<CXX_COMPILER_ID:NVHPC>,$<COMPILE_LANGUAGE:CXX>>:-gpu=nomanaged>)
target_link_options(nvexec_executable_flags INTERFACE
$<$<AND:$<CXX_COMPILER_ID:NVHPC>,$<COMPILE_LANGUAGE:CXX>>:-gpu=nomanaged>)
# Set up nvexec library
option(STDEXEC_ENABLE_CUDA "Enable CUDA targets for non-nvc++ compilers" OFF)
if(CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC")
set(STDEXEC_ENABLE_CUDA ON)
# Unset these if using nvc++
disable_compiler(LANG CUDA)
endif()
if(STDEXEC_ENABLE_CUDA)
file(GLOB_RECURSE nvexec_sources include/nvexec/*.cuh)
add_library(nvexec INTERFACE ${nvexec_sources})
list(APPEND stdexec_export_targets nvexec)
add_library(STDEXEC::nvexec ALIAS nvexec)
target_compile_features(nvexec INTERFACE cuda_std_20)
target_link_libraries(nvexec INTERFACE STDEXEC::stdexec)
target_compile_options(nvexec INTERFACE
$<$<AND:$<CXX_COMPILER_ID:NVHPC>,$<COMPILE_LANGUAGE:CXX>>:-stdpar -gpu=cc${CMAKE_CUDA_ARCHITECTURES}>)
target_link_options(nvexec INTERFACE
$<$<AND:$<CXX_COMPILER_ID:NVHPC>,$<COMPILE_LANGUAGE:CXX>>:-stdpar -gpu=cc${CMAKE_CUDA_ARCHITECTURES}>)
if(NOT (CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC"))
include(rapids-cuda)
# Needs to run before `enable_language(CUDA)`
rapids_cuda_init_architectures(STDEXEC)
enable_language(CUDA)
# Since stdexec only enables CUDA optionally we need to manually include
# the file that rapids_cuda_init_architectures relies on `project` calling
if(CMAKE_PROJECT_STDEXEC_INCLUDE)
include("${CMAKE_PROJECT_STDEXEC_INCLUDE}")
endif()
# Must come after enable_language(CUDA)
# Use `-isystem <path>` instead of `-isystem=<path>`
# because the former works with clangd intellisense
set(CMAKE_INCLUDE_SYSTEM_FLAG_CUDA "-isystem ")
set_source_files_properties(${nvexec_sources} PROPERTIES LANGUAGE CUDA)
include(rapids-find)
rapids_find_package(
CUDAToolkit REQUIRED
BUILD_EXPORT_SET stdexec-exports
INSTALL_EXPORT_SET stdexec-exports
)
target_link_libraries(nvexec INTERFACE CUDA::cudart)
include(${rapids-cmake-dir}/cpm/cccl.cmake)
rapids_cpm_cccl(
BUILD_EXPORT_SET stdexec-exports
INSTALL_EXPORT_SET stdexec-exports
SYSTEM TRUE)
target_link_libraries(stdexec INTERFACE CCCL::CCCL)
endif ()
endif ()
option(STDEXEC_ENABLE_TBB "Enable TBB targets" OFF)
if (STDEXEC_ENABLE_TBB)
include(rapids-find)
rapids_find_package(
TBB REQUIRED
BUILD_EXPORT_SET stdexec-exports
INSTALL_EXPORT_SET stdexec-exports
)
file(GLOB_RECURSE tbbexec_sources include/tbbexec/*.hpp)
add_library(tbbexec INTERFACE ${tbbexec_sources})
list(APPEND stdexec_export_targets tbbexec)
add_library(STDEXEC::tbbexec ALIAS tbbexec)
target_link_libraries(tbbexec
INTERFACE
STDEXEC::stdexec
TBB::tbb
)
endif()
include(CheckIncludeFileCXX)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
CHECK_INCLUDE_FILE_CXX("dispatch/dispatch.h" STDEXEC_FOUND_LIBDISPATCH)
option(STDEXEC_ENABLE_LIBDISPATCH "Enable the tests for the Grand Central Dispatch scheduler" ${STDEXEC_FOUND_LIBDISPATCH})
endif()
option (STDEXEC_ENABLE_NUMA "Enable NUMA affinity for static_thread_pool" OFF)
if (STDEXEC_ENABLE_NUMA)
find_package(numa REQUIRED)
target_link_libraries(stdexec INTERFACE numa::numa)
target_compile_definitions(stdexec INTERFACE STDEXEC_ENABLE_NUMA)
endif()
set(SYSTEM_CONTEXT_SOURCES src/system_context/system_context.cpp)
add_library(system_context STATIC ${SYSTEM_CONTEXT_SOURCES})
target_include_directories(system_context PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_compile_features(system_context PUBLIC cxx_std_20)
set_target_properties(system_context PROPERTIES
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF)
target_compile_options(system_context PUBLIC
$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/Zc:__cplusplus /Zc:preprocessor>
)
add_library(STDEXEC::system_context ALIAS system_context)
if(CMAKE_CROSSCOMPILING)
CHECK_INCLUDE_FILE_CXX("linux/io_uring.h" STDEXEC_FOUND_IO_URING)
else()
include(CheckCXXSourceRuns)
CHECK_CXX_SOURCE_RUNS(
"
#include <linux/io_uring.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <cstdlib>
int main()
{
io_uring_params a = {};
return syscall(__NR_io_uring_setup, 1, &a) != -1
? EXIT_SUCCESS
: EXIT_FAILURE;
}
"
STDEXEC_FOUND_IO_URING)
endif()
option(STDEXEC_ENABLE_IO_URING_TESTS "Enable io_uring tests" ${STDEXEC_FOUND_IO_URING})
option(STDEXEC_BUILD_DOCS "Build stdexec documentation" OFF)
option(STDEXEC_BUILD_EXAMPLES "Build stdexec examples" ON)
# Configure documentation
if(STDEXEC_BUILD_DOCS)
add_subdirectory(docs)
endif()
# Configure test executables
if(BUILD_TESTING)
add_subdirectory(test)
endif()
# Configure example executables
if(STDEXEC_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
##############################################################################
# Install targets ------------------------------------------------------------
include(CPack)
install(TARGETS stdexec system_context
DESTINATION ${CMAKE_INSTALL_LIBDIR}
EXPORT stdexec-exports)
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/include/stdexec_version_config.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
##############################################################################
# Install exports ------------------------------------------------------------
set(code_string "")
# Install side of the export set
rapids_export(
INSTALL ${stdexec_export_targets}
EXPORT_SET stdexec-exports
GLOBAL_TARGETS ${stdexec_export_targets}
NAMESPACE STDEXEC::
FINAL_CODE_BLOCK code_string
)
# Build side of the export set so a user can use the build dir as a CMake package root
rapids_export(
BUILD ${stdexec_export_targets}
EXPORT_SET stdexec-exports
GLOBAL_TARGETS ${stdexec_export_targets}
NAMESPACE STDEXEC::
FINAL_CODE_BLOCK code_string
)