5 -- set xmake minimum version
9 set_version("0.1.14", { 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,undefined",
43 "-fsanitize=address,leak",
44 "-fsanitize-recover=all",
45 "-fno-omit-frame-pointer",
57 set_values("4", "8", "16")
58 set_description("floating-point number bytes")
66 set_description("dynamic library search path")
69 if xmake
.version():ge("2.8.5") then
70 includes("@builtin/check")
72 includes("check_csnippets.lua")
73 includes("check_cincludes.lua")
74 includes("check_cfuncs.lua")
77 configvar_check_sizeof
= configvar_check_sizeof
78 or function(define_name
, type_name
)
79 configvar_check_csnippets(
81 'printf("%u", sizeof(' .. type_name
.. "));return 0;",
82 { output
= true, number = true }
87 -- make as a collection of objects
89 -- detect c code functions
90 configvar_check_sizeof("A_SIZE_POINTER", "void *")
91 configvar_check_csnippets(
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
106 configvar_check_cfuncs(have
, func
, opt
)
109 local funcs
= { "expm1", "log1p", "hypot", "atan2" }
110 check_math(funcs
, { includes
= "math.h" })
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*"))
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 })
150 -- make as a static library
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*)")
157 add_headerfiles("include/(a/**.h)")
159 on_load(function(target
)
160 target
:set("links", target
:targetfile(), { interface
= true })
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 })
170 -- add the dependent target
175 -- make as a shared library
177 -- add the platform options
178 if not is_plat("windows") then
179 set_prefixname("lib")
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
189 target
:set("links", liba
, { interface
= true })
191 add_defines("A_IMPORTS", { interface
= true })
192 -- add the dependent target
201 set_description("Enable/Disable Rust")
204 if has_config("liba-rust") then
208 add_files("src/lib.rs")
209 if get_config("liba-float") == "4" then
210 add_rcflags('--cfg=feature="float"')
216 -- include module sources
217 if not table.empty(os
.files("*/xmake.lua")) then
218 includes("*/xmake.lua")