forked from btccom/btcagent
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
213 lines (172 loc) · 7.15 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
cmake_minimum_required (VERSION 3.1)
project (PoolAgent)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_C_STANDARD 99)
#
# Cross compilation toolchain
# cmake -DTOOLCHAIN=/path/to/toolchain ..
#
IF(TOOLCHAIN)
set(CROSS_PREFIX ${TOOLCHAIN}/bin/mipsel-openwrt-linux-)
set(CMAKE_CXX_COMPILER ${CROSS_PREFIX}g++)
set(CMAKE_C_COMPILER ${CROSS_PREFIX}gcc)
message("-- TOOLCHAIN: ${CMAKE_CXX_COMPILER} ${CMAKE_C_COMPILER}")
ENDIF()
#
# cmake -DCMAKE_BUILD_TYPE=Debug ..
# cmake -DCMAKE_BUILD_TYPE=Release ..
#
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
message("-- Build Type: ${CMAKE_BUILD_TYPE} (-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})")
IF (CMAKE_SYSTEM_NAME MATCHES "Windows")
###
# Use IOCP (I/O Completion Port) replace select() for libevent
###
option(POOLAGENT__USE_IOCP "Use IOCP (I/O Completion Port) replace select() for libevent" OFF)
if(POOLAGENT__USE_IOCP)
message("-- Use IOCP (I/O Completion Port) for libevent (-DPOOLAGENT__USE_IOCP=ON)")
set(CompilerFlags CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE)
foreach(CompilerFlag ${CompilerFlags})
set(${CompilerFlag} "${${CompilerFlag}} -DUSE_IOCP")
message("${CompilerFlag}=${${CompilerFlag}}")
endforeach()
else()
message("-- Use select() for libevent (-DPOOLAGENT__USE_IOCP=OFF)")
endif()
###
# static linking VC++ runtime library
###
option(POOLAGENT__STATIC_LINKING_VC_LIB "Static linking VC++ runtime library (/MT)" OFF)
macro(set_linking_vclib CompilerFlag LinkFlag)
string(REPLACE "/MDd" "" ${CompilerFlag} "${${CompilerFlag}}")
string(REPLACE "/MD" "" ${CompilerFlag} "${${CompilerFlag}}")
string(REPLACE "/MTd" "" ${CompilerFlag} "${${CompilerFlag}}")
string(REPLACE "/MT" "" ${CompilerFlag} "${${CompilerFlag}}")
set(${CompilerFlag} "${${CompilerFlag}} ${LinkFlag}")
message("${CompilerFlag}=${${CompilerFlag}}")
endmacro()
if(POOLAGENT__STATIC_LINKING_VC_LIB)
message("-- Static linking VC++ runtime library (/MT): -DPOOLAGENT__STATIC_LINKING_VC_LIB=ON")
set_linking_vclib(CMAKE_CXX_FLAGS_DEBUG "/MTd")
set_linking_vclib(CMAKE_C_FLAGS_DEBUG "/MTd")
set_linking_vclib(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MTd")
set_linking_vclib(CMAKE_C_FLAGS_RELWITHDEBINFO "/MTd")
set_linking_vclib(CMAKE_CXX_FLAGS_RELEASE "/MT")
set_linking_vclib(CMAKE_C_FLAGS_RELEASE "/MT")
set_linking_vclib(CMAKE_CXX_FLAGS_MINSIZEREL "/MT")
set_linking_vclib(CMAKE_C_FLAGS_MINSIZEREL "/MT")
else()
message("-- Dynamic linking VC++ runtime library (/MD): -DPOOLAGENT__STATIC_LINKING_VC_LIB=OFF")
set_linking_vclib(CMAKE_CXX_FLAGS_DEBUG "/MDd")
set_linking_vclib(CMAKE_C_FLAGS_DEBUG "/MDd")
set_linking_vclib(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MDd")
set_linking_vclib(CMAKE_C_FLAGS_RELWITHDEBINFO "/MDd")
set_linking_vclib(CMAKE_CXX_FLAGS_RELEASE "/MD")
set_linking_vclib(CMAKE_C_FLAGS_RELEASE "/MD")
set_linking_vclib(CMAKE_CXX_FLAGS_MINSIZEREL "/MD")
set_linking_vclib(CMAKE_C_FLAGS_MINSIZEREL "/MD")
endif()
set(POOLAGENT__GENERATE_DEB_PACKAGE OFF)
ELSE()
IF(CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_CXX_FLAGS "-g -O0 -Wall")
ELSEIF(CMAKE_BUILD_TYPE MATCHES Release)
set(CMAKE_CXX_FLAGS "-O2 -Wall")
ENDIF()
# Debian/Ubuntu software package
option(POOLAGENT__GENERATE_DEB_PACKAGE "Generate Debian/Ubuntu software package" ON)
if(POOLAGENT__GENERATE_DEB_PACKAGE)
message("-- Generate Debian/Ubuntu software package: Enabled (-DPOOLAGENT__GENERATE_DEB_PACKAGE=ON)")
else()
message("-- Generate Debian/Ubuntu software package: Disabled (-DPOOLAGENT__GENERATE_DEB_PACKAGE=OFF)")
endif()
set(POOLAGENT__USE_IOCP OFF)
set(POOLAGENT__STATIC_LINKING_VC_LIB OFF)
ENDIF()
###
# Use GLog for logging replace stdout
###
option(POOLAGENT__USE_GLOG "Use GLog for logging replace stdout" ON)
if(POOLAGENT__USE_GLOG)
message("-- Use GLog for logging (-DPOOLAGENT__USE_GLOG=ON)")
set(CompilerFlags CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE)
foreach(CompilerFlag ${CompilerFlags})
set(${CompilerFlag} "${${CompilerFlag}} -DGOOGLE_GLOG_DLL_DECL= -DSUPPORT_GLOG")
message("${CompilerFlag}=${${CompilerFlag}}")
endforeach()
else()
message("-- Use stdout for logging (-DPOOLAGENT__USE_GLOG=OFF)")
endif()
###
# Print logs to stdout with files
###
option(POOLAGENT__GLOG_TO_STDOUT "Print logs to stdout with files" OFF)
if(POOLAGENT__GLOG_TO_STDOUT)
message("-- Print logs to stdout with files (-DPOOLAGENT__GLOG_TO_STDOUT=ON)")
set(CompilerFlags CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE)
foreach(CompilerFlag ${CompilerFlags})
set(${CompilerFlag} "${${CompilerFlag}} -DGLOG_TO_STDOUT")
message("${CompilerFlag}=${${CompilerFlag}}")
endforeach()
else()
message("-- Only logs to file (-DPOOLAGENT__GLOG_TO_STDOUT=OFF)")
endif()
###################################### Libs ######################################
if(POOLAGENT__USE_GLOG)
find_package(Glog)
if(NOT GLOG_FOUND)
message(FATAL_ERROR "Glog not found!")
endif(NOT GLOG_FOUND)
endif()
find_package(LibEvent)
if(NOT LibEvent_FOUND)
message(FATAL_ERROR "libevent2 not found!")
endif(NOT LibEvent_FOUND)
include_directories(src test ${GLOG_INCLUDE_DIRS} ${LIBEVENT_INCLUDE_DIR})
set(THRID_LIBRARIES ${GLOG_LIBRARIES} ${LIBEVENT_LIB})
IF (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(THRID_LIBRARIES ${THRID_LIBRARIES} ws2_32)
ELSE()
set(THRID_LIBRARIES ${THRID_LIBRARIES} pthread)
ENDIF()
file(GLOB LIB_SOURCES src/*.*)
file(GLOB LIB_BITCOIN_SOURCES src/bitcoin/*.*)
file(GLOB LIB_ETH_SOURCES src/eth/*.*)
add_library(btccomagent STATIC ${LIB_SOURCES} ${LIB_BITCOIN_SOURCES} ${LIB_ETH_SOURCES})
file(GLOB_RECURSE TEST_SOURCES test/*.*)
add_executable(unittest ${TEST_SOURCES})
target_link_libraries(unittest btccomagent ${THRID_LIBRARIES})
file(GLOB_RECURSE AGENT_SOURCES src/agent/*.*)
IF (CMAKE_SYSTEM_NAME MATCHES "Windows")
file(GLOB_RECURSE AGENT_SOURCES ${AGENT_SOURCES} src/win32/getopt/*.*)
ENDIF()
add_executable(btcagent ${AGENT_SOURCES})
target_link_libraries(btcagent btccomagent ${THRID_LIBRARIES})
# make instal support
IF(POOLAGENT__GENERATE_DEB_PACKAGE)
install(TARGETS btcagent
DESTINATION /usr/bin)
install(FILES src/agent/agent_conf.json README.md README-zh_CN.md
DESTINATION /etc/btcagent)
install(FILES install/btcagent-single_user.conf
DESTINATION /etc/supervisor/conf.d)
# generate deb package by CPack
set(CPACK_GENERATOR "DEB")
set(CPACK_PACKAGE_NAME "btcagent-single_user")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "YihaoPeng [email protected]")
SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/install/debian-control/postinst")
# version
SET(CPACK_PACKAGE_VERSION_MAJOR "1")
SET(CPACK_PACKAGE_VERSION_MINOR "0")
SET(CPACK_PACKAGE_VERSION_PATCH "0")
# dependencies
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "supervisor")
include(CPack)
ENDIF()