forked from category-labs/monad
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
340 lines (280 loc) · 11.2 KB
/
CMakeLists.txt
File metadata and controls
340 lines (280 loc) · 11.2 KB
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
# Copyright (C) 2025 Category Labs, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
cmake_minimum_required(VERSION 3.27)
cmake_policy(SET CMP0144 NEW) # find_package uses upper-case _ROOT variables
project(monad)
set(CATEGORY_MAIN_DIR ${PROJECT_SOURCE_DIR})
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15)
message(FATAL_ERROR "GCC version 15 or higher is required.")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19)
message(FATAL_ERROR "Clang version 19 or higher is required.")
endif()
endif()
if(BUILD_SHARED_LIBS)
# BUILD_SHARED_LIBS=ON does not automatically set -fPIC, leading to
# relocations being emitted in object files that can't be patched
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(MONAD_COMPILER_LLVM "Build llvm backend" OFF)
option(MONAD_COMPILER_COVERAGE "Build with coverage" OFF)
option(MONAD_COMPILER_TESTING "Build compiler tests" OFF)
option(MONAD_COMPILER_BENCHMARKS "Build compiler benchmarks" OFF)
option(MONAD_COMPILER_DUMP_ASM "Dump assembly files into build/asm" OFF)
option(MONAD_COMPILER_STATS "Print statistics about the compiler" OFF)
option(MONAD_COMPILER_HOT_PATH_STATS "Print statistics about the vm" OFF)
if(NOT DEFINED BUILD_SHARED_LIBS)
# If this isn't defined, evmone has the audacity to define it itself (to ON)
# whereas the ordinary default is for static libraries; if it's not specified,
# we explicitly set it to OFF, agreeing with the expected default and
# preventing evmone from doing something different
option(BUILD_SHARED_LIBS "Build monad with shared libraries" OFF)
endif()
include(cmake/test.cmake)
# ##############################################################################
# deps
# ##############################################################################
set(THIRD_PARTY_DIR "${PROJECT_SOURCE_DIR}/third_party")
function(monad_compile_options target)
set_property(TARGET ${target} PROPERTY C_STANDARD 23)
set_property(TARGET ${target} PROPERTY C_STANDARD_REQUIRED ON)
set_property(TARGET ${target} PROPERTY CXX_STANDARD 23)
set_property(TARGET ${target} PROPERTY CXX_STANDARD_REQUIRED ON)
target_compile_options(${target} PRIVATE -Wall -Wextra -Wconversion -Werror)
target_compile_definitions(${target} PUBLIC "_GNU_SOURCE")
target_compile_options(
${target} PRIVATE $<$<CXX_COMPILER_ID:GNU>:-Wno-missing-field-initializers>)
target_compile_definitions(${target} PUBLIC QUILL_ROOT_LOGGER_ONLY)
if(MONAD_COMPILER_TESTING)
target_compile_definitions(${target} PUBLIC "MONAD_COMPILER_TESTING=1")
endif()
if(MONAD_COMPILER_STATS)
target_compile_definitions(${target} PUBLIC "MONAD_COMPILER_STATS=1")
endif()
if(MONAD_COMPILER_HOT_PATH_STATS)
target_compile_definitions(${target} PUBLIC "MONAD_COMPILER_HOT_PATH_STATS=1")
endif()
target_compile_options(
${target}
PUBLIC $<$<CXX_COMPILER_ID:GNU>:-Wno-attributes=clang::no_sanitize>)
# this is needed to turn off ranges support in nlohmann_json, because the
# ranges standard header triggers a clang bug which is fixed in trunk but not
# currently available to us
# https://gcc.gnu.org/bugzilla//show_bug.cgi?id=109647
target_compile_definitions(${target} PUBLIC "JSON_HAS_RANGES=0")
endfunction()
find_package(Boost REQUIRED COMPONENTS fiber json CONFIG)
find_package(PkgConfig REQUIRED)
pkg_check_modules(brotli REQUIRED IMPORTED_TARGET libbrotlienc libbrotlidec)
pkg_check_modules(crypto++ REQUIRED IMPORTED_TARGET libcrypto++)
# ankerl
add_library(ankerl_hash INTERFACE)
target_include_directories(ankerl_hash INTERFACE "third_party/ankerl")
# asmjit
set(ASMJIT_STATIC ON)
add_subdirectory(third_party/asmjit)
# BLAKE3
add_subdirectory(third_party/BLAKE3/c)
# blst
set(DOWNLOAD_BLST OFF)
include(cmake/blst.cmake)
# c-kzg-4844
add_subdirectory("third_party/c-kzg-4844-builder")
# cli11
find_package(CLI11 REQUIRED)
# concurrentqueue
add_subdirectory("third_party/concurrentqueue")
# cthash
add_subdirectory("third_party/cthash")
# ethash
set(ETHASH_TESTING NO)
add_subdirectory("third_party/ethash")
# immer
option(immer_BUILD_TESTS OFF)
option(immer_BUILD_EXAMPLES OFF)
option(immer_BUILD_EXTRAS OFF)
add_subdirectory("third_party/immer" SYSTEM)
# intx
add_subdirectory("third_party/intx")
# evmc
set(HUNTER_ENABLED OFF)
add_subdirectory("third_party/evmc")
# evmone
if (MONAD_COMPILER_TESTING OR MONAD_COMPILER_BENCHMARKS)
include(cmake/evmone.cmake)
endif()
# komihash
add_library(komihash INTERFACE)
target_include_directories(komihash INTERFACE "third_party/komihash")
# LLVM
# Because LLVM is a large dependency, we only try to find it if it's
# explicitly enabled as part of the VM build: regular client builds don't need
# to use it.
if(UTILS_CLANG_TIDY_AUTO_CONST OR MONAD_COMPILER_LLVM)
include(cmake/LinkLLVM.cmake)
find_package(LLVM 19.1.7 REQUIRED CONFIG)
endif()
if(MONAD_COMPILER_LLVM)
add_definitions(-DMONAD_COMPILER_LLVM)
endif()
# magic_enum
find_package(magic_enum REQUIRED)
# nanobench
add_subdirectory("third_party/nanobench")
# nlohmann_json
add_subdirectory("third_party/nlohmann_json" SYSTEM)
# quill
add_subdirectory("third_party/quill")
# TODO
target_compile_options(
quill
PUBLIC
$<$<AND:$<CXX_COMPILER_ID:GNU>,$<CONFIG:Release>>:-Wno-stringop-overflow>)
target_compile_options(
quill PUBLIC $<$<CXX_COMPILER_ID:GNU>:-Wno-tautological-compare>)
# silkpre
set(OPTIONAL_BUILD_TESTS OFF)
add_subdirectory(third_party/silkpre)
# undo the injection of ccache silkpre/ff does
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK)
# tbb
find_package(TBB REQUIRED)
# thread-safe-lru
add_library(thread_safe_lru INTERFACE)
target_include_directories(thread_safe_lru
INTERFACE "third_party/thread-safe-lru")
# unordered_dense
add_subdirectory("third_party/unordered_dense")
# ##############################################################################
# unit tests
# ##############################################################################
set(TEST_DATA_DIR "${PROJECT_SOURCE_DIR}/test")
set(VM_DATA_DIR "${PROJECT_SOURCE_DIR}/test/vm/data")
configure_file(cmake/test_resource_data.h.in test/test_resource_data.h @ONLY)
set(TOP_CURRENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
function(monad_add_test2 target)
add_executable(
${target}
"${CMAKE_CURRENT_FUNCTION_LIST_DIR}/test/unit/common/src/test/main.cpp"
${ARGN})
monad_compile_options(${target})
target_compile_options(${target} PUBLIC "-Wno-missing-field-initializers"
)# TODO
target_include_directories(
${target}
PRIVATE "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/test/unit/common/include")
target_include_directories(${target} PRIVATE "${TOP_CURRENT_BINARY_DIR}/test")
target_link_libraries(${target} monad_execution GTest::GTest GTest::Main)
if("${target}" MATCHES "test_statesync")
gtest_discover_tests(
${target} DISCOVERY_MODE PRE_TEST
PROPERTIES RUN_SERIAL
TRUE
ENVIRONMENT
ASAN_OPTIONS=abort_on_error=1
ENVIRONMENT
UBSAN_OPTIONS=halt_on_error=1,print_stacktrace=1
ENVIRONMENT
TSAN_OPTIONS=external_symbolizer_path=/usr/bin/llvm-symbolizer)
else()
gtest_discover_tests(
${target} DISCOVERY_MODE PRE_TEST
PROPERTIES ENVIRONMENT ASAN_OPTIONS=abort_on_error=1 ENVIRONMENT
UBSAN_OPTIONS=halt_on_error=1,print_stacktrace=1 ENVIRONMENT
TSAN_OPTIONS=external_symbolizer_path=/usr/bin/llvm-symbolizer)
endif()
endfunction()
function(monad_add_test_folder target)
file(GLOB_RECURSE test_files CONFIGURE_DEPENDS ${target}/test_*.cpp
${target}/*_test.cpp)
foreach(test_file ${test_files})
get_filename_component(test_name ${test_file} NAME_WLE)
monad_add_test2(${test_name} ${test_file})
endforeach()
endfunction()
function(monad_add_test_death target)
cmake_parse_arguments(ADD_DEATH_TEST "" "FAIL_REGEX"
"SOURCES;LINK_LIBRARIES;TEST_PROPERTIES" ${ARGN})
if(NOT ADD_DEATH_TEST_FAIL_REGEX)
message(FATAL_ERROR "FATAL: FAIL_REGEX is mandatory")
endif()
add_executable(${target} ${ADD_DEATH_TEST_SOURCES})
monad_compile_options(${target})
target_link_libraries(${target} PUBLIC GTest::gtest_main
${ADD_DEATH_TEST_LINK_LIBRARIES})
add_test(NAME "${PROJECT_NAME}/${target}" COMMAND ${CMAKE_COMMAND} -E env
$<TARGET_FILE:${target}>)
set_tests_properties(
"${PROJECT_NAME}/${target}"
PROPERTIES PASS_REGULAR_EXPRESSION
"${ADD_DEATH_TEST_FAIL_REGEX}"
${ADD_DEATH_TEST_TEST_PROPERTIES}
ENVIRONMENT
ASAN_OPTIONS=abort_on_error=1
ENVIRONMENT
UBSAN_OPTIONS=halt_on_error=1,print_stacktrace=1
ENVIRONMENT
TSAN_OPTIONS=external_symbolizer_path=/usr/bin/llvm-symbolizer)
endfunction()
# ##############################################################################
# libs
# ##############################################################################
add_subdirectory("category/async")
add_subdirectory("category/core")
add_subdirectory("category/mpt")
add_subdirectory("category/event")
add_subdirectory("category/execution")
add_subdirectory("category/rpc")
add_subdirectory("category/statesync")
add_subdirectory("category/vm")
# Assemble all the object libraries into complete monad runtime library,
# monad_execution
add_library(monad_execution)
target_link_libraries(
monad_execution
PUBLIC monad_core
monad_async
monad_trie
monad_execution_ethereum
monad_execution_native
monad_rpc
monad_statesync
monad-vm
monad-vm-core
monad-vm-compiler
monad-vm-evm
monad-vm-interpreter
monad-vm-runtime
monad-vm-utils)
# ##############################################################################
# cmds
# ##############################################################################
add_subdirectory(${PROJECT_SOURCE_DIR}/cmd)
# ##############################################################################
# unit tests
# ##############################################################################
add_subdirectory(${PROJECT_SOURCE_DIR}/test/ethereum_test)
add_subdirectory(${PROJECT_SOURCE_DIR}/test/unit/common)
add_subdirectory(${PROJECT_SOURCE_DIR}/test/vm)
# ##############################################################################
# utilities
# ##############################################################################
if(UTILS_CLANG_TIDY_AUTO_CONST)
add_subdirectory(${PROJECT_SOURCE_DIR}/utils)
endif()