5 -- set xmake minimum version
9 set_version("0.1.9", { build
= "%Y%m%d" })
16 set_description("Enable/Disable c++")
23 set_description("Enable/Disable warnings")
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")
33 add_cflags("-Wno-declaration-after-statement")
34 add_cxxflags("-Wno-c++98-compat-pedantic")
35 add_cxflags("-Wno-unsafe-buffer-usage")
39 add_rules("mode.check", "mode.debug", "mode.release")
40 if is_mode("check") and not is_plat("mingw") then
42 "-fsanitize=address,leak",
43 "-fsanitize=address,undefined",
44 "-fsanitize-recover=all",
45 "-fno-omit-frame-pointer",
56 set_values("4", "8", "16")
57 set_description("floating-point number bytes")
64 set_description("dynamic library search path")
67 if xmake
.version():ge("2.8.5") then
68 includes("@builtin/check")
70 includes("check_csnippets.lua")
71 includes("check_cincludes.lua")
72 includes("check_cfuncs.lua")
75 configvar_check_sizeof
= configvar_check_sizeof
76 or function(define_name
, type_name
)
77 configvar_check_csnippets(
79 'printf("%u", sizeof(' .. type_name
.. "));return 0;",
80 { output
= true, number = true }
85 -- make as a collection of objects
87 -- detect c code functions
88 configvar_check_sizeof("A_SIZE_POINTER", "void *")
89 configvar_check_csnippets(
91 'int x = 1; puts(*(char *)&x ? "1234" : "4321");',
92 { output
= true, number = true }
94 float
= get_config("liba-float")
95 function check_math(funcs
, opt
)
96 for i
, func
in pairs(funcs
) do
97 local have
= "A_HAVE_" .. string.upper(func
)
104 configvar_check_cfuncs(have
, func
, opt
)
107 local funcs
= { "expm1", "log1p", "hypot", "atan2" }
108 check_math(funcs
, { includes
= "math.h" })
110 local funcs
= { "csqrt",
111 "cpow", "cexp", "clog",
112 "csin", "ccos", "ctan",
113 "csinh", "ccosh", "ctanh",
114 "casin", "cacos", "catan",
115 "casinh", "cacosh", "catanh",
117 check_math(funcs
, { includes
= "complex.h" })
118 -- set the auto-generated a.xmake.h
119 a_have_h
= path
.relative(os
.projectdir() .. "/$(buildir)/a.xmake.h", "include/a")
120 add_defines('A_HAVE_H="' .. a_have_h
.. '"', { public
= true })
121 set_configvar("XMAKE_VERSION", tostring(xmake
.version()))
122 set_configvar("A_SIZE_FLOAT", float
, { quote
= false })
123 add_configfiles("include/a.xmake.h.in")
124 -- add include directories
125 add_includedirs("include", { public
= true })
126 -- set export library symbols
127 add_defines("A_EXPORTS")
128 -- add the common source files
129 add_files("src/**.c")
130 if not table.empty(os
.files("src/**.cc")) and has_config("liba-cxx") then
131 add_files("src/**.cc")
133 -- add the platform options
134 rpath
= get_config("liba-rpath")
136 add_linkdirs(rpath
, { public
= true })
137 add_rpathdirs(rpath
, { public
= true })
139 if not is_plat("windows", "mingw") then
140 add_syslinks("m", { public
= true })
143 after_build(function(target
)
144 import("core.tool.linker")
145 local object
= target
:objectfiles()
146 local output
= path
.join(target
:targetdir(), "liba.o")
147 local program
= linker
.linkargv("binary", "cc", object
, output
, { target
= target
})
150 os
.runv(program
, table.join("-nostdlib", "-o", output
, "-r", object
))
154 after_install(function(target
)
155 local output
= path
.join(target
:installdir(), "lib", "liba.o")
156 os
.trycp(path
.join(target
:targetdir(), "liba.o"), output
)
158 after_clean(function(target
)
159 os
.tryrm(path
.join(target
:targetdir(), "liba.o"))
165 -- make as a static library
167 -- add the header files for installing
168 add_headerfiles("include/(**.h)")
169 add_headerfiles("$(buildir)/a.xmake.h", { prefixdir
= "a" })
170 if not table.empty(os
.files("include/**.hpp")) and has_config("liba-cxx") then
171 add_headerfiles("include/(**.hpp)")
173 on_load(function(target
)
174 target
:set("links", target
:targetfile(), { interface
= true })
176 after_install(function(target
)
177 if target
:installdir() then
178 local cur
= "#if defined(A_HAVE_H)"
179 local new
= '#include "a.xmake.h"\n' .. cur
180 local includedir
= path
.join(target
:installdir(), "include")
181 io
.replace(path
.join(includedir
, "a", "a.h"), cur
, new
, { plain
= true })
184 -- add the dependent target
189 -- make as a shared library
191 -- add the platform options
192 if not is_plat("windows") then
193 set_prefixname("lib")
196 on_load(function(target
)
197 local liba
= target
:targetfile()
198 if target
:is_plat("windows") then
199 liba
= liba
:gsub(".dll", ".lib")
200 elseif target
:is_plat("mingw") then
203 target
:set("links", liba
, { interface
= true })
205 add_defines("A_IMPORTS", { interface
= true })
206 -- add the dependent target
215 set_description("Enable/Disable rust")
218 if has_config("liba-rust") then
223 add_files("src/lib.rs")
224 if get_config("liba-float") == "4" then
225 add_rcflags('--cfg=feature="float"')
230 -- include module sources
231 if not table.empty(os
.files("*/xmake.lua")) then
232 includes("*/xmake.lua")