2023-11-28 21:11:48 +08:00
|
|
|
---@diagnostic disable
|
2023-03-17 21:35:38 +08:00
|
|
|
-- set project name
|
|
|
|
set_project("liba")
|
|
|
|
|
|
|
|
-- set xmake minimum version
|
|
|
|
set_xmakever("2.5.0")
|
|
|
|
|
|
|
|
-- set project version
|
2024-09-30 22:42:08 +08:00
|
|
|
set_version("0.1.15", { build = "%Y%m%d" })
|
2023-03-17 21:35:38 +08:00
|
|
|
|
2023-04-20 18:41:43 +08:00
|
|
|
-- option: liba-cxx
|
|
|
|
option("liba-cxx")
|
2023-08-28 22:53:53 +08:00
|
|
|
set_default(true)
|
|
|
|
set_showmenu(true)
|
|
|
|
set_category("liba")
|
2024-04-06 20:00:55 +08:00
|
|
|
set_description("Enable/Disable C++")
|
2023-03-17 21:35:38 +08:00
|
|
|
option_end()
|
|
|
|
|
|
|
|
-- option: warning
|
|
|
|
option("warning")
|
2023-08-28 22:53:53 +08:00
|
|
|
set_default(false)
|
|
|
|
set_showmenu(true)
|
|
|
|
set_description("Enable/Disable warnings")
|
2023-03-17 21:35:38 +08:00
|
|
|
option_end()
|
|
|
|
|
|
|
|
if has_config("warning") then
|
|
|
|
-- set warning everything
|
|
|
|
set_warnings("everything")
|
|
|
|
-- disable some compiler errors
|
|
|
|
if is_plat("windows") then
|
2023-12-02 18:53:07 +08:00
|
|
|
add_cxflags("/wd4464", "/wd4514", "/wd4710", "/wd4711", "/wd4820", "/wd5039", "/wd5045")
|
2023-03-17 21:35:38 +08:00
|
|
|
end
|
|
|
|
add_cflags("-Wno-declaration-after-statement")
|
|
|
|
add_cxxflags("-Wno-c++98-compat-pedantic")
|
2023-04-17 05:06:30 +08:00
|
|
|
add_cxflags("-Wno-unsafe-buffer-usage")
|
2023-03-17 21:35:38 +08:00
|
|
|
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",
|
2024-05-11 21:17:23 +08:00
|
|
|
"-fsanitize=address,leak",
|
2024-04-06 13:26:07 +08:00
|
|
|
"-fsanitize-recover=all",
|
2023-03-17 21:35:38 +08:00
|
|
|
"-fno-omit-frame-pointer",
|
|
|
|
}
|
|
|
|
add_cxflags(flags)
|
2024-05-13 13:33:09 +08:00
|
|
|
add_shflags(flags)
|
2023-03-17 21:35:38 +08:00
|
|
|
add_ldflags(flags)
|
|
|
|
end
|
|
|
|
|
2023-05-24 17:42:07 +08:00
|
|
|
-- option: float
|
|
|
|
option("liba-float")
|
2023-08-28 22:53:53 +08:00
|
|
|
set_default("8")
|
|
|
|
set_showmenu(true)
|
|
|
|
set_category("liba")
|
|
|
|
set_values("4", "8", "16")
|
|
|
|
set_description("floating-point number bytes")
|
2023-03-17 21:35:38 +08:00
|
|
|
option_end()
|
|
|
|
|
|
|
|
-- option: rpath
|
2023-04-20 18:41:43 +08:00
|
|
|
option("liba-rpath")
|
2024-05-09 23:15:20 +08:00
|
|
|
set_default("")
|
2023-08-28 22:53:53 +08:00
|
|
|
set_showmenu(true)
|
|
|
|
set_category("liba")
|
|
|
|
set_description("dynamic library search path")
|
2023-03-17 21:35:38 +08:00
|
|
|
option_end()
|
|
|
|
|
2023-12-02 18:53:07 +08:00
|
|
|
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
|
|
|
|
|
2023-04-17 04:47:51 +08:00
|
|
|
target("a")
|
2023-08-28 22:53:53 +08:00
|
|
|
-- make as a collection of objects
|
|
|
|
set_kind("object")
|
|
|
|
-- detect c code functions
|
2023-12-02 18:53:07 +08:00
|
|
|
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 }
|
|
|
|
)
|
2024-01-13 16:16:58 +08:00
|
|
|
float = get_config("liba-float")
|
2023-08-28 22:53:53 +08:00
|
|
|
function check_math(funcs, opt)
|
|
|
|
for i, func in pairs(funcs) do
|
|
|
|
local have = "A_HAVE_" .. string.upper(func)
|
|
|
|
if float == "16" then
|
|
|
|
func = func .. "l"
|
2023-03-17 21:35:38 +08:00
|
|
|
end
|
2023-08-28 22:53:53 +08:00
|
|
|
if float == "4" then
|
|
|
|
func = func .. "f"
|
|
|
|
end
|
|
|
|
configvar_check_cfuncs(have, func, opt)
|
2023-03-17 21:35:38 +08:00
|
|
|
end
|
2023-08-28 22:53:53 +08:00
|
|
|
end
|
2024-01-20 22:37:02 +08:00
|
|
|
local funcs = { "expm1", "log1p", "hypot", "atan2" }
|
2023-08-28 22:53:53 +08:00
|
|
|
check_math(funcs, { includes = "math.h" })
|
|
|
|
-- stylua: ignore
|
2024-01-20 22:37:02 +08:00
|
|
|
local funcs = { "csqrt",
|
2023-08-28 22:53:53 +08:00
|
|
|
"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_FLOAT", float, { 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
|
2024-04-20 19:22:59 +08:00
|
|
|
if has_config("liba-cxx") then
|
|
|
|
add_files(os.files("src/**.c*"))
|
|
|
|
else
|
|
|
|
add_files("src/**.c")
|
2023-08-28 22:53:53 +08:00
|
|
|
end
|
|
|
|
-- add the platform options
|
|
|
|
rpath = get_config("liba-rpath")
|
2024-05-09 23:15:20 +08:00
|
|
|
if rpath and path.is_absolute(rpath) then
|
2023-08-28 22:53:53 +08:00
|
|
|
add_linkdirs(rpath, { public = true })
|
2024-01-13 16:16:58 +08:00
|
|
|
add_rpathdirs(rpath, { public = true })
|
2023-08-28 22:53:53 +08:00
|
|
|
end
|
|
|
|
if not is_plat("windows", "mingw") then
|
|
|
|
add_syslinks("m", { public = true })
|
|
|
|
add_cxflags("-fPIC")
|
|
|
|
end
|
2023-03-17 21:35:38 +08:00
|
|
|
target_end()
|
|
|
|
|
2023-04-17 04:47:51 +08:00
|
|
|
target("alib")
|
2023-08-28 22:53:53 +08:00
|
|
|
set_basename("a")
|
|
|
|
-- make as a static library
|
|
|
|
set_kind("static")
|
|
|
|
-- add the header files for installing
|
2024-01-13 16:16:58 +08:00
|
|
|
add_headerfiles("$(buildir)/a.xmake.h", { prefixdir = "a" })
|
2024-04-20 19:22:59 +08:00
|
|
|
if has_config("liba-cxx") then
|
|
|
|
add_headerfiles("include/(a/**.h*)")
|
|
|
|
else
|
|
|
|
add_headerfiles("include/(a/**.h)")
|
2023-08-28 22:53:53 +08:00
|
|
|
end
|
2024-01-13 16:16:58 +08:00
|
|
|
on_load(function(target)
|
|
|
|
target:set("links", target:targetfile(), { interface = true })
|
|
|
|
end)
|
2023-08-28 22:53:53 +08:00
|
|
|
after_install(function(target)
|
|
|
|
if target:installdir() then
|
2024-02-25 20:32:25 +08:00
|
|
|
local cur = "#if defined(A_HAVE_H)"
|
|
|
|
local new = '#include "a.xmake.h"\n' .. cur
|
2023-08-28 22:53:53 +08:00
|
|
|
local includedir = path.join(target:installdir(), "include")
|
2024-02-25 20:32:25 +08:00
|
|
|
io.replace(path.join(includedir, "a", "a.h"), cur, new, { plain = true })
|
2023-03-17 21:35:38 +08:00
|
|
|
end
|
2023-08-28 22:53:53 +08:00
|
|
|
end)
|
|
|
|
-- add the dependent target
|
|
|
|
add_deps("a")
|
2023-03-17 21:35:38 +08:00
|
|
|
target_end()
|
|
|
|
|
|
|
|
target("liba")
|
2023-08-28 22:53:53 +08:00
|
|
|
-- make as a shared library
|
|
|
|
set_kind("shared")
|
|
|
|
-- add the platform options
|
2024-01-13 16:16:58 +08:00
|
|
|
if not is_plat("windows") then
|
|
|
|
set_prefixname("lib")
|
|
|
|
set_basename("a")
|
2023-08-28 22:53:53 +08:00
|
|
|
end
|
2024-01-13 16:16:58 +08:00
|
|
|
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 })
|
2023-08-28 22:53:53 +08:00
|
|
|
-- add the dependent target
|
|
|
|
add_deps("a")
|
2023-03-17 21:35:38 +08:00
|
|
|
target_end()
|
|
|
|
|
2023-04-20 18:41:43 +08:00
|
|
|
-- option: liba-rust
|
|
|
|
option("liba-rust")
|
2023-08-28 22:53:53 +08:00
|
|
|
set_default(false)
|
|
|
|
set_showmenu(true)
|
|
|
|
set_category("liba")
|
2024-04-06 20:00:55 +08:00
|
|
|
set_description("Enable/Disable Rust")
|
2023-03-17 21:35:38 +08:00
|
|
|
option_end()
|
|
|
|
|
2023-04-20 18:41:43 +08:00
|
|
|
if has_config("liba-rust") then
|
2023-05-10 05:12:00 +08:00
|
|
|
target("ars")
|
2023-08-28 22:53:53 +08:00
|
|
|
set_kind("static")
|
|
|
|
set_basename("liba")
|
|
|
|
add_files("src/lib.rs")
|
|
|
|
if get_config("liba-float") == "4" then
|
|
|
|
add_rcflags('--cfg=feature="float"')
|
|
|
|
end
|
2024-04-06 20:00:55 +08:00
|
|
|
add_deps("a")
|
2023-03-17 21:35:38 +08:00
|
|
|
target_end()
|
|
|
|
end
|
|
|
|
|
2023-04-18 02:30:02 +08:00
|
|
|
-- include module sources
|
|
|
|
if not table.empty(os.files("*/xmake.lua")) then
|
|
|
|
includes("*/xmake.lua")
|
2023-04-16 18:04:38 +08:00
|
|
|
end
|