summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSineStriker <[email protected]>2025-04-20 05:07:38 +0800
committerruki <[email protected]>2025-04-23 11:30:30 +0800
commitd57cceb19f58b99d5198cea0c32ec306ea22a9fb (patch)
tree74f5b5cd3f707887b35fea49e6621dd1ee5b34d7
parentcef17b4c566a186ba8e9dd3dc52ab44901fed9f1 (diff)
Add `set_implibdir` to target APIs
-rw-r--r--xmake/actions/package/oldpkg/main.lua17
-rw-r--r--xmake/core/project/target.lua21
-rw-r--r--xmake/core/tool/linker.lua16
-rw-r--r--xmake/modules/core/tools/gcc.lua10
-rw-r--r--xmake/modules/core/tools/link.lua8
-rw-r--r--xmake/modules/core/tools/nvcc.lua10
-rw-r--r--xmake/modules/target/action/clean/main.lua12
-rw-r--r--xmake/modules/target/action/install/main.lua6
-rw-r--r--xmake/plugins/pack/batchcmds.lua11
-rw-r--r--xmake/rules/utils/inherit_links/inherit_links.lua8
10 files changed, 58 insertions, 61 deletions
diff --git a/xmake/actions/package/oldpkg/main.lua b/xmake/actions/package/oldpkg/main.lua
index 983f187a9..54a560cb9 100644
--- a/xmake/actions/package/oldpkg/main.lua
+++ b/xmake/actions/package/oldpkg/main.lua
@@ -48,20 +48,9 @@ function _package_library(target)
-- copy *.lib for shared/windows (*.dll) target
-- @see https://github.com/xmake-io/xmake/issues/787
- if target:is_shared() then
- if target:is_plat("windows") then
- local targetfile = target:targetfile()
- local targetfile_lib = path.join(target:implibdir(), path.basename(targetfile) .. ".lib")
- if os.isfile(targetfile_lib) then
- os.vcp(targetfile_lib, format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/", outputdir, targetname))
- end
- elseif target:is_plat("mingw") then
- local targetfile = target:targetfile()
- local targetfile_lib = path.join(target:implibdir(), path.basename(targetfile) .. ".dll.a")
- if os.isfile(targetfile_lib) then
- os.vcp(targetfile_lib, format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/", outputdir, targetname))
- end
- end
+ local target_implib = target:implibfile()
+ if target_implib and os.isfile(target_implib) then
+ os.vcp(target_implib, format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/", outputdir, targetname))
end
-- copy headers
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 411822fcb..ea250b9c9 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -1611,20 +1611,22 @@ function _instance:implibdir()
return nil
end
- local targetdir = self:extraconf("targetdir") or {}
- local implibdir = nil
- for _, v in pairs(targetdir) do
- if type(v) == "table" then
- implibdir = v["implibdir"]
- end
- break
- end
+ local implibdir = self:get("implibdir")
if not implibdir then
- return self:targetdir()
+ implibdir = self:targetdir()
end
return implibdir
end
+-- get the imp-lib file (only on windows)
+function _instance:implibfile()
+ local implibdir = self:implibdir()
+ if not implibdir then
+ return nil
+ end
+ return path.join(implibdir, path.basename(self:targetfile()) .. (self:is_plat("mingw") and ".dll.a" or ".lib"))
+end
+
-- get the target file name
function _instance:filename()
@@ -2916,6 +2918,7 @@ function target.apis()
-- target.set_xxx
"target.set_targetdir"
, "target.set_objectdir"
+ , "target.set_implibdir"
, "target.set_dependir"
, "target.set_autogendir"
, "target.set_configdir"
diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua
index 451c0ac7e..a0ae27641 100644
--- a/xmake/core/tool/linker.lua
+++ b/xmake/core/tool/linker.lua
@@ -68,14 +68,14 @@ function linker:_add_flags_from_linker(flags)
end
-- add implib-dir to the options
-function linker:_add_implibdir_to_options(opt)
+function linker:_add_implib_to_options(opt)
opt = opt or {}
- if not opt.implibdir then
+ if not opt.implib then
local target = self:target()
if target:type() == "target" then
- local implibdir = target:implibdir()
- if implibdir then
- opt.implibdir = implibdir
+ local impblibfile = target:implibfile()
+ if impblibfile then
+ opt.implib = impblibfile
end
end
end
@@ -244,7 +244,7 @@ function linker:link(objectfiles, targetfile, opt)
opt = table.copy(opt)
opt.target = self:target()
- opt = self:_add_implibdir_to_options(opt)
+ opt = self:_add_implib_to_options(opt)
profiler:enter(self:name(), "link", targetfile)
local ok, errors = sandbox.load(self:_tool().link, self:_tool(), table.wrap(objectfiles), self:_targetkind(), targetfile, linkflags, opt)
@@ -254,13 +254,13 @@ end
-- get the link arguments list
function linker:linkargv(objectfiles, targetfile, opt)
- opt = self:_add_implibdir_to_options(opt)
+ opt = self:_add_implib_to_options(opt)
return self:_tool():linkargv(table.wrap(objectfiles), self:_targetkind(), targetfile, opt.linkflags or self:linkflags(opt), opt)
end
-- get the link command
function linker:linkcmd(objectfiles, targetfile, opt)
- opt = self:_add_implibdir_to_options(opt)
+ opt = self:_add_implib_to_options(opt)
return os.args(table.join(self:linkargv(objectfiles, targetfile, opt)))
end
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 48e2ebe73..e59898efa 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -575,8 +575,8 @@ function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
-- add `-Wl,--out-implib,outputdir/libxxx.a` for xxx.dll on mingw/gcc
if targetkind == "shared" and self:is_plat("mingw") then
- local implibdir = opt.implibdir or path.directory(targetfile)
- table.insert(flags_extra, "-Wl,--out-implib," .. path.join(implibdir, path.basename(targetfile) .. ".dll.a"))
+ local implib = opt.implib or path.join(path.directory(targetfile), path.basename(targetfile) .. ".dll.a")
+ table.insert(flags_extra, "-Wl,--out-implib," .. implib)
end
-- init arguments
@@ -595,11 +595,13 @@ end
--
function link(self, objectfiles, targetkind, targetfile, flags, opt)
opt = opt or {}
+
+ -- ensure the target directory
os.mkdir(path.directory(targetfile))
-- ensure the implib directory
- if opt.implibdir then
- os.mkdir(opt.implibdir)
+ if opt.implib then
+ os.mkdir(path.directory(opt.implib))
end
local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua
index 7220b59c2..12bad4a0d 100644
--- a/xmake/modules/core/tools/link.lua
+++ b/xmake/modules/core/tools/link.lua
@@ -137,8 +137,8 @@ function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
table.insert(argv, 1, "-lib")
elseif targetkind == "shared" then
table.insert(argv, 1, "-dll")
- if opt.implibdir then
- table.insert(argv, "/IMPLIB:" .. path.join(opt.implibdir, path.basename(targetfile) .. ".lib"))
+ if opt.implib then
+ table.insert(argv, "/IMPLIB:" .. opt.implib)
end
end
return self:program(), argv
@@ -151,8 +151,8 @@ function link(self, objectfiles, targetkind, targetfile, flags, opt)
os.mkdir(path.directory(targetfile))
-- ensure the implib directory
- if opt and opt.implibdir then
- os.mkdir(opt.implibdir)
+ if opt and opt.implib then
+ os.mkdir(path.directory(opt.implib))
end
try
diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua
index 58d614fbd..ec0e15874 100644
--- a/xmake/modules/core/tools/nvcc.lua
+++ b/xmake/modules/core/tools/nvcc.lua
@@ -288,9 +288,9 @@ function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
-- add `-Wl,--out-implib,outputdir/libxxx.a` for xxx.dll on mingw/gcc
if targetkind == "shared" and self:is_plat("mingw") then
- local implibdir = opt.implibdir or path.directory(targetfile)
+ local implib = opt.implib or path.join(path.directory(targetfile), path.basename(targetfile) .. ".dll.a")
table.insert(flags_extra, "-Xlinker")
- table.insert(flags_extra, "-Wl,--out-implib," .. path.join(implibdir, path.basename(targetfile) .. ".dll.a"))
+ table.insert(flags_extra, "-Wl,--out-implib," .. implib)
end
-- make link args
@@ -299,11 +299,13 @@ end
-- link the target file
function link(self, objectfiles, targetkind, targetfile, flags, opt)
+
+ -- ensure the target directory
os.mkdir(path.directory(targetfile))
-- ensure the implib directory
- if opt and opt.implibdir then
- os.mkdir(opt.implibdir)
+ if opt and opt.implib then
+ os.mkdir(path.directory(opt.implib))
end
local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
diff --git a/xmake/modules/target/action/clean/main.lua b/xmake/modules/target/action/clean/main.lua
index 911fbe17e..98773a9ab 100644
--- a/xmake/modules/target/action/clean/main.lua
+++ b/xmake/modules/target/action/clean/main.lua
@@ -40,16 +40,14 @@ function main(target)
if target:is_shared() then
if target:is_plat("windows") then
local expfile = path.join(target:implibdir(), path.basename(targetfile) .. ".exp")
- local libfile = path.join(target:implibdir(), path.basename(targetfile) .. ".lib")
if os.isfile(expfile) then
- remove_files(libfile)
remove_files(expfile)
end
- elseif target:is_plat("mingw") then
- local libfile = path.join(target:implibdir(), path.basename(targetfile) .. ".dll.a")
- if os.isfile(libfile) then
- remove_files(libfile)
- end
+ end
+
+ local implibfile = target:implibfile()
+ if implibfile and os.isfile(implibfile) then
+ remove_files(implibfile)
end
end
diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua
index d60426b0a..9fb90b1fe 100644
--- a/xmake/modules/target/action/install/main.lua
+++ b/xmake/modules/target/action/install/main.lua
@@ -237,10 +237,10 @@ function _install_shared(target, opt)
-- @see https://github.com/xmake-io/xmake/issues/714
os.vcp(target:targetfile(), bindir)
local libdir = _get_target_libdir(target, opt)
- local targetfile_lib = path.join(target:implibdir(), path.basename(targetfile) .. (target:is_plat("mingw") and ".dll.a" or ".lib"))
- if os.isfile(targetfile_lib) then
+ local target_implib = target:implibfile()
+ if os.isfile(target_implib) then
os.mkdir(libdir)
- os.vcp(targetfile_lib, libdir)
+ os.vcp(target_implib, libdir)
end
else
-- install target with soname and symlink
diff --git a/xmake/plugins/pack/batchcmds.lua b/xmake/plugins/pack/batchcmds.lua
index aeb1b842e..70d8e2f5f 100644
--- a/xmake/plugins/pack/batchcmds.lua
+++ b/xmake/plugins/pack/batchcmds.lua
@@ -303,13 +303,10 @@ function _on_target_installcmd_shared(target, batchcmds_, opt)
-- install *.lib for shared/windows (*.dll) target
-- @see https://github.com/xmake-io/xmake/issues/714
- if target:is_plat("windows", "mingw") and target:is_shared() then
- local targetfile = target:targetfile()
- local targetfile_lib = path.join(target:implibdir(), path.basename(targetfile) .. (target:is_plat("mingw") and ".dll.a" or ".lib"))
- if os.isfile(targetfile_lib) then
- batchcmds_:mkdir(libdir)
- batchcmds_:cp(targetfile_lib, path.join(libdir, path.filename(targetfile_lib)))
- end
+ local target_implib = target:implibfile()
+ if target_implib and os.isfile(target_implib) then
+ batchcmds_:mkdir(libdir)
+ batchcmds_:cp(target_implib, path.join(libdir, path.filename(target_implib)))
end
_install_target_headers(target, batchcmds_, opt)
diff --git a/xmake/rules/utils/inherit_links/inherit_links.lua b/xmake/rules/utils/inherit_links/inherit_links.lua
index a128e1cb7..213c13f82 100644
--- a/xmake/rules/utils/inherit_links/inherit_links.lua
+++ b/xmake/rules/utils/inherit_links/inherit_links.lua
@@ -80,7 +80,13 @@ function main(target)
end
end
- _add_export_value(target, "linkdirs", path.directory(targetfile))
+ local implibdir = target:implibdir()
+ if implibdir then
+ _add_export_value(target, "linkdirs", implibdir)
+ else
+ _add_export_value(target, "linkdirs", path.directory(targetfile))
+ end
+
if target:rule("go") then
-- we need to add includedirs to support import modules for golang
_add_export_value(target, "includedirs", path.directory(targetfile))