forked from qdrvm/kagome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
180 lines (152 loc) · 6.55 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
cmake_minimum_required(VERSION 3.12)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
set(
CMAKE_TOOLCHAIN_FILE
"${CMAKE_SOURCE_DIR}/cmake/toolchain/cxx17.cmake"
CACHE
FILEPATH
"Default toolchain"
)
include("cmake/Hunter/init.cmake")
project(kagome C CXX)
include(cmake/print.cmake)
print("C flags: ${CMAKE_C_FLAGS}")
print("CXX flags: ${CMAKE_CXX_FLAGS}")
print("Using CMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads)
link_libraries(Threads::Threads)
if(THREADS_HAVE_PTHREAD_ARG)
link_libraries(pthread)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(TESTING "Build and run test suite" ON )
option(CLANG_FORMAT "Enable clang-format target" ON )
option(CLANG_TIDY "Enable clang-tidy checks during compilation" OFF)
option(COVERAGE "Enable generation of coverage info" OFF)
option(EMBEDDINGS "Embed developers assets" ON )
option(PROFILING "Enable internal profiling instruments" OFF)
# sanitizers will be enabled only for Kagome, and will be disabled for dependencies
option(ASAN "Enable address sanitizer" OFF)
option(LSAN "Enable leak sanitizer" OFF)
option(MSAN "Enable memory sanitizer" OFF)
option(TSAN "Enable thread sanitizer" OFF)
option(UBSAN "Enable UB sanitizer" OFF)
set(RECOMMENDED_CLANG_FORMAT_VERSION 12)
include(CheckCXXCompilerFlag)
include(cmake/dependencies.cmake)
include(cmake/functions.cmake)
include(cmake/san.cmake)
## setup compilation flags
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(AppleClang|Clang|GNU)$")
# enable those flags
add_flag(-Wall)
add_flag(-Wextra)
add_flag(-Woverloaded-virtual) # warn if you overload (not override) a virtual function
add_flag(-Wformat=2) # warn on security issues around functions that format output (ie printf)
add_flag(-Wmisleading-indentation) # (only in GCC >= 6.0) warn if indentation implies blocks where blocks do not exist
add_flag(-Wduplicated-cond) # (only in GCC >= 6.0) warn if if / else chain has duplicated conditions
add_flag(-Wduplicated-branches) # (only in GCC >= 7.0) warn if if / else branches have duplicated code
add_flag(-Wnull-dereference) # (only in GCC >= 6.0) warn if a null dereference is detected
add_flag(-Wdouble-promotion) # (GCC >= 4.6, Clang >= 3.8) warn if float is implicit promoted to double
add_flag(-Wsign-compare)
add_flag(-Wtype-limits) # size_t - size_t >= 0 -> always true
# disable those flags
add_flag(-Wno-unused-command-line-argument) # clang: warning: argument unused during compilation: '--coverage' [-Wunused-command-line-argument]
add_flag(-Wno-unused-parameter) # prints too many useless warnings
add_flag(-Wno-format-nonliteral) # prints way too many warnings from spdlog
add_flag(-Wno-gnu-zero-variadic-macro-arguments) # https://stackoverflow.com/questions/21266380/is-the-gnu-zero-variadic-macro-arguments-safe-to-ignore
if (
(("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(AppleClang|Clang)$") AND (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "12.0"))
OR
(("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(GNU)$") AND (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "9.0"))
)
# use new options format for clang >= 12 and gnu >= 9
add_flag(-Werror=unused-lambda-capture) # error if lambda capture is unused
add_flag(-Werror=return-type) # warning: control reaches end of non-void function [-Wreturn-type]
add_flag(-Werror=non-virtual-dtor) # warn the user if a class with virtual functions has a non-virtual destructor. This helps catch hard to track down memory errors
add_flag(-Werror=sign-compare) # warn the user if they compare a signed and unsigned numbers
add_flag(-Werror=reorder) # field '$1' will be initialized after field '$2'
add_flag(-Werror=mismatched-tags) # warning: class '$1' was previously declared as struct
else()
# promote to errors
add_flag(-Werror-unused-lambda-capture) # error if lambda capture is unused
add_flag(-Werror-return-type) # warning: control reaches end of non-void function [-Wreturn-type]
add_flag(-Werror-non-virtual-dtor) # warn the user if a class with virtual functions has a non-virtual destructor. This helps catch hard to track down memory errors
add_flag(-Werror-sign-compare) # warn the user if they compare a signed and unsigned numbers
add_flag(-Werror-reorder) # field '$1' will be initialized after field '$2'
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# using Visual Studio C++
# TODO(warchant): add flags https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md#msvc
endif()
if(COVERAGE)
include(cmake/coverage.cmake)
endif()
if(CLANG_TIDY)
include(cmake/clang-tidy.cmake)
endif()
if(CLANG_FORMAT)
include(cmake/clang-format.cmake)
endif()
if(EMBEDDINGS)
add_compile_definitions(PRIVATE USE_KAGOME_EMBEDDINGS)
endif()
if (NOT DEFINED PROFILING)
if(${CMAKE_BUILD_TYPE} EQUALS "Debug")
set(PROFILING ON)
endif()
endif()
if(PROFILING)
add_compile_definitions(PRIVATE KAGOME_PROFILING)
endif()
include(GNUInstallDirs)
include(cmake/install.cmake)
include_directories(
$<INSTALL_INTERFACE:${CMAKE_INSTALL_FULL_INCLUDEDIR}/kagome>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/core>
)
add_subdirectory(core)
# TODO(Harrm): refactor to avoid manually adding each new directory
kagome_install_setup(
HEADER_DIRS
core/application
core/assets
core/blockchain
core/clock
core/common
core/consensus
core/crypto
core/filesystem
core/host_api
core/log
core/macro
core/network
core/offchain
core/outcome
core/primitives
core/runtime
core/scale
core/storage
core/subscription
)
include(CMakePackageConfigHelpers)
set(CONFIG_INCLUDE_DIRS ${CMAKE_INSTALL_FULL_INCLUDEDIR}/kagome)
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/kagomeConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/kagomeConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kagome
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/kagomeConfig.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kagome
)
export(PACKAGE kagome)
if(TESTING)
enable_testing()
add_subdirectory(test)
endif()
add_subdirectory(node)