-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxmake.lua
273 lines (225 loc) · 9.44 KB
/
xmake.lua
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
-- config version
set_version("1.1.4", {build="%Y%m%d%H%M"}) --使用 build 参数将导致每次重编译
-- set warning all as error
set_warnings("all", "error")
-- set language: C99, c++ standard
-- set_languages("cxx17", "c99")
add_rules("mode.debug", "mode.release", "mode.coverage", "mode.profile")
set_objectdir("$(buildir)/$(mode)/$(plat)/$(arch)/.objs")
set_targetdir("$(buildir)/$(mode)/$(plat)/$(arch)/lib")
option("mysql", {description = "Enable sqlite driver.", default = false})
option("sqlite", {description = "Enable sqlite driver.", default = true})
option("sqlcipher", {description = "Enalbe sqlchiper driver.", default = false})
option("sql_trace", {description = "Print the executed SQL statement", default = false})
-- 注意:stacktrace 在 windows 下会严重影响性能
option("stacktrace", {description = "Enable check/assert with stack trace info.", default = false})
option("datetime", {description = "Enable DateTime.", default = true})
option("spend_time", {description = "Enable spent time.", default = true})
option("log_level", {description = "set log level.", default = 2, values = {1, 2, 3, 4, 5, 6}})
option("async_log", {description = "Use async log.", default = false})
option("leak_check", {description = "Enable leak check for test", default = false})
option("ini_parser", {description = "Enable ini parser.", default = true})
option("mo", {description = "International language support", default = false})
option("http_client", {description = "use http client", default = true})
option("http_client_ssl", {description = "enable https support for http client", default = false})
option("http_client_zip", {description = "enable http support gzip", default = false})
option("node", {description = "enable node reqrep server/client", default = true})
if has_config("leak_check") then
-- 需要 export LD_PRELOAD=libasan.so
set_policy("build.sanitizer.address", true)
set_policy("build.sanitizer.leak", true)
-- set_policy("build.sanitizer.memory", true)
-- set_policy("build.sanitizer.thread", true)
end
-- SPDLOG_ACTIVE_LEVEL 需要单独加
local log_level = get_config("log_level")
if log_level == nil then
log_level = 2
end
add_defines("SPDLOG_ACTIVE_LEVEL=" .. log_level)
-- is release now
if is_mode("release") then
if is_plat("windows") then
-- Unix-like systems hidden symbols will cause the link dynamic libraries to failed!
set_symbols("hidden")
end
end
-- for the windows platform (msvc)
if is_plat("windows") then
-- add some defines only for windows
add_defines("NOCRYPT", "NOGDI")
add_cxflags("-EHsc", "/Zc:__cplusplus", "/utf-8")
add_cxflags("-wd4819") -- template dll export warning
add_cxflags("-wd4068") -- unknown pragma
add_defines("WIN32_LEAN_AND_MEAN")
if is_mode("debug") then
add_cxflags("-Gs", "-RTC1", "/bigobj")
end
end
if not is_plat("windows") then
-- disable some compiler errors
add_cxflags("-Wno-error=deprecated-declarations", "-fno-strict-aliasing")
add_cxflags("-ftemplate-depth=1023", "-pthread")
add_cxxflags("-frtti") ---- gcc 只能用于编译 C++ 文件,否则保报错
add_shflags("-pthread")
add_ldflags("-pthread")
end
add_repositories("hikyuu-repo https://github.com/fasiondog/hikyuu_extern_libs.git")
-- add_repositories("hikyuu-repo https://gitee.com/fasiondog/hikyuu_extern_libs.git
local fmt_version = "11.0.2"
add_requires("fmt " .. fmt_version, {configs = {header_only = true}})
add_requires("spdlog", {configs = {header_only = true, fmt_external = true}})
add_requireconfs("spdlog.fmt", {override = true, version=fmt_version, configs = {header_only = true}})
add_requires("yas")
add_requires("boost", {
system = false,
debug = is_mode("debug"),
configs = {
shared = is_plat("windows"),
runtimes = get_config("runtime"),
multi = true,
date_time = has_config("datetime"),
filesystem = false,
serialization = false,
system = false,
python = false,
cmake = false,
},
})
-- 使用 sqlcipher 时,忽略 sqlite3
if has_config("sqlcipher") then
if is_plat("iphoneos") then
add_requires("sqlcipher", {system=false})
else
add_requires("sqlcipher", {system = false, configs = {shared = true, safe_mode="2"}})
end
elseif has_config("sqlite") then
add_requires("sqlite3", {system = false, configs = {shared = true, safe_mode="2"}})
end
if has_config("mysql") then
if is_plat("linux") and linuxos.name() == "ubuntu" then
add_requires("apt::libmysqlclient-dev", {alias = "mysql"})
else
add_requires("mysql")
end
end
if has_config("http_client") or has_config("node") then
add_requires("nlohmann_json")
if is_kind("shared") then
add_requires("nng", {configs = {NNG_ENABLE_TLS = has_config("http_client_ssl"), cxflags = "-fPIC"}})
add_requireconfs("nng.mbedtls", {configs = {cxflags = "-fPIC"}})
else
add_requires("nng", {configs = {NNG_ENABLE_TLS = has_config("http_client_ssl")}})
end
if has_config("http_client_zip") then
add_requires("gzip-hpp")
end
end
target("hku_utils")
set_kind("$(kind)")
set_configdir("$(projectdir)/hikyuu/utilities")
add_configfiles("$(projectdir)/version.h.in")
add_configfiles("$(projectdir)/config.h.in")
set_configvar("HKU_ENABLE_MYSQL", has_config("mysql") and 1 or 0)
set_configvar("HKU_ENABLE_SQLITE", (has_config("sqlite") or has_config("sqlcipher")) and 1 or 0)
set_configvar("HKU_ENABLE_SQLCIPHER", has_config("sqlcipher") and 1 or 0)
set_configvar("HKU_SQL_TRACE", has_config("sql_trace") and 1 or 0)
set_configvar("HKU_SUPPORT_DATETIME", has_config("datetime") and 1 or 0)
set_configvar("HKU_ENABLE_INI_PARSER", has_config("ini_parser") and 1 or 0)
set_configvar("HKU_ENABLE_STACK_TRACE", has_config("stacktrace") and 1 or 0)
set_configvar("HKU_CLOSE_SPEND_TIME", has_config("spend_time") and 0 or 1)
set_configvar("HKU_ENABLE_MO", has_config("mo") and 1 or 0)
set_configvar("HKU_ENABLE_HTTP_CLIENT", has_config("http_client") and 1 or 0)
set_configvar("HKU_ENABLE_HTTP_CLIENT_SSL", has_config("http_client_ssl") and 1 or 0)
set_configvar("HKU_ENABLE_HTTP_CLIENT_ZIP", has_config("http_client_zip") and 1 or 0)
set_configvar("HKU_ENABLE_NODE", has_config("node") and 1 or 0)
set_configvar("HKU_USE_SPDLOG_ASYNC_LOGGER", has_config("async_log") and 1 or 0)
set_configvar("HKU_LOG_ACTIVE_LEVEL", get_config("log_level"))
add_packages("fmt", "spdlog", "boost", "yas")
add_includedirs(".")
if has_config("sqlcipher") then
add_packages("sqlcipher")
elseif has_config("sqlite") then
add_packages("sqlite3")
if is_plat("cross") then
add_syslinks("dl")
end
end
if has_config("mysql") then
add_packages("mysql")
end
if has_config("http_client") or has_config("node") then
add_packages("nng", "nlohmann_json")
end
if has_config("http_client_zip") then
add_packages("gzip-hpp")
end
if is_plat("linux", "cross") then
add_rpathdirs("$ORIGIN")
end
if is_kind("shared") then
if is_plat("windows") then
add_defines("HKU_UTILS_API=__declspec(dllexport)")
else
add_defines("HKU_UTILS_API=__attribute__((visibility(\"default\")))")
add_cxflags("-fPIC", {force=true})
end
elseif is_kind("static") and not is_plat("windows") then
add_cxflags("-fPIC", {force=true})
end
if is_plat("macosx", "iphoneos") then
add_cxflags("-Wno-deprecated-declarations")
add_links("iconv")
end
-- gcc 4.8.5 必须编译和链接同时加上 -pthread, 否则运行异常
if is_plat("macosx", "linux", "cross") then
add_cxflags("-pthread")
add_syslinks("pthread")
end
if is_plat("windows") then
add_cxflags("-wd4996", "-wd4251")
end
add_headerfiles("$(projectdir)/(hikyuu/**.h)")
add_files("hikyuu/utilities/*.cpp")
add_files("hikyuu/utilities/thread/*.cpp")
add_files("hikyuu/utilities/db_connect/*.cpp")
if has_config("sqlite") then
add_files("hikyuu/utilities/db_connect/sqlite/*.cpp")
end
if has_config("mysql") then
add_files("hikyuu/utilities/db_connect/mysql/*.cpp")
end
if has_config("ini_parser") then
add_files("hikyuu/utilities/ini_parser/*.cpp")
end
if has_config("datetime") then
add_files("hikyuu/utilities/datetime/*.cpp")
end
if has_config("mo") then
add_files("hikyuu/utilities/mo/*.cpp")
end
if has_config("http_client") then
add_files("hikyuu/utilities/http_client/*.cpp")
end
before_build(function(target)
-- 注:windows 使用 dll 需要 c++17, linux 使用静态库最低需要 C++ 17
-- 未指定 C++标准时,设置最低要求 c++11
local x = target:get("languages")
if x == nil then
target:set("languages", "cxx17")
end
end)
after_build(function(target)
local destpath = get_config("buildir") .. "/" .. get_config("mode") .. "/" .. get_config("plat") .. "/" .. get_config("arch")
print(destpath)
import("core.project.task")
task.run("copy_dependents", {}, target, destpath, true)
end)
after_install(function(target)
local destpath = target:installdir()
import("core.project.task")
task.run("copy_dependents", {}, target, destpath, false)
end)
target_end()
includes("copy_dependents.lua")
includes("./test")