forked from fasiondog/hku_utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmake.lua
375 lines (322 loc) · 11.1 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
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
-- config version
set_version("1.0.0", {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")
option("mysql")
set_default(true)
set_showmenu(true)
set_category("hikyuu")
set_description("Enable mysql kdata engine.")
if is_plat("macosx") then
if os.exists("/usr/local/opt/mysql-client/lib") then
add_includedirs("/usr/local/opt/mysql-client/include/mysql")
add_includedirs("/usr/local/opt/mysql-client/include")
add_linkdirs("/usr/local/opt/mysql-client/lib")
add_rpathdirs("/usr/local/opt/mysql-client/lib")
end
if os.exists("/usr/local/mysql/lib") then
add_linkdirs("/usr/local/mysql/lib")
add_rpathdirs("/usr/local/mysql/lib")
end
if not os.exists("/usr/local/include/mysql") then
if os.exists("/usr/local/mysql/include") then
os.run("ln -s /usr/local/mysql/include /usr/local/include/mysql")
else
print("Not Found MySQL include dir!")
end
end
add_links("mysqlclient")
elseif is_plat("windows") then
add_defines("NOMINMAX")
end
option_end()
option("sqlite")
set_default(true)
set_showmenu(true)
set_category("hikyuu")
set_description("Enable sqlite kdata engine.")
option_end()
option("sqlcipher")
set_default(false)
set_showmenu(true)
set_category("hikyuu")
set_description("Enalbe sqlchiper driver")
add_defines("HKU_ENABLE_SQLCIPHER")
option_end()
option("sql_trace")
set_default(false)
set_showmenu(true)
set_category("hikyuu")
set_description("打印执行的 SQL 语句")
add_defines("HKU_SQL_TRACE")
option_end()
-- 注意:stacktrace 在 windows 下会严重影响性能
option("stacktrace")
set_default(false)
set_showmenu(true)
set_category("hikyuu")
set_description("Enable check/assert with stack trace info.")
add_defines("HKU_ENABLE_STACK_TRACE")
option_end()
option("datetime")
set_default(true)
set_showmenu(true)
set_category("hikyuu")
set_description("Enable DateTime.")
add_defines("HKU_SUPPORT_DATETIME")
option_end()
option("spend_time")
set_default(true)
set_showmenu(true)
set_category("hikyuu")
set_description("Enable spend time.")
add_defines("HKU_CLOSE_SPEND_TIME=0")
option_end()
option("log_name")
set_default("hikyuu")
set_showmenu(true)
set_category("hikyuu")
set_description("set default log name")
after_check(function (option)
local name = get_config("log_name")
option:add("defines", 'HKU_DEFAULT_LOG_NAME="' .. name .. '"')
end)
option_end()
option("log_level")
set_default("info")
set_values("trace", "debug", "info", "warn", "error", "fatal", "off")
set_showmenu(true)
set_category("hikyuu")
set_description("set log level")
after_check(function (option)
local level = get_config("log_level")
if level == "trace" then
option:add("defines", "HKU_LOG_ACTIVE_LEVEL=0")
elseif level == "debug" then
option:add("defines", "HKU_LOG_ACTIVE_LEVEL=1")
elseif level == "info" then
option:add("defines", "HKU_LOG_ACTIVE_LEVEL=2")
elseif level == "warn" then
option:add("defines", "HKU_LOG_ACTIVE_LEVEL=3")
elseif level == "error" then
option:add("defines", "HKU_LOG_ACTIVE_LEVEL=4")
elseif level == "fatal" then
option:add("defines", "HKU_LOG_ACTIVE_LEVEL=5")
else
option:add("defines", "HKU_LOG_ACTIVE_LEVEL=6")
end
end)
option_end()
option("async_log")
set_default(false)
set_showmenu(true)
set_category("hikyuu")
set_description("Use async log.")
add_defines("HKU_USE_SPDLOG_ASYNC_LOGGER=1")
option_end()
option("leak_check")
set_default(false)
set_showmenu(true)
set_category("hikyuu")
set_description("Enable leak check for test")
option_end()
option("ini_parser")
set_default(true)
set_showmenu(true)
set_category("hikyuu")
set_description("Enable ini parser")
option_end()
if get_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
-- 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_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_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
add_requires("fmt", {system=false})
add_requires("spdlog", {system = false, configs = {header_only = true, fmt_external = true}})
add_requires("yas", {system=false})
add_requires("boost", {
system = false,
debug = is_mode("debug"),
configs = {
shared = is_plat("windows"),
runtimes = get_config("runtime"),
multi = true,
date_time = true,
filesystem = false,
serialization = false,
system = false,
python = false,
},
})
-- 使用 sqlcipher 时,忽略 sqlite3
if get_config("sqlcipher") then
if is_plat("iphoneos") then
add_requires("sqlcipher", {system=false})
else
add_requires("sqlcipher", {system = false, configs = {shared = true, tiny = true, SQLITE_THREADSAFE="2"}})
end
elseif get_config("sqlite") then
if is_plat("windows", "android", "cross") then
add_requires("sqlite3", {system = false, configs = {shared = true, tiny = true, SQLITE_THREADSAFE="2"}})
end
if is_plat("linux") and linuxos.name() == "ubuntu" then
add_requires("apt::libsqlite3-dev")
if get_config("mysql") then
add_requires("apt::libmysqlclient-dev")
end
end
end
if get_config("mysql") then
if is_plat("windows") then
add_requires("mysql")
elseif is_plat("macosx") then
add_requires("brew::mysql-client")
elseif is_plat("linux") and linuxos.name() == "ubuntu" then
add_requires("apt::libmysqlclient-dev")
end
end
set_objectdir("$(buildir)/$(mode)/$(plat)/$(arch)/.objs")
set_targetdir("$(buildir)/$(mode)/$(plat)/$(arch)/lib")
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_UTILS_ENABLE_MYSQL", get_config("mysql") and 1 or 0)
add_options("log_name", "log_level", "spend_time", "sqlcipher", "sqlite", "mysql", "ini_parser",
"datetime", "stacktrace", "async_log", "leak_check")
add_packages("fmt", "spdlog", "boost", "yas")
add_includedirs(".")
if get_config("sqlcipher") then
add_packages("sqlcipher")
elseif get_config("sqlite") then
if is_plat("windows", "android", "cross") then
add_packages("sqlite3")
elseif is_plat("linux", "cross") then
add_links("sqlite3")
elseif is_plat("macosx", "iphoneos") then
add_links("sqlite3")
end
if is_plat("cross") then
add_syslinks("dl")
end
end
if get_config("mysql") then
add_packages("mysql")
end
if is_plat("linux", "cross") then
add_rpathdirs("$ORIGIN")
end
if is_plat("macosx") then
add_includedirs("/usr/local/include")
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_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)", "$(projectdir)/(hikyuu/**.hpp)")
add_files("hikyuu/utilities/*.cpp")
add_files("hikyuu/utilities/thread/*.cpp")
add_files("hikyuu/utilities/db_connect/*.cpp")
if get_config("sqlite") then
add_files("hikyuu/utilities/db_connect/sqlite/*.cpp")
end
if get_config("mysql") then
add_files("hikyuu/utilities/db_connect/mysql/*.cpp")
end
if get_config("ini_parser") then
add_files("hikyuu/utilities/ini_parser/*.cpp")
end
if get_config("datetime") then
add_files("hikyuu/utilities/datetime/*.cpp")
end
before_build(function(target)
local function has_flag(flag)
for _, name in ipairs(target:get("cxflags")) do
if name == flag then
return true
end
end
return false
end
-- 如果没有指定c++标准,设为最低要求 c++11
if not has_flag("-std") then
if is_plat("windows") then
target:set("languages", "cxx17")
else
target:set("languages", "cxx11")
end
end
if is_plat("macosx") then
if not os.exists("/usr/local/include/mysql") then
if os.exists("/usr/local/mysql/include") then
os.run("ln -s /usr/local/mysql/include /usr/local/include/mysql")
else
print("Not Found MySQL include dir!")
end
end
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, true)
end)
target_end()
includes("copy_dependents.lua")
includes("./test")