summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-07-16 00:48:07 +0800
committerruki <[email protected]>2024-07-16 00:48:07 +0800
commit81640975b434a293cabed7d758c599a2668a6efe (patch)
tree096b579eccee306b51580a3335273f4582e7741c
parent2396ca21342a288b9f0d972f479763847709d3a3 (diff)
improve to install headerfiles
-rw-r--r--tests/actions/install/xmake.lua1
-rw-r--r--xmake/modules/target/action/install/main.lua31
-rw-r--r--xmake/modules/target/action/uninstall/main.lua9
-rw-r--r--xmake/plugins/pack/batchcmds.lua30
4 files changed, 38 insertions, 33 deletions
diff --git a/tests/actions/install/xmake.lua b/tests/actions/install/xmake.lua
index 3061cab86..b774e9e27 100644
--- a/tests/actions/install/xmake.lua
+++ b/tests/actions/install/xmake.lua
@@ -8,6 +8,7 @@ target("foo")
set_kind("shared")
add_files("src/foo.cpp")
add_packages("libplist", {public = true})
+ add_headerfiles("src/foo.h", {public = true})
add_installfiles("src/foo.txt", {prefixdir = "assets", public = true})
set_prefixdir("/", {bindir = "foo_bin", libdir = "foo_lib"})
diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua
index a8acaf5a7..3c1a12a8e 100644
--- a/xmake/modules/target/action/install/main.lua
+++ b/xmake/modules/target/action/install/main.lua
@@ -68,30 +68,35 @@ end
-- install files
function _install_files(target)
local srcfiles, dstfiles = target:installfiles()
- for idx, srcfile in ipairs(srcfiles) do
- os.vcp(srcfile, dstfiles[idx])
+ if srcfiles and dstfiles then
+ for idx, srcfile in ipairs(srcfiles) do
+ os.vcp(srcfile, dstfiles[idx])
+ end
end
for _, dep in ipairs(target:orderdeps()) do
local srcfiles, dstfiles = dep:installfiles(dep:installdir(), {interface = true})
- for idx, srcfile in ipairs(srcfiles) do
- os.vcp(srcfile, dstfiles[idx])
+ if srcfiles and dstfiles then
+ for idx, srcfile in ipairs(srcfiles) do
+ os.vcp(srcfile, dstfiles[idx])
+ end
end
end
end
-- install headers
function _install_headers(target, opt)
- local includedir = target:includedir()
- os.mkdir(includedir)
- local srcheaders, dstheaders = target:headerfiles(includedir, {installonly = true})
+ local srcheaders, dstheaders = target:headerfiles(target:includedir(), {installonly = true})
if srcheaders and dstheaders then
- local i = 1
- for _, srcheader in ipairs(srcheaders) do
- local dstheader = dstheaders[i]
- if dstheader then
- os.vcp(srcheader, dstheader)
+ for idx, srcheader in ipairs(srcheaders) do
+ os.vcp(srcheader, dstheaders[idx])
+ end
+ end
+ for _, dep in ipairs(target:orderdeps()) do
+ local srcfiles, dstfiles = dep:headerfiles(dep:includedir(), {installonly = true, interface = true})
+ if srcfiles and dstfiles then
+ for idx, srcfile in ipairs(srcfiles) do
+ os.vcp(srcfile, dstfiles[idx])
end
- i = i + 1
end
end
end
diff --git a/xmake/modules/target/action/uninstall/main.lua b/xmake/modules/target/action/uninstall/main.lua
index d3fa34585..73c28f02c 100644
--- a/xmake/modules/target/action/uninstall/main.lua
+++ b/xmake/modules/target/action/uninstall/main.lua
@@ -77,11 +77,16 @@ end
-- uninstall headers
function _uninstall_headers(target, opt)
- local includedir = target:includedir()
- local _, dstheaders = target:headerfiles(includedir, {installonly = true})
+ local _, dstheaders = target:headerfiles(target:includedir(), {installonly = true})
for _, dstheader in ipairs(dstheaders) do
remove_files(dstheader, {emptydir = true})
end
+ for _, dep in ipairs(target:orderdeps()) do
+ local _, dstfiles = dep:headerfiles(dep:includedir(), {installonly = true, interface = true})
+ for _, dstfile in ipairs(dstfiles) do
+ remove_files(dstfile, {emptydir = true})
+ end
+ end
end
-- uninstall shared libraries
diff --git a/xmake/plugins/pack/batchcmds.lua b/xmake/plugins/pack/batchcmds.lua
index b1721bf10..26ab4f7b0 100644
--- a/xmake/plugins/pack/batchcmds.lua
+++ b/xmake/plugins/pack/batchcmds.lua
@@ -104,13 +104,17 @@ end
function _install_target_files(target, batchcmds_, opt)
local package = opt.package
local srcfiles, dstfiles = target:installfiles(_get_target_installdir(package, target))
- for idx, srcfile in ipairs(srcfiles) do
- batchcmds_:cp(srcfile, dstfiles[idx])
+ if srcfiles and dstfiles then
+ for idx, srcfile in ipairs(srcfiles) do
+ batchcmds_:cp(srcfile, dstfiles[idx])
+ end
end
for _, dep in ipairs(target:orderdeps()) do
local srcfiles, dstfiles = dep:installfiles(_get_target_installdir(package, dep), {interface = true})
- for idx, srcfile in ipairs(srcfiles) do
- batchcmds_:cp(srcfile, dstfiles[idx])
+ if srcfiles and dstfiles then
+ for idx, srcfile in ipairs(srcfiles) do
+ batchcmds_:cp(srcfile, dstfiles[idx])
+ end
end
end
end
@@ -120,25 +124,15 @@ function _install_target_headers(target, batchcmds_, opt)
local package = opt.package
local srcheaders, dstheaders = target:headerfiles(_get_target_includedir(package, target), {installonly = true})
if srcheaders and dstheaders then
- local i = 1
- for _, srcheader in ipairs(srcheaders) do
- local dstheader = dstheaders[i]
- if dstheader then
- batchcmds_:cp(srcheader, dstheader)
- end
- i = i + 1
+ for idx, srcheader in ipairs(srcheaders) do
+ batchcmds_:cp(srcheader, dstheaders[idx])
end
end
for _, dep in ipairs(target:orderdeps()) do
local srcheaders, dstheaders = dep:headerfiles(_get_target_includedir(package, dep), {installonly = true, interface = true})
if srcheaders and dstheaders then
- local i = 1
- for _, srcheader in ipairs(srcheaders) do
- local dstheader = dstheaders[i]
- if dstheader then
- batchcmds_:cp(srcheader, dstheader)
- end
- i = i + 1
+ for idx, srcheader in ipairs(srcheaders) do
+ batchcmds_:cp(srcheader, dstheaders[idx])
end
end
end