-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
274 lines (232 loc) · 8.83 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
cmake_minimum_required(VERSION 3.13)
project(Scilib
VERSION 0.3
LANGUAGES CXX
)
################################################################################
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
################################################################################
include(GNUInstallDirs)
################################################################################
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
################################################################################
set(Scilib_STANDALONE_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(Scilib_STANDALONE_PROJECT ON)
endif()
option(Scilib_BUILD_TESTS "Build tests." ${Scilib_STANDALONE_PROJECT})
option(Scilib_BUILD_BENCH "Build benchmarks." ${Scilib_STANDALONE_PROJECT})
option(Scilib_BUILD_EXAMPLES "Build examples." ${Scilib_STANDALONE_PROJECT})
option(Scilib_CODE_COVERAGE "Enable code coverage." OFF)
################################################################################
# Set installation directory.
if (WIN32)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX $ENV{USERPROFILE} CACHE PATH "USERPROFILE" FORCE)
endif()
else()
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX $ENV{HOME} CACHE PATH "HOME" FORCE)
endif()
endif()
################################################################################
if(WIN32)
option(BUILD_SHARED_LIBS "Compile shared libraries." OFF)
else()
option(BUILD_SHARED_LIBS "Compile shared libraries." ON)
endif()
# Check if C++23 standard is available.
if("cxx_std_23" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
message(STATUS "Using C++23 standard")
set(CMAKE_CXX_STANDARD 23)
else()
if("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
message(STATUS "Using C++20 standard")
set(CMAKE_CXX_STANDARD 20)
else()
message(FATAL_ERROR "Requested Scilib_CXX_STANDARD not supported by provided C++ compiler")
endif()
endif()
option(Scilib_ENABLE_CONCEPTS "Try to enable concepts support by giving extra flags." ON)
if(Scilib_ENABLE_CONCEPTS)
if(CMAKE_CXX_STANDARD GREATER_EQUAL 20)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-fconcepts" COMPILER_SUPPORTS_FCONCEPTS)
if(COMPILER_SUPPORTS_FCONCEPTS)
message(STATUS "-- Using \"-fconcepts\" to enable concepts support")
set(Scilib_CXX_FLAGS ${CMAKE_CXX_FLAGS} -fconcepts)
else()
CHECK_CXX_COMPILER_FLAG("-fconcepts-ts" COMPILER_SUPPORTS_FCONCEPTS_TS)
if(COMPILER_SUPPORTS_FCONCEPTS)
message(STATUS "-- Using \"-fconcepts-ts\" to enable concepts support")
set(Scilib_CXX_FLAGS ${CMAKE_CXX_FLAGS} -fconcepts-ts)
endif()
endif()
endif()
endif()
# Set compiler options.
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(Scilib_CXX_FLAGS ${Scilib_CXX_FLAGS} -Wpedantic -Wall -Wshadow -Wextra -Wno-missing-braces -Werror -Wno-error=strict-overflow -Wno-error=unused-parameter -Wno-maybe-uninitialized)
set(Scilib_CXX_FLAGS_DEBUG ${Scilib_CXX_FLAGS} -g -p)
set(Scilib_CXX_FLAGS_RELEASE ${Scilib_CXX_FLAGS} -O3 -DNDEBUG)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(Scilib_CMAKE_CXX_FLAGS ${Scilib_CXX_FLAGS} -Wpedantic -Wall -Wshadow -Wextra -Wno-missing-braces -Werror -Wno-error=strict-overflow)
set(Scilib_CXX_FLAGS_DEBUG ${Scilib_CXX_FLAGS} -g)
set(Scilib_CXX_FLAGS_RELEASE ${Scilib_CXX_FLAGS} -O3 -DNDEBUG)
endif()
if(MSVC)
if (CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
set(Scilib_CXX_FLAGS ${Scilib_CXX_FLAGS} /W4 /Qstd:c++20 /EHsc)
set(Scilib_CXX_FLAGS_DEBUG ${Scilib_CXX_FLAGS} /Zi /Od /Qopenmp)
set(Scilib_CXX_FLAGS_RELEASE ${Scilib_CXX_FLAGS} /O3 /Qopenmp /DNDEBUG)
else()
set(Scilib_CXX_FLAGS ${Scilib_CXX_FLAGS} /W4 /WX)
set(Scilib_CXX_FLAGS_DEBUG ${Scilib_CXX_FLAGS} /Zi /Od)
set(Scilib_CXX_FLAGS_RELEASE ${Scilib_CXX_FLAGS} /O2 /DNDEBUG)
endif()
endif()
if (Scilib_CODE_COVERAGE)
set(Scilib_BUILD_BENCH OFF)
set(Scilib_BUILD_EXAMPLES OFF)
set(Scilib_CXX_FLAGS ${Scilib_CXX_FLAGS} -Wpedantic -Wall -Wshadow -Wextra -Wno-missing-braces -Werror -Wno-error=strict-overflow -Wno-error=unused-parameter -Wno-maybe-uninitialized)
set(Scilib_CXX_FLAGS_DEBUG ${Scilib_CXX_FLAGS} -O0 -g -fprofile-arcs -ftest-coverage --coverage)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
################################################################################
# mdspan is required.
message(STATUS "Fetch mdspan from Github")
include(FetchContent)
FetchContent_Declare(
mdspan
GIT_REPOSITORY https://github.com/kokkos/mdspan.git
GIT_TAG mdspan-0.6.0
)
FetchContent_MakeAvailable(mdspan)
if(NOT TARGET std::mdspan)
find_package(mdspan REQUIRED)
endif()
# stdBLAS is required.
message(STATUS "Fetch stdBLAS from Github")
include(FetchContent)
FetchContent_Declare(
linalg
GIT_REPOSITORY https://github.com/stigrs/stdBLAS.git
GIT_TAG main
)
FetchContent_MakeAvailable(linalg)
if(NOT TARGET std::linalg)
find_package(linalg REQUIRED)
endif()
# GSL is required.
message(STATUS "Fetch GSL from Github")
include(FetchContent)
FetchContent_Declare(
GSL
GIT_REPOSITORY https://github.com/microsoft/GSL.git
GIT_TAG v4.0.0
)
FetchContent_MakeAvailable(GSL)
if(NOT TARGET Microsoft.GSL::GSL)
find_package(Microsoft.GSL CONFIG)
endif()
# ranges-v3 is required.
message(STATUS "Fetch range-v3 from Github")
include(FetchContent)
FetchContent_Declare(
range-v3
GIT_REPOSITORY https://github.com/ericniebler/range-v3.git
GIT_TAG master
)
FetchContent_MakeAvailable(range-v3)
if(NOT TARGET range-v3)
find_package(range-v3 CONFIG)
endif()
# BLAS and LAPACKE are required.
if(DEFINED ENV{MKLROOT})
find_package(MKL)
if(MKL_FOUND)
message(STATUS "Intel MKL found")
add_definitions(${MKL_DEFINITIONS})
endif()
option(USE_MKL_ALLOCATOR OFF)
option(MKL_MEM_ALIGNMENT_VALUE "")
if(USE_MKL_ALLOCATOR)
if(MSVC)
add_definitions(/DUSE_MKL_ALLOCATOR /DMKL_ALIGN)
if(MKL_MEM_ALIGNMENT_VALUE)
add_definitions(/DMKL_MEM_ALIGNMENT=${MKL_MEM_ALIGNMENT_VALUE})
endif()
else()
add_definitions(-DUSE_MKL_ALLOCATOR -DMKL_ALIGN)
if(MKL_MEM_ALIGNMENT_VALUE)
add_definitions(-DMKL_MEM_ALIGNMENT=${MKL_MEM_ALIGNMENT_VALUE})
endif()
endif()
endif()
else()
find_package(OpenBLAS)
if(BLAS_FOUND)
MESSAGE(STATUS "OpenBLAS found")
add_definitions(${BLAS_DEFINITIONS})
endif()
endif()
################################################################################
add_library(scilib INTERFACE)
add_library(scilib::scilib ALIAS scilib)
target_link_libraries(scilib INTERFACE std::mdspan std::linalg Microsoft.GSL::GSL range-v3-meta range-v3-concepts range-v3)
target_include_directories(scilib INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${BLAS_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${LAPACKE_INCLUDE_DIRS}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
install(TARGETS scilib mdspan linalg GSL range-v3-meta range-v3-concepts range-v3
EXPORT scilibTargets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/scilib DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT scilibTargets
FILE scilibTargets.cmake
NAMESPACE scilib::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/scilib
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/scilibConfigVersion.cmake"
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/scilibConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/scilibConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/scilib
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/scilibConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/scilibConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/scilib
)
################################################################################
if(Scilib_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
if(Scilib_BUILD_BENCH)
find_package(Eigen3 3.4 QUIET)
if (NOT TARGET Eigen3::Eigen)
message(STATUS "No installed Eigen found, fetching from GitLab")
include(FetchContent)
FetchContent_Declare(
eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG master
)
FetchContent_MakeAvailable(eigen)
endif()
add_subdirectory(bench)
endif()
if(Scilib_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()