-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
447 lines (349 loc) · 14.9 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
#[[
© 2024 AO Kaspersky Lab
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
cmake_minimum_required(VERSION 3.25)
include_guard(GLOBAL)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(CMakeDependentOption)
include(third-party)
include(version)
knp_get_version()
if(NOT KNP_VERSION)
message(FATAL_ERROR "Kaspersky Neuromorphic Platform version is mandatory for build, but it cannot be determined.")
endif()
enable_language(CXX)
if (POLICY CMP0091)
# Enable MSVS library selection using property.
cmake_policy(SET CMP0091 NEW)
endif()
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.30")
# Suppress Boost warning.
cmake_policy(SET CMP0167 OLD)
endif()
project(knp VERSION "${KNP_VERSION}"
DESCRIPTION "Kaspersky Neuromorphic Platform"
HOMEPAGE_URL "https://neuro.kaspersky.ru/neyromorfnye-tekhnologii/")
set(KNP_BOOST_MIN_VERSION "1.74.0")
set(KNP_ROOT_DIR "${PROJECT_SOURCE_DIR}" CACHE STRING "Kaspersky Neuromorphic Platform root directory")
if (MSVC)
add_compile_options(/EHsc /MP /MDd)
# add_link_options(/LTCG:INCREMENTAL) # /NODEFAULTLIB:LIBCMTD
add_compile_definitions(_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING=1 _SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS=1)
endif()
foreach (boost_ver RANGE 81 89)
list(APPEND Boost_ADDITIONAL_VERSIONS "1.${boost_ver}")
endforeach()
if (NOT Boost_ROOT)
if (DEFINED ENV{Boost_ROOT})
set(Boost_ROOT "$ENV{Boost_ROOT}")
elseif(DEFINED ENV{BOOST_ROOT})
set(Boost_ROOT "$ENV{BOOST_ROOT}")
endif()
endif()
if (Boost_ROOT) # WIN32?
# WARNING: Do not change variable case.
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_ALL_DYN_LINK OFF)
if (NOT WIN32)
set(Boost_USE_STATIC_RUNTIME ON)
endif()
# Boost detection setup.
if(NOT BOOST_INCLUDE_DIR)
set(BOOST_INCLUDE_DIR "${BOOST_ROOT}")
endif()
if (NOT BOOST_LIBRARYDIR)
if(EXISTS "${Boost_ROOT}/stage/lib")
set(BOOST_LIBRARYDIR "${Boost_ROOT}/stage/lib")
elseif(EXISTS "${Boost_ROOT}/stage")
set(BOOST_LIBRARYDIR "${Boost_ROOT}/stage")
else()
file(GLOB _BOOST_LIB_DIRS LIST_DIRECTORIES true "${Boost_ROOT}/lib*-*-*")
list(GET _BOOST_LIB_DIRS 0 BOOST_LIBRARYDIR)
# set(Boost_LIB_PREFIX "")
endif()
endif()
message(STATUS "Boost library directory: ${BOOST_LIBRARYDIR}.")
endif()
# set(Boost_DEBUG ON)
find_package(Boost ${KNP_BOOST_MIN_VERSION} REQUIRED)
if (MSVC)
message(STATUS "Adding \"${BOOST_LIBRARYDIR}\" to LIBPATH")
add_link_options("/LIBPATH:${BOOST_LIBRARYDIR}")
endif()
#
# Kaspersky Neuromorphic Platform build option set.
#
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(KNP_BUILD_AUTONOMOUS TRUE)
else()
# Build is not from source directory, it is possible to specify it via add_subdirectory().
set(KNP_BUILD_AUTONOMOUS FALSE)
endif()
if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
set(KNP_ENABLE_AVX_DEFAULT ON)
endif()
else()
set(KNP_ENABLE_AVX_DEFAULT OFF)
endif()
if (KNP_BUILD_AUTONOMOUS OR KNP_MAINTAINER_BUILD)
find_package(Doxygen OPTIONAL_COMPONENTS dot)
if(NOT DOXYGEN_FOUND)
message(WARNING "Doxygen was not found. Documentation build will be disabled by default.")
endif()
endif()
find_program(_STUBGEN stubgen NO_CACHE)
if ("${_STUBGEN}" STREQUAL "_STUBGEN-NOTFOUND")
message(WARNING "MyPy stubgen was not found. Please install MyPy (see requirements.txt). Python framework build will be disabled.")
set(KNP_PYTHON_FRAMEWORK_BUILD_DEFAULT OFF)
else()
set(KNP_PYTHON_FRAMEWORK_BUILD_DEFAULT ON)
endif()
cmake_dependent_option(KNP_BUILD_DOCUMENTATION "Build doxygen auto documentation" ${KNP_BUILD_AUTONOMOUS} "DOXYGEN_FOUND" OFF)
option(KNP_BUILD_EXAMPLES "Build usage examples" ${KNP_BUILD_AUTONOMOUS})
option(KNP_BUILD_TESTS "Build tests" ${KNP_BUILD_AUTONOMOUS})
option(KNP_ENABLE_AVX "Enable AVX and other CPU-specific extensions in the release build" ${KNP_ENABLE_AVX_DEFAULT})
option(KNP_ENABLE_COVERAGE "Enable coverage checking" OFF)
option(KNP_IPO_ENABLED "Enable interprocedural optimization" ON)
option(KNP_INSTALL "Enable Kaspersky Neuromorphic Platform installation" ON)
option(KNP_MAINTAINER_BUILD "Build for maintainer, but not for the development purposes" OFF)
cmake_dependent_option(KNP_PYTHON_FRAMEWORK_BUILD "Build Kaspersky Neuromorphic Platform Python framework" ON "KNP_PYTHON_FRAMEWORK_BUILD_DEFAULT" OFF)
cmake_dependent_option(KNP_PYTHON_BUILD_WHEEL "Build WHL package for the Python framework" ${KNP_MAINTAINER_BUILD} "KNP_PYTHON_FRAMEWORK_BUILD" OFF)
mark_as_advanced(KNP_MAINTAINER_BUILD)
mark_as_advanced(KNP_ENABLE_COVERAGE)
mark_as_advanced(KNP_ENABLE_AVX)
mark_as_advanced(KNP_IPO_ENABLED)
message(STATUS "KNP_BUILD_DOCUMENTATION = ${KNP_BUILD_DOCUMENTATION}")
message(STATUS "KNP_BUILD_EXAMPLES = ${KNP_BUILD_EXAMPLES}")
message(STATUS "KNP_BUILD_TESTS = ${KNP_BUILD_TESTS}")
message(STATUS "KNP_ENABLE_AVX = ${KNP_ENABLE_AVX}")
message(STATUS "KNP_ENABLE_COVERAGE = ${KNP_ENABLE_COVERAGE}")
message(STATUS "KNP_IPO_ENABLED = ${KNP_IPO_ENABLED}")
message(STATUS "KNP_INSTALL = ${KNP_INSTALL}")
message(STATUS "KNP_MAINTAINER_BUILD = ${KNP_MAINTAINER_BUILD}")
message(STATUS "KNP_PYTHON_FRAMEWORK_BUILD = ${KNP_PYTHON_FRAMEWORK_BUILD}")
message(STATUS "KNP_PYTHON_BUILD_WHEEL = ${KNP_PYTHON_BUILD_WHEEL}")
if (KNP_ENABLE_AVX)
message(STATUS "AVX enabled.")
message(STATUS "Setting release optimization flags...")
# -pipe
set(CMAKE_C_FLAGS_RELEASE "-march=native -mtune=native -mno-vzeroupper -Ofast -funroll-loops -fomit-frame-pointer -finline")
# if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fopt-info-vec-optimized")
# endif()
set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
add_compile_options(-include x86intrin.h)
# -include bits/stdc++.h
endif()
if (NOT KNP_MAINTAINER_BUILD AND KNP_BUILD_AUTONOMOUS)
execute_process(COMMAND pre-commit install
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
if(ret AND NOT ret EQUAL 0)
message(FATAL_ERROR "Cannot install pre-commit hooks.")
endif()
execute_process(COMMAND pre-commit install -t commit-msg
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
endif()
if (KNP_BUILD_TESTS)
add_compile_definitions(SPDLOG_ACTIVE_LEVEL=0)
endif()
#
# Common parameters.
#
set(ENABLE_FAST_MATH ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Required for linters.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(knp-functions)
include(print-variables)
#
# Build third-party.
#
if (KNP_BUILD_AUTONOMOUS)
if (NOT CPM_SOURCE_CACHE_DEFAULT)
set(CPM_SOURCE_CACHE_DEFAULT "${CMAKE_CURRENT_SOURCE_DIR}/third-party")
endif()
if (NOT CPM_SOURCE_CACHE)
message(STATUS "Autonomous build. Setting source cached directory to \"${CPM_SOURCE_CACHE_DEFAULT}\".")
set(CPM_SOURCE_CACHE "${CPM_SOURCE_CACHE_DEFAULT}")
endif()
endif()
# Make cache variables for installation destinations.
include(GNUInstallDirs)
if (MSVC AND CMAKE_GENERATOR STREQUAL "Ninja")
set(ZMQ_ENABLE_PRECOMPS OFF)
else()
set(ZMQ_ENABLE_PRECOMPS ON)
endif()
add_third_party("gh:gabime/[email protected]"
OPTIONS
"SPDLOG_BUILD_PIC ON"
"SPDLOG_BUILD_SHARED OFF")
if (MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif()
add_third_party(NAME "libzmq"
GITHUB_REPOSITORY "zeromq/libzmq"
VERSION "4.3.5"
FIND_PACKAGE_ARGUMENTS "NAMES ZeroMQ libzmq zmq zmq5 libzmq5"
OPTIONS
"WITH_DOCS OFF"
"BUILD_TESTS OFF"
"ENABLE_CPACK OFF"
"ENABLE_PRECOMPILED ${ZMQ_ENABLE_PRECOMPS}")
add_third_party("gh:google/[email protected]"
OPTIONS
"FLATBUFFERS_BUILD_TESTS OFF"
"FLATBUFFERS_BUILD_CPP17 ON"
"FLATBUFFERS_INSTALL OFF")
macro(install)
# Special hack needs to prevent redundant packages generation by third-party.
if (CMAKE_CURRENT_SOURCE_DIR MATCHES "${CPM_SOURCE_CACHE}/.*" OR CMAKE_CURRENT_SOURCE_DIR MATCHES "${CPM_SOURCE_CACHE_DEFAULT}/.*")
message(STATUS "Third-party installation will be skipped: ${CMAKE_CURRENT_SOURCE_DIR}")
return()
endif()
_install(${ARGV})
endmacro()
#
# LibHDF5 and its dependencies.
#
add_third_party("https://gitlab.dkrz.de/k202009/[email protected]")
#add_third_party("gh:erdc/szip")
add_third_party("gh:HDFGroup/hdf5#hdf5_1.14.4"
GIT_SHALLOW ON
FIND_PACKAGE_ARGUMENTS "NAMES hdf5 libhdf5 hdf5-static"
OPTIONS
"HDF5_EXTERNALLY_CONFIGURED ON"
"HDF5_BUILD_DOC OFF"
"HDF5_NO_PACKAGES ON"
"HDF5_BUILD_SHARED_LIBS ON"
"HDF5_BUILD_TOOLS OFF"
"HDF5_BUILD_UTILS OFF"
"HDF5_VOL_ALLOW_EXTERNAL YES") # "HDF5_ALLOW_EXTERNAL_SUPPORT GIT" SZIP_USE_EXTERNAL
add_third_party("gh:BlueBrain/[email protected]"
GIT_SHALLOW ON
OPTIONS
"HIGHFIVE_FIND_HDF5 OFF"
"HIGHFIVE_EXAMPLES OFF"
"HIGHFIVE_BUILD_DOCS OFF"
"HIGHFIVE_USE_BOOST OFF"
"HIGHFIVE_UNIT_TESTS OFF"
"HDF5_C_LIBRARIES ${HDF5_LIBRARIES_TO_EXPORT}")
# End of LibHDF5.
add_third_party("gh:p-ranav/[email protected]"
OPTIONS
"CSV2_BUILD_TESTS OFF"
"CSV2_TEST OFF"
"CSV2_SAMPLES OFF")
if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "(x86.*)|(X86.*)|(amd64)|(AMD64)")
add_third_party("gh:intel/pcm"
GIT_TAG 2f9b0c2
OPTIONS
"NO_STATIC_MSVC_RUNTIME_LIBRARY ON"
"NO_ASAN ON")
include_directories("${CPM_PACKAGE_pcm_SOURCE_DIR}/src")
endif()
add_third_party("gh:zeromq/[email protected]"
OPTIONS
"CPPZMQ_BUILD_TESTS OFF")
add_third_party("gh:Tencent/rapidjson#ebd87cb"
OPTIONS
"RAPIDJSON_BUILD_DOC OFF"
"RAPIDJSON_BUILD_ASAN OFF"
"RAPIDJSON_BUILD_UBSAN OFF"
"RAPIDJSON_BUILD_CXX17 ON"
"RAPIDJSON_BUILD_EXAMPLES OFF"
"RAPIDJSON_BUILD_TESTS OFF"
"RAPIDJSON_HAS_STDSTRING ON")
include_directories("${CPM_PACKAGE_rapidjson_SOURCE_DIR}/include")
if (KNP_BUILD_TESTS)
add_compile_definitions(SPDLOG_ACTIVE_LEVEL=0)
add_third_party("gh:google/[email protected]"
OPTIONS
"INSTALL_GMOCK OFF"
"INSTALL_GTEST OFF")
endif()
#if (CPM_SOURCE_CACHE)
# file(GLOB THIRD_PARTY_INCLUDES LIST_DIRECTORIES true "${CPM_SOURCE_CACHE}/**/include")
# include_directories("${CPM_SOURCE_CACHE}" ${THIRD_PARTY_INCLUDES})
#endif()
if (MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS FALSE)
endif()
#
# Build Kaspersky Neuromorphic Platform.
#
set(CMAKE_TIDY_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/knp/.clang-tidy" CACHE PATH "Clang-tidy config file")
add_subdirectory("knp")
if (KNP_BUILD_DOCUMENTATION)
add_subdirectory(doc)
endif()
if (KNP_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
#
# Packaging.
#
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}" CACHE STRING "The resulting package name")
#SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}.${CMAKE_SYSTEM_PROCESSOR}")
#set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
set(CPACK_PACKAGE_ICON "packaging/neuromorphic-platform.svg")
set(CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${CMAKE_PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${CMAKE_PROJECT_VERSION_PATCH})
set(CPACK_PACKAGE_VENDOR "AO Kaspersky Lab")
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CMAKE_PROJECT_DESCRIPTION}"
CACHE STRING "Package description for the package metadata")
set(CPACK_PACKAGE_DESCRIPTION "Kaspersky Neuromorphic Platform - spiking networks simulator")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}")
set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_BINARY_DIR}/_packages")
# https://unix.stackexchange.com/a/11552/254512
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/packaging/LICENSE.txt")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CMAKE_INSTALL_PREFIX}")
set(CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
# On Linux, grouping must be ignored: one component corresponds to one package.
set(CPACK_COMPONENTS_GROUPING IGNORE)
#
# Deb package.
#
set(CPACK_DEB_PACKAGE_COMPONENT ON)
set(CPACK_DEB_COMPONENT_INSTALL ON)
#set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP)
set(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS ON)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Artiom N.")
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}")
set(CPACK_DEBIAN_PACKAGE_SECTION "science")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS OFF)
set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS OFF)
#
# RPM package.
#
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_RPM_PACKAGE_RELOCATABLE ON)
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_RPM_PACKAGE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
set(CPACK_RPM_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}")
set(CPACK_RPM_PACKAGE_GROUP "science")
include (CPack)