Browse Source

fix header distribution of headeronly project

V2-origin
Zhicheng Wang 5 days ago
parent
commit
56b5259a37
  1. 2
      shared_module/xmake.lua
  2. 22
      xmake/rules/library/shared/xmake.lua

2
shared_module/xmake.lua

@ -9,5 +9,5 @@ target("shared_module")
set_kind("headeronly")
add_includedirs("./", {public = true})
add_packages("mimalloc", "parallel-hashmap", "range-v3", "eigen-latest", "xxhash", {public = true})
add_rules("library.force.distribute.header", {headers = path.join(os.scriptdir(), "math", "math_defs.h")})
add_rules("library.headeronly.distribute.header", {projectdir = os.scriptdir()})
target_end()

22
xmake/rules/library/shared/xmake.lua

@ -18,8 +18,9 @@ rule_end()
rule("library.distribute.header")
after_build(function (target)
local projectdir = target:extraconf("rules", "library.distribute.header", "projectdir")
local outputdir = path.join(target:targetdir(), "..", "include")
local outputdir = path.join(os.projectdir(), "distribute", "include")
if has_config("shipping_one") then
print("Distributing header files for project: " .. target:name())
for _, filepath in ipairs(os.files(path.join(projectdir, "interface", "*.h"))) do
local file = io.readfile(filepath)
@ -32,6 +33,7 @@ rule("library.distribute.header")
local replace_api2 = string.gsub(replace_api1, "API", "__declspec(dllimport)")
io.writefile(path.join(outputdir, path.filename(filepath)), replace_api2)
print("Distributed header file: " .. path.filename(filepath))
end
end
end)
@ -40,8 +42,9 @@ rule_end()
rule("library.force.distribute.header")
after_build(function (target)
local headers = target:extraconf("rules", "library.force.distribute.header", "headers")
local outputdir = path.join(target:targetdir(), "..", "include")
local outputdir = path.join(os.projectdir(), "distribute", "include")
if has_config("shipping_one") then
print("Forcing distribution of header files: " .. headers)
for _, filepath in ipairs(os.files(headers)) do
local file = io.readfile(filepath)
@ -54,6 +57,21 @@ rule("library.force.distribute.header")
local replace_api2 = string.gsub(replace_api1, "API", "__declspec(dllimport)")
io.writefile(path.join(outputdir, path.filename(filepath)), replace_api2)
print("Forced distribution of header file: " .. path.filename(filepath))
end
end
end)
rule_end()
rule("library.headeronly.distribute.header")
on_build(function (target)
print("Distributing header files for header-only library: " .. target:name())
local projectdir = target:extraconf("rules", "library.headeronly.distribute.header", "projectdir")
local outputdir = path.join(os.projectdir(), "distribute", "include")
if has_config("shipping_one") then
for _, filepath in ipairs(os.files(path.join(projectdir, "**", "*.h"))) do
os.cp(filepath, outputdir)
print("Distributed header file: " .. path.filename(filepath))
end
end
end)

Loading…
Cancel
Save