-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxmake.lua
219 lines (203 loc) · 5.67 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
---@diagnostic disable
-- set project name
set_project("liba")
-- set xmake minimum version
set_xmakever("2.5.0")
-- set project version
set_version("0.1.15", { build = "%Y%m%d" })
-- option: liba-cxx
option("liba-cxx")
set_default(true)
set_showmenu(true)
set_category("liba")
set_description("Enable/Disable C++")
option_end()
-- option: warning
option("warning")
set_default(false)
set_showmenu(true)
set_description("Enable/Disable warnings")
option_end()
if has_config("warning") then
-- set warning everything
set_warnings("everything")
-- disable some compiler errors
if is_plat("windows") then
add_cxflags("/wd4464", "/wd4514", "/wd4710", "/wd4711", "/wd4820", "/wd5039", "/wd5045")
end
add_cflags("-Wno-declaration-after-statement")
add_cxxflags("-Wno-c++98-compat-pedantic")
add_cxflags("-Wno-unsafe-buffer-usage")
end
-- add build modes
add_rules("mode.check", "mode.debug", "mode.release")
if is_mode("check") and not is_plat("mingw") then
local flags = {
"-fsanitize=address,undefined",
"-fsanitize=address,leak",
"-fsanitize-recover=all",
"-fno-omit-frame-pointer",
}
add_cxflags(flags)
add_shflags(flags)
add_ldflags(flags)
end
-- option: real
option("liba-real")
set_default("8")
set_showmenu(true)
set_category("liba")
set_values("4", "8", "16")
set_description("floating-point number bytes")
option_end()
-- option: rpath
option("liba-rpath")
set_default("")
set_showmenu(true)
set_category("liba")
set_description("dynamic library search path")
option_end()
if xmake.version():ge("2.8.5") then
includes("@builtin/check")
else
includes("check_csnippets.lua")
includes("check_cincludes.lua")
includes("check_cfuncs.lua")
end
configvar_check_sizeof = configvar_check_sizeof
or function(define_name, type_name)
configvar_check_csnippets(
define_name,
'printf("%u", sizeof(' .. type_name .. "));return 0;",
{ output = true, number = true }
)
end
target("a")
-- make as a collection of objects
set_kind("object")
-- detect c code functions
configvar_check_sizeof("A_SIZE_POINTER", "void *")
configvar_check_csnippets(
"A_BYTE_ORDER",
'int x = 1; puts(*(char *)&x ? "1234" : "4321");',
{ output = true, number = true }
)
real = get_config("liba-real")
function check_math(funcs, opt)
for i, func in pairs(funcs) do
local have = "A_HAVE_" .. string.upper(func)
if real == "16" then
func = func .. "l"
end
if real == "4" then
func = func .. "f"
end
configvar_check_cfuncs(have, func, opt)
end
end
local funcs = { "asinh", "acosh", "atanh", "expm1", "log1p", "atan2", "hypot" }
check_math(funcs, { includes = "math.h" })
-- stylua: ignore
local funcs = { "csqrt",
"cpow", "cexp", "clog",
"csin", "ccos", "ctan",
"csinh", "ccosh", "ctanh",
"casin", "cacos", "catan",
"casinh", "cacosh", "catanh",
}
check_math(funcs, { includes = "complex.h" })
-- set the auto-generated a.xmake.h
a_have_h = path.relative(os.projectdir() .. "/$(buildir)/a.xmake.h", "include/a")
add_defines('A_HAVE_H="' .. a_have_h .. '"', { public = true })
set_configvar("XMAKE_VERSION", tostring(xmake.version()))
set_configvar("A_SIZE_REAL", real, { quote = false })
add_configfiles("include/a.xmake.h.in")
-- add include directories
add_includedirs("include", { public = true })
-- set export library symbols
add_defines("A_EXPORTS")
-- add the common source files
if has_config("liba-cxx") then
add_files(os.files("src/**.c*"))
else
add_files("src/**.c")
end
-- add the platform options
rpath = get_config("liba-rpath")
if rpath and path.is_absolute(rpath) then
add_linkdirs(rpath, { public = true })
add_rpathdirs(rpath, { public = true })
end
if not is_plat("windows", "mingw") then
add_syslinks("m", { public = true })
add_cxflags("-fPIC")
end
target_end()
target("alib")
set_basename("a")
-- make as a static library
set_kind("static")
-- add the header files for installing
add_headerfiles("$(buildir)/a.xmake.h", { prefixdir = "a" })
if has_config("liba-cxx") then
add_headerfiles("include/(a/**.h*)")
else
add_headerfiles("include/(a/**.h)")
end
on_load(function(target)
target:set("links", target:targetfile(), { interface = true })
end)
after_install(function(target)
if target:installdir() then
local cur = "#if defined(A_HAVE_H)"
local new = '#include "a.xmake.h"\n' .. cur
local includedir = path.join(target:installdir(), "include")
io.replace(path.join(includedir, "a", "a.h"), cur, new, { plain = true })
end
end)
-- add the dependent target
add_deps("a")
target_end()
target("liba")
-- make as a shared library
set_kind("shared")
-- add the platform options
if not is_plat("windows") then
set_prefixname("lib")
set_basename("a")
end
on_load(function(target)
local liba = target:targetfile()
if target:is_plat("windows") then
liba = liba:gsub(".dll", ".lib")
elseif target:is_plat("mingw") then
liba = liba .. ".a"
end
target:set("links", liba, { interface = true })
end)
add_defines("A_IMPORTS", { interface = true })
-- add the dependent target
add_deps("a")
target_end()
-- option: liba-rust
option("liba-rust")
set_default(false)
set_showmenu(true)
set_category("liba")
set_description("Enable/Disable Rust")
option_end()
if has_config("liba-rust") then
target("ars")
set_kind("static")
set_basename("liba")
add_files("src/lib.rs")
if get_config("liba-real") == "4" then
add_rcflags('--cfg=feature="float"')
end
add_deps("a")
target_end()
end
-- include module sources
if not table.empty(os.files("*/xmake.lua")) then
includes("*/xmake.lua")
end