forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 14
/
CMakeLists.txt
174 lines (144 loc) · 5.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
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(TrustWalletCore)
include(GNUInstallDirs)
# Configure warnings
if(NOT ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC"))
set(TW_CXX_WARNINGS "-Wshorten-64-to-32")
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TW_CXX_WARNINGS}")
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "Minimum OS X deployment version" FORCE)
if((NOT ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")) AND (NOT ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")))
message(FATAL_ERROR "You should use clang or msvc compiler")
endif()
if ("$ENV{PREFIX}" STREQUAL "")
set(PREFIX "${CMAKE_SOURCE_DIR}/build/local")
else()
set(PREFIX "$ENV{PREFIX}")
endif()
# Configure CCache if available
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)
include_directories(${PREFIX}/include)
link_directories(${PREFIX}/lib)
if(WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS) # Disable strcpy warnings
endif()
add_subdirectory(trezor-crypto)
macro(find_host_package)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
find_package(${ARGN})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
endmacro(find_host_package)
find_host_package(Boost REQUIRED)
include(ExternalProject)
# Dependencies
if(WIN32)
# Use regular static lib on Windows
find_package(Protobuf REQUIRED)
include_directories(${Protobuf_INCLUDE_DIRS})
else()
# Build as part of project otherwise
include(cmake/Protobuf.cmake)
endif()
if(WIN32)
# Static library is required when building tools (walletconsole) that include the C++ headers
option(TW_STATIC_LIBRARY "Build static TrustWalletCore library" OFF)
if(TW_STATIC_LIBRARY)
add_definitions(-DTW_STATIC_LIBRARY)
endif()
endif()
option(CODE_COVERAGE "Enable coverage reporting" OFF)
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "-fprofile-arcs -ftest-coverage")
endif()
option(CLANG_TIDY "Enable static code analysis with (clang-tidy)" OFF)
if(CLANG_TIDY)
find_program(CLANG_TIDY_BIN NAMES clang-tidy-11)
if(CLANG_TIDY_BIN)
set(CMAKE_CXX_CLANG_TIDY clang-tidy-11;)
message("clang-tidy ${CMAKE_CXX_CLANG_TIDY} ${CLANG_TIDY_BIN}")
else()
message(FATAL_ERROR "Could not find clang-tidy")
endif()
endif()
option(CLANG_ASAN "Enable ASAN dynamic address sanitizer" OFF)
if(CLANG_ASAN)
# https://clang.llvm.org/docs/AddressSanitizer.html
# https://github.com/trustwallet/wallet-core/issues/1170
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer")
message("CLANG_ASAN on, ${CMAKE_CXX_FLAGS_DEBUG}")
endif()
# Source files
if(${ANDROID})
message("Configuring for JNI")
file(GLOB_RECURSE sources src/*.c src/*.cc src/*.cpp src/*.h jni/cpp/*.c jni/cpp/*.cpp jni/cpp/*.h jni/cpp/*.c)
add_library(TrustWalletCore SHARED ${sources} ${PROTO_SRCS} ${PROTO_HDRS})
find_library(log-lib log)
target_link_libraries(TrustWalletCore PRIVATE TrezorCrypto ${Protobuf_LIBRARIES} ${log-lib} Boost::boost)
else()
file(GLOB_RECURSE sources src/*.c src/*.cc src/*.cpp src/*.h)
if(WIN32)
file(GLOB_RECURSE headers include/TrustWalletCore/*.h)
if(TW_STATIC_LIBRARY)
message("Configuring static for Windows")
add_library(TrustWalletCore ${sources} ${headers} ${PROTO_SRCS} ${PROTO_HDRS})
else()
message("Configuring shared for Windows")
add_library(TrustWalletCore SHARED ${sources} ${headers} ${PROTO_SRCS} ${PROTO_HDRS})
target_compile_definitions(TrustWalletCore PRIVATE TW_EXPORT_LIBRARY)
endif()
else()
message("Configuring standalone")
add_library(TrustWalletCore ${sources} ${PROTO_SRCS} ${PROTO_HDRS})
endif()
target_link_libraries(TrustWalletCore PRIVATE TrezorCrypto ${Protobuf_LIBRARIES} Boost::boost)
endif()
if(NOT ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC"))
target_compile_options(TrustWalletCore PRIVATE "-Wall")
endif()
set_target_properties(TrustWalletCore
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
# Define headers for this library. PUBLIC headers are used for compiling the
# library, and will be added to consumers' build paths.
target_include_directories(TrustWalletCore
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/jni/cpp
${CMAKE_CURRENT_SOURCE_DIR}/build/local/include
)
if(NOT ANDROID AND NOT IOS_PLATFORM AND NOT (WIN32 AND NOT TW_STATIC_LIBRARY))
add_subdirectory(tests)
add_subdirectory(walletconsole/lib)
add_subdirectory(walletconsole)
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/swift/cpp.xcconfig.in ${CMAKE_CURRENT_SOURCE_DIR}/swift/cpp.xcconfig @ONLY)
if(WIN32 AND NOT TW_STATIC_LIBRARY)
install(TARGETS TrustWalletCore RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
install(TARGETS TrustWalletCore
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/WalletCore
FILES_MATCHING PATTERN "*.h")
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})