forked from alpaka-group/alpaka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
205 lines (160 loc) · 9.23 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
#
# Copyright 2023 Benjamin Worpitz, Jan Stephan, Bernhard Manfred Gruber
#
# This file is part of alpaka.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
################################################################################
# Required CMake version
cmake_minimum_required(VERSION 3.18)
cmake_policy(SET CMP0091 NEW)
include(CMakePrintHelpers)
#-------------------------------------------------------------------------------
# Find alpaka version.
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/include/alpaka/version.hpp" alpaka_VERSION_MAJOR_HPP REGEX "#define ALPAKA_VERSION_MAJOR ")
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/include/alpaka/version.hpp" alpaka_VERSION_MINOR_HPP REGEX "#define ALPAKA_VERSION_MINOR ")
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/include/alpaka/version.hpp" alpaka_VERSION_PATCH_HPP REGEX "#define ALPAKA_VERSION_PATCH ")
string(REGEX MATCH "([0-9]+)" alpaka_VERSION_MAJOR ${alpaka_VERSION_MAJOR_HPP})
string(REGEX MATCH "([0-9]+)" alpaka_VERSION_MINOR ${alpaka_VERSION_MINOR_HPP})
string(REGEX MATCH "([0-9]+)" alpaka_VERSION_PATCH ${alpaka_VERSION_PATCH_HPP})
set(PACKAGE_VERSION "${alpaka_VERSION_MAJOR}.${alpaka_VERSION_MINOR}.${alpaka_VERSION_PATCH}")
project(alpaka VERSION ${alpaka_VERSION_MAJOR}.${alpaka_VERSION_MINOR}.${alpaka_VERSION_PATCH}
DESCRIPTION "The alpaka library is a header-only C++17 abstraction library for accelerator development."
HOMEPAGE_URL "https://github.com/alpaka-group/alpaka"
LANGUAGES CXX)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
################################################################################
# Options and Variants
option(alpaka_BUILD_EXAMPLES "Build the examples" OFF)
# Enable the test infrastructure only if alpaka is the top-level project
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
option(BUILD_TESTING "Build the testing tree." OFF)
include(CTest)
endif()
option(alpaka_INSTALL_TEST_HEADER "Install headers of the namespace alpaka::test. Attention, headers are not designed for production code, see documentation." OFF)
include(CMakeDependentOption)
cmake_dependent_option(alpaka_CHECK_HEADERS "Check all alpaka headers as part of the tests whether they can be compiled standalone." OFF BUILD_TESTING OFF)
cmake_dependent_option(alpaka_USE_INTERNAL_CATCH2 "Use internally shipped Catch2" ON BUILD_TESTING OFF)
################################################################################
# Internal variables.
# Set found to true initially and set it to false if a required dependency is missing.
set(_alpaka_FOUND TRUE)
# This file's directory.
set(_alpaka_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
# Normalize the path (e.g. remove ../)
get_filename_component(_alpaka_ROOT_DIR ${_alpaka_ROOT_DIR} ABSOLUTE)
# Compiler feature tests.
set(_alpaka_FEATURE_TESTS_DIR "${_alpaka_ROOT_DIR}/cmake/tests")
# Add common functions.
set(_alpaka_COMMON_FILE "${_alpaka_ROOT_DIR}/cmake/common.cmake")
include(${_alpaka_COMMON_FILE})
# Add alpaka_ADD_EXECUTABLE function.
set(_alpaka_ADD_EXECUTABLE_FILE "${_alpaka_ROOT_DIR}/cmake/addExecutable.cmake")
include(${_alpaka_ADD_EXECUTABLE_FILE})
# Add alpaka_ADD_LIBRARY function.
set(_alpaka_ADD_LIBRARY_FILE "${_alpaka_ROOT_DIR}/cmake/addLibrary.cmake")
include(${_alpaka_ADD_LIBRARY_FILE})
# Set include directories
set(_alpaka_INCLUDE_DIRECTORY "${_alpaka_ROOT_DIR}/include")
set(_alpaka_SUFFIXED_INCLUDE_DIR "${_alpaka_INCLUDE_DIRECTORY}/alpaka")
# the sequential accelerator is required for the tests and examples
if(alpaka_BUILD_EXAMPLES OR BUILD_TESTING)
if (NOT (alpaka_ACC_GPU_CUDA_ONLY_MODE OR alpaka_ACC_GPU_HIP_ONLY_MODE))
if (NOT DEFINED alpaka_ACC_CPU_B_SEQ_T_SEQ_ENABLE)
option(alpaka_ACC_CPU_B_SEQ_T_SEQ_ENABLE "enable alpaka serial accelerator" ON)
elseif(NOT alpaka_ACC_CPU_B_SEQ_T_SEQ_ENABLE)
set(alpaka_ACC_CPU_B_SEQ_T_SEQ_ENABLE ON CACHE BOOL "enable alpaka serial accelerator" FORCE)
endif()
else() #CUDA or HIP-only mode
message(WARNING "CUDA/HIP-only mode enabled: not enabling alpaka serial accelerator (required for examples and tests)")
endif()
endif()
include(${_alpaka_ROOT_DIR}/cmake/alpakaCommon.cmake)
# Add all the source and include files in all recursive subdirectories and group them accordingly.
append_recursive_files_add_to_src_group("${_alpaka_SUFFIXED_INCLUDE_DIR}" "${_alpaka_SUFFIXED_INCLUDE_DIR}" "hpp" _alpaka_FILES_HEADER)
append_recursive_files_add_to_src_group("${_alpaka_SUFFIXED_INCLUDE_DIR}" "${_alpaka_SUFFIXED_INCLUDE_DIR}" "h" _alpaka_FILES_HEADER)
# remove headers of the folder alpaka/test, if alpaka_INSTALL_TEST_HEADER is disabled
if(NOT alpaka_INSTALL_TEST_HEADER)
list(FILTER _alpaka_FILES_HEADER EXCLUDE REGEX "(.*)/alpaka/test/(.*)")
endif()
append_recursive_files_add_to_src_group("${_alpaka_ROOT_DIR}/script" "${_alpaka_ROOT_DIR}" "sh" _alpaka_FILES_SCRIPT)
set_source_files_properties(${_alpaka_FILES_SCRIPT} PROPERTIES HEADER_FILE_ONLY TRUE)
append_recursive_files_add_to_src_group("${_alpaka_ROOT_DIR}/cmake" "${_alpaka_ROOT_DIR}" "cmake" _alpaka_FILES_CMAKE)
list(APPEND _alpaka_FILES_CMAKE "${_alpaka_ROOT_DIR}/cmake/alpakaConfig.cmake.in" "${_alpaka_ROOT_DIR}/CMakeLists.txt")
set_source_files_properties(${_alpaka_FILES_CMAKE} PROPERTIES HEADER_FILE_ONLY TRUE)
append_recursive_files_add_to_src_group("${_alpaka_ROOT_DIR}/docs/markdown" "${_alpaka_ROOT_DIR}" "md" _alpaka_FILES_DOC)
set_source_files_properties(${_alpaka_FILES_DOC} PROPERTIES HEADER_FILE_ONLY TRUE)
append_recursive_files_add_to_src_group("${_alpaka_ROOT_DIR}/.github" "${_alpaka_ROOT_DIR}" "yml" _alpaka_FILES_OTHER)
list(APPEND _alpaka_FILES_OTHER "${_alpaka_ROOT_DIR}/.clang-format" "${_alpaka_ROOT_DIR}/.gitignore" "${_alpaka_ROOT_DIR}/.zenodo.json" "${_alpaka_ROOT_DIR}/LICENSE" "${_alpaka_ROOT_DIR}/README.md")
set_source_files_properties(${_alpaka_FILES_OTHER} PROPERTIES HEADER_FILE_ONLY TRUE)
if(TARGET alpaka)
# HACK: Workaround for the limitation that files added to INTERFACE targets (target_sources) can not be marked as PUBLIC or PRIVATE but only as INTERFACE.
# Therefore those files will be added to projects "linking" to the INTERFACE library, but are not added to the project itself within an IDE.
add_custom_target("alpakaIde"
SOURCES ${_alpaka_FILES_HEADER} ${_alpaka_FILES_SCRIPT} ${_alpaka_FILES_CMAKE} ${_alpaka_FILES_DOC} ${_alpaka_FILES_OTHER})
endif()
################################################################################
# Export NVCC/HIPCC flags to parent scope if alpaka is used as a CMake
# subdirectory.
#
# These flags are set in cmake/alpakaCommon.cmake but are visible in this scope
# since alpakaCommon.cmake is included.
if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
if(alpaka_ACC_GPU_HIP_ENABLE)
# export HIPCC flags to parent scope in case alpaka is another project's subdirectory
set(HIP_HIPCC_FLAGS ${HIP_HIPCC_FLAGS} PARENT_SCOPE)
set(HIP_NVCC_FLAGS ${HIP_NVCC_FLAGS} PARENT_SCOPE)
set(HIP_VERBOSE_BUILD ${HIP_VERBOSE_BUILD} PARENT_SCOPE)
endif()
endif()
################################################################################
# Add subdirectories
add_subdirectory(thirdParty)
if(alpaka_BUILD_EXAMPLES)
add_subdirectory("example/")
endif()
# Only build the tests if alpaka is the top-level project and BUILD_TESTING is ON
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
add_subdirectory("test/")
endif()
################################################################################
# Installation.
# Do not install if alpaka is used as a CMake subdirectory
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
set(_alpaka_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/alpaka")
install(TARGETS alpaka
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
write_basic_package_version_file(
"alpakaConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
configure_package_config_file(
"${_alpaka_ROOT_DIR}/cmake/alpakaConfig.cmake.in"
"${PROJECT_BINARY_DIR}/alpakaConfig.cmake"
INSTALL_DESTINATION "${_alpaka_INSTALL_CMAKEDIR}")
install(FILES "${PROJECT_BINARY_DIR}/alpakaConfig.cmake"
"${PROJECT_BINARY_DIR}/alpakaConfigVersion.cmake"
DESTINATION "${_alpaka_INSTALL_CMAKEDIR}")
if(alpaka_INSTALL_TEST_HEADER)
install(DIRECTORY "${_alpaka_SUFFIXED_INCLUDE_DIR}"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
else()
install(DIRECTORY "${_alpaka_SUFFIXED_INCLUDE_DIR}"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
PATTERN "test" EXCLUDE)
endif()
install(FILES "${_alpaka_ROOT_DIR}/cmake/addExecutable.cmake"
"${_alpaka_ROOT_DIR}/cmake/addLibrary.cmake"
"${_alpaka_ROOT_DIR}/cmake/alpakaCommon.cmake"
"${_alpaka_ROOT_DIR}/cmake/common.cmake"
DESTINATION "${_alpaka_INSTALL_CMAKEDIR}")
install(DIRECTORY "${_alpaka_ROOT_DIR}/cmake/tests"
DESTINATION "${_alpaka_INSTALL_CMAKEDIR}")
endif()