rename a_pid_fuzzy.op to a_pid_fuzzy.opr
[liba.git] / xmake.lua
blob3674f4eb4dc9d68f690b2fa45b48ef99c2e23622
1 ---@diagnostic disable
2 -- set project name
3 set_project("liba")
5 -- set xmake minimum version
6 set_xmakever("2.5.0")
8 -- set project version
9 set_version("0.1.14", { build = "%Y%m%d" })
11 -- option: liba-cxx
12 option("liba-cxx")
13 set_default(true)
14 set_showmenu(true)
15 set_category("liba")
16 set_description("Enable/Disable C++")
17 option_end()
19 -- option: warning
20 option("warning")
21 set_default(false)
22 set_showmenu(true)
23 set_description("Enable/Disable warnings")
24 option_end()
26 if has_config("warning") then
27 -- set warning everything
28 set_warnings("everything")
29 -- disable some compiler errors
30 if is_plat("windows") then
31 add_cxflags("/wd4464", "/wd4514", "/wd4710", "/wd4711", "/wd4820", "/wd5039", "/wd5045")
32 end
33 add_cflags("-Wno-declaration-after-statement")
34 add_cxxflags("-Wno-c++98-compat-pedantic")
35 add_cxflags("-Wno-unsafe-buffer-usage")
36 end
38 -- add build modes
39 add_rules("mode.check", "mode.debug", "mode.release")
40 if is_mode("check") and not is_plat("mingw") then
41 local flags = {
42 "-fsanitize=address,undefined",
43 "-fsanitize=address,leak",
44 "-fsanitize-recover=all",
45 "-fno-omit-frame-pointer",
47 add_cxflags(flags)
48 add_shflags(flags)
49 add_ldflags(flags)
50 end
52 -- option: float
53 option("liba-float")
54 set_default("8")
55 set_showmenu(true)
56 set_category("liba")
57 set_values("4", "8", "16")
58 set_description("floating-point number bytes")
59 option_end()
61 -- option: rpath
62 option("liba-rpath")
63 set_default("")
64 set_showmenu(true)
65 set_category("liba")
66 set_description("dynamic library search path")
67 option_end()
69 if xmake.version():ge("2.8.5") then
70 includes("@builtin/check")
71 else
72 includes("check_csnippets.lua")
73 includes("check_cincludes.lua")
74 includes("check_cfuncs.lua")
75 end
77 configvar_check_sizeof = configvar_check_sizeof
78 or function(define_name, type_name)
79 configvar_check_csnippets(
80 define_name,
81 'printf("%u", sizeof(' .. type_name .. "));return 0;",
82 { output = true, number = true }
84 end
86 target("a")
87 -- make as a collection of objects
88 set_kind("object")
89 -- detect c code functions
90 configvar_check_sizeof("A_SIZE_POINTER", "void *")
91 configvar_check_csnippets(
92 "A_BYTE_ORDER",
93 'int x = 1; puts(*(char *)&x ? "1234" : "4321");',
94 { output = true, number = true }
96 float = get_config("liba-float")
97 function check_math(funcs, opt)
98 for i, func in pairs(funcs) do
99 local have = "A_HAVE_" .. string.upper(func)
100 if float == "16" then
101 func = func .. "l"
103 if float == "4" then
104 func = func .. "f"
106 configvar_check_cfuncs(have, func, opt)
109 local funcs = { "expm1", "log1p", "hypot", "atan2" }
110 check_math(funcs, { includes = "math.h" })
111 -- stylua: ignore
112 local funcs = { "csqrt",
113 "cpow", "cexp", "clog",
114 "csin", "ccos", "ctan",
115 "csinh", "ccosh", "ctanh",
116 "casin", "cacos", "catan",
117 "casinh", "cacosh", "catanh",
119 check_math(funcs, { includes = "complex.h" })
120 -- set the auto-generated a.xmake.h
121 a_have_h = path.relative(os.projectdir() .. "/$(buildir)/a.xmake.h", "include/a")
122 add_defines('A_HAVE_H="' .. a_have_h .. '"', { public = true })
123 set_configvar("XMAKE_VERSION", tostring(xmake.version()))
124 set_configvar("A_SIZE_FLOAT", float, { quote = false })
125 add_configfiles("include/a.xmake.h.in")
126 -- add include directories
127 add_includedirs("include", { public = true })
128 -- set export library symbols
129 add_defines("A_EXPORTS")
130 -- add the common source files
131 if has_config("liba-cxx") then
132 add_files(os.files("src/**.c*"))
133 else
134 add_files("src/**.c")
136 -- add the platform options
137 rpath = get_config("liba-rpath")
138 if rpath and path.is_absolute(rpath) then
139 add_linkdirs(rpath, { public = true })
140 add_rpathdirs(rpath, { public = true })
142 if not is_plat("windows", "mingw") then
143 add_syslinks("m", { public = true })
144 add_cxflags("-fPIC")
146 target_end()
148 target("alib")
149 set_basename("a")
150 -- make as a static library
151 set_kind("static")
152 -- add the header files for installing
153 add_headerfiles("$(buildir)/a.xmake.h", { prefixdir = "a" })
154 if has_config("liba-cxx") then
155 add_headerfiles("include/(a/**.h*)")
156 else
157 add_headerfiles("include/(a/**.h)")
159 on_load(function(target)
160 target:set("links", target:targetfile(), { interface = true })
161 end)
162 after_install(function(target)
163 if target:installdir() then
164 local cur = "#if defined(A_HAVE_H)"
165 local new = '#include "a.xmake.h"\n' .. cur
166 local includedir = path.join(target:installdir(), "include")
167 io.replace(path.join(includedir, "a", "a.h"), cur, new, { plain = true })
169 end)
170 -- add the dependent target
171 add_deps("a")
172 target_end()
174 target("liba")
175 -- make as a shared library
176 set_kind("shared")
177 -- add the platform options
178 if not is_plat("windows") then
179 set_prefixname("lib")
180 set_basename("a")
182 on_load(function(target)
183 local liba = target:targetfile()
184 if target:is_plat("windows") then
185 liba = liba:gsub(".dll", ".lib")
186 elseif target:is_plat("mingw") then
187 liba = liba .. ".a"
189 target:set("links", liba, { interface = true })
190 end)
191 add_defines("A_IMPORTS", { interface = true })
192 -- add the dependent target
193 add_deps("a")
194 target_end()
196 -- option: liba-rust
197 option("liba-rust")
198 set_default(false)
199 set_showmenu(true)
200 set_category("liba")
201 set_description("Enable/Disable Rust")
202 option_end()
204 if has_config("liba-rust") then
205 target("ars")
206 set_kind("static")
207 set_basename("liba")
208 add_files("src/lib.rs")
209 if get_config("liba-float") == "4" then
210 add_rcflags('--cfg=feature="float"')
212 add_deps("a")
213 target_end()
216 -- include module sources
217 if not table.empty(os.files("*/xmake.lua")) then
218 includes("*/xmake.lua")