-
Notifications
You must be signed in to change notification settings - Fork 20
/
CMakeLists.txt
237 lines (195 loc) · 7.92 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
cmake_minimum_required(VERSION 3.20)
# Set current version of the project
set(TARAXA_MAJOR_VERSION 1)
set(TARAXA_MINOR_VERSION 11)
set(TARAXA_PATCH_VERSION 4)
set(TARAXA_VERSION ${TARAXA_MAJOR_VERSION}.${TARAXA_MINOR_VERSION}.${TARAXA_PATCH_VERSION})
# Any time a change in the network protocol is introduced this version should be increased
set(TARAXA_NET_VERSION 3)
# Major version is modified when DAG blocks, pbft blocks and any basic building blocks of our blockchain is modified
# in the db
set(TARAXA_DB_MAJOR_VERSION 1)
# Minor version should be modified when changes to the database are made in the tables that can be rebuilt from the
# basic tables
set(TARAXA_DB_MINOR_VERSION 2)
# Defines Taraxa library target.
project(taraxa-node VERSION ${TARAXA_VERSION})
# Set project properties like C++ standard, etc...
set(CMAKE_CXX_STANDARD 20)
# export compile_commands.json file
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_compile_options(-Wall
-Wpedantic
-Wextra
-Werror
-Wvla
-Wextra-semi
-Wnull-dereference
-Wno-unknown-pragmas
-Wno-overlength-strings)
# Set the position independent code property on all targets
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if (APPLE)
add_compile_options(-Wno-deprecated-declarations -Wrange-loop-analysis)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# deal with errors from taraxa-evm autogenerated files
add_compile_options(-Wno-c99-extensions)
endif()
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
# Enable LTO
option(TARAXA_ENABLE_LTO "Build taraxad with LTO (ON or OFF)" OFF)
if(TARAXA_ENABLE_LTO AND NOT TARAXA_STATIC_BUILD)
include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)
if( supported )
message(STATUS "IPO / LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "IPO / LTO not supported: <${error}>")
endif()
endif()
if (NOT CONAN_PROFILE)
set(CONAN_PROFILE "clang")
endif()
# taraxad full static build option
option(TARAXA_STATIC_BUILD "Build taraxad statically (ON or OFF)" ON)
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS "CONAN_PROFILE: ${CONAN_PROFILE}")
message(STATUS "TARAXA_STATIC_BUILD: ${TARAXA_STATIC_BUILD}")
# enable sanitizers
option(TARAXA_ENABLE_SANITIZERS "Enable sanitizers (ON or OFF)" OFF)
if (TARAXA_ENABLE_SANITIZERS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=undefined")
endif()
message(STATUS "TARAXA_ENABLE_SANITIZERS: ${TARAXA_ENABLE_SANITIZERS}")
# Use ccache to speed-up recompilation
find_program(CCACHE_PROGRAM ccache)
if (CCACHE_PROGRAM)
message(STATUS "Building with ccache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
else ()
message(STATUS "Building without ccache")
endif ()
# Mac OS
set(CMAKE_MACOSX_RPATH OFF)
# Enable creation of taraxa package containing taraxad binary
set(ENABLE_PACKAGE_INSTALLER TRUE CACHE BOOL "Build Taraxa package")
if (ENABLE_PACKAGE_INSTALLER)
include(InstallRequiredSystemLibraries)
set(CPACK_OUTPUT_FILE_PREFIX ${CMAKE_BINARY_DIR}/packages)
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install)
SET(CPACK_PACKAGE_DIRECTORY "${CMAKE_INSTALL_PREFIX}")
set(CPACK_PACKAGE_NAME "Taraxa")
set(CPACK_PACKAGE_VENDOR "Phragmites Inc.")
set(CPACK_PACKAGE_VERSION_MAJOR "${TARAXA_MAJOR_VERSION}")
set(CPACK_PACKAGE_VERSION_MINOR "${TARAXA_MINOR_VERSION}")
set(CPACK_PACKAGE_VERSION_PATCH "${TARAXA_PATCH_VERSION}")
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_PACKAGE_DESCRIPTION "A client for the Taraxa network")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A client for the Taraxa network")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "Taraxa ${CPACK_PACKAGE_VERSION}")
if (APPLE)
set(CPACK_GENERATOR "DragNDrop")
endif ()
if (LINUX)
# Linux gets a .tgz
SET(CPACK_GENERATOR "TGZ")
SET(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 1)
endif (LINUX)
include(CPack)
endif (ENABLE_PACKAGE_INSTALLER)
if (TARAXA_STATIC_BUILD)
# all internal libs will be built as static if not explicitly specified as shared
set(BUILD_SHARED_LIBS OFF)
if (NOT APPLE)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") # zlib does not support zlib_USE_STATIC_LIBS or similar approach
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
endif()
else (TARAXA_STATIC_BUILD)
# all internal libs will be built as shared if not explicitly specified as static
set(BUILD_SHARED_LIBS ON)
endif (TARAXA_STATIC_BUILD)
# fix for boost thread library on MacOS
IF(APPLE)
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0)
set(CMAKE_USE_PTHREADS_INIT 1)
set(THREADS_PREFER_PTHREAD_FLAG ON)
ENDIF()
# conan package manager
if(CONAN_EXPORTED)
## conan install already called
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
else()
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://github.com/conan-io/cmake-conan/raw/v0.16.1/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake"
TLS_VERIFY ON)
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_run(CONANFILE conanfile.py
BUILD_TYPE ${CMAKE_BUILD_TYPE}
CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
BASIC_SETUP
CMAKE_TARGETS
KEEP_RPATHS
PROFILE ${CONAN_PROFILE}
BUILD missing
)
set(CONAN_EXPORTED true CACHE BOOL "Is conan already run on the project")
endif()
# Custom CMakeModules for finding libraries
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
# Building with gperftools
option(TARAXA_GPERF "Build taraxad with GPERFTOOLS" OFF)
if(TARAXA_GPERF)
find_library(TCMALLOC_LIB NAMES tcmalloc)
if(TCMALLOC_LIB)
message("Found TCMALLOC_LIB: ${TCMALLOC_LIB}")
else()
message(FATAL_ERROR "TCMALLOC_LIB library not found")
endif()
endif()
# We are using clang from llvm toolchain as default compiler as well as clang-format and clang-tidy
# It is possible to build taraxa-node also with other C++ compilers but to contribute to the official repo,
# changes must pass clang-format/clang-tidy checks for which we internally use llvm version=LLVM_VERSION
set(LLVM_VERSION "17")
# clang-tidy
include(CMakeModules/clang_tidy.cmake)
# clang-format
include(CMakeModules/clang_format.cmake)
# cppcheck
include(CMakeModules/cppcheck.cmake)
add_custom_target(check-static DEPENDS cpp-check clang-format clang-format-check)
# execute command to get git info
include(CMakeModules/git_info.cmake)
include(ExternalProject)
# find and include system libraries used in submodules and libraries
find_package(GMP)
find_package(MPFR)
# use JSONCPP library from conan for JSONRPCCPP build
set(JSONCPP_INCLUDE_DIR ${CONAN_INCLUDE_DIRS_JSONCPP})
include(ProjectJSONRPCCPP)
# rocksdb build
include(${PROJECT_SOURCE_DIR}/CMakeModules/rocksdb.cmake)
# Add sub-directories cmakes
add_subdirectory(submodules)
add_subdirectory(libraries)
add_subdirectory(programs)
add_subdirectory(tests)
# An extension of this file that you can play with locally
include(local/CMakeLists_ext.cmake OPTIONAL)
# dependency graph
# add_custom_target(graphviz ALL
# COMMAND ${CMAKE_COMMAND} "--graphviz=foo.dot" .
# COMMAND dot -Tpng foo.dot -o foo.png
# WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
# )