summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSineStriker <[email protected]>2025-04-20 20:28:50 +0800
committerruki <[email protected]>2025-04-23 11:30:30 +0800
commit42be9d4228849def30a728b3933209a1cd90638e (patch)
treef9c58d1b2b978521517b749434eca1aed032f476
parentc208820b204ad066812f87545b96703ad5cebf3a (diff)
Make `set_targetdir` similar to `set_prefixdir`
-rw-r--r--xmake/core/project/target.lua138
-rw-r--r--xmake/modules/private/action/build/link_objects.lua2
-rw-r--r--xmake/modules/target/action/clean/main.lua2
-rw-r--r--xmake/modules/target/action/install/main.lua2
-rw-r--r--xmake/rules/utils/inherit_links/inherit_links.lua5
5 files changed, 106 insertions, 43 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index ea250b9c9..6e8b93e7b 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -1570,61 +1570,121 @@ function _instance:autogenfile(sourcefile, opt)
return path.join(rootdir, (opt and opt.filename) and opt.filename or path.filename(sourcefile))
end
+-- get the default target directory
+function _instance:_default_targetdir()
+ local targetdir = config.buildir()
+
+ -- get root directory of target
+ local intermediate_directory = self:policy("build.intermediate_directory")
+ if intermediate_directory == false then
+ return targetdir
+ end
+
+ -- generate intermediate directory
+ local plat = self:plat()
+ if plat then
+ targetdir = path.join(targetdir, plat)
+ end
+ local arch = self:arch()
+ if arch then
+ targetdir = path.join(targetdir, arch)
+ end
+ local mode = config.mode()
+ if mode then
+ targetdir = path.join(targetdir, mode)
+ end
+ local namespace = self:namespace()
+ if namespace then
+ targetdir = path.join(targetdir, (namespace:replace("::", path.sep())))
+ end
+ return targetdir
+end
+
-- get the target directory
function _instance:targetdir()
-
- -- the target directory
local targetdir = self:get("targetdir")
if not targetdir then
- targetdir = config.buildir()
+ return self:_default_targetdir()
+ end
- -- get root directory of target
- local intermediate_directory = self:policy("build.intermediate_directory")
- if intermediate_directory == false then
- return targetdir
+ -- executable, windows shared library
+ if self:is_binary() or self:has_implib() then
+ local subdir = self:extraconf("targetdir", targetdir, "bin")
+ if subdir then
+ targetdir = path.join(targetdir, subdir)
end
+ return targetdir
+ end
- -- generate intermediate directory
- local plat = self:plat()
- if plat then
- targetdir = path.join(targetdir, plat)
- end
- local arch = self:arch()
- if arch then
- targetdir = path.join(targetdir, arch)
- end
- local mode = config.mode()
- if mode then
- targetdir = path.join(targetdir, mode)
- end
- local namespace = self:namespace()
- if namespace then
- targetdir = path.join(targetdir, (namespace:replace("::", path.sep())))
+ -- static library, non-windows shared library
+ if self:is_static() or self:is_shared() then
+ local subdir = self:extraconf("targetdir", targetdir, "lib")
+ if subdir then
+ targetdir = path.join(targetdir, subdir)
end
+ return targetdir
+ end
+
+ return targetdir
+end
+
+-- get the build artifact output directory
+function _instance:artifactdir(type)
+ local targetdir = self:get("targetdir")
+ if not targetdir then
+ return self:_default_targetdir()
+ end
+
+ local subdir = self:extraconf("targetdir", targetdir, type)
+ if subdir then
+ return path.join(targetdir, subdir)
end
return targetdir
end
--- get the imp-lib directory (only on windows)
-function _instance:implibdir()
- if not ((self:is_plat("windows", "mingw")) and self:is_shared()) then
+-- get the build artifact output file
+function _instance:artifactfile(type)
+ if type == "bin" then
+ -- executable, windows shared library
+ if self:is_binary() or self:has_implib() then
+ return self:targetfile()
+ end
+
return nil
end
- local implibdir = self:get("implibdir")
- if not implibdir then
- implibdir = self:targetdir()
+ if type == "lib" then
+ if self:is_static() then
+ -- static library
+ return self:targetfile()
+ end
+ if self:is_shared() then
+ if self:is_plat("windows") then
+ -- msvc shared library implib
+ return path.join(self:artifactdir("lib"), path.basename(self:filename()) .. ".lib")
+
+ elseif self:is_plat("mingw")then
+ -- mingw shared library implib
+ return path.join(self:artifactdir("lib"), path.basename(self:filename()) .. ".dll.a")
+ else
+ -- unix shared library
+ return self:targetfile()
+ end
+ end
+
+ return nil
end
- return implibdir
+
+ -- to be added...
+ return nil
end
--- get the imp-lib file (only on windows)
+-- get the implib file (windows shared library only)
function _instance:implibfile()
- local implibdir = self:implibdir()
- if not implibdir then
- return nil
+ if self:has_implib() then
+ return self:artifactfile("lib")
end
- return path.join(implibdir, path.basename(self:targetfile()) .. (self:is_plat("mingw") and ".dll.a" or ".lib"))
+ return nil
end
-- get the target file name
@@ -2503,6 +2563,13 @@ function _instance:has_runtime(...)
end
end
+-- has implib artifact file?
+--
+-- equivalent to "is_windows_shared_library"
+function _instance:has_implib()
+ return self:is_shared() and self:is_plat("windows", "mingw")
+end
+
-- get the given toolchain
function _instance:toolchain(name)
local toolchains_map = self:_memcache():get("toolchains_map")
@@ -2918,7 +2985,6 @@ 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/modules/private/action/build/link_objects.lua b/xmake/modules/private/action/build/link_objects.lua
index 31e41ca6f..8d3c8e7a1 100644
--- a/xmake/modules/private/action/build/link_objects.lua
+++ b/xmake/modules/private/action/build/link_objects.lua
@@ -51,8 +51,6 @@ function _do_link_target(target, opt)
print(linkinst:linkcmd(objectfiles, targetfile, {linkflags = linkflags, implib = target:implibfile(), rawargs = true}))
end
- print("TO LINK: ", target:name(), target:implibfile(), targetfile)
-
if not dryrun then
assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags, implib = target:implibfile()}))
end
diff --git a/xmake/modules/target/action/clean/main.lua b/xmake/modules/target/action/clean/main.lua
index 98773a9ab..8806ed483 100644
--- a/xmake/modules/target/action/clean/main.lua
+++ b/xmake/modules/target/action/clean/main.lua
@@ -39,7 +39,7 @@ function main(target)
-- @see https://github.com/xmake-io/xmake/issues/3052
if target:is_shared() then
if target:is_plat("windows") then
- local expfile = path.join(target:implibdir(), path.basename(targetfile) .. ".exp")
+ local expfile = path.join(target:artifactdir("lib"), path.basename(targetfile) .. ".exp")
if os.isfile(expfile) then
remove_files(expfile)
end
diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua
index 9fb90b1fe..660700c0b 100644
--- a/xmake/modules/target/action/install/main.lua
+++ b/xmake/modules/target/action/install/main.lua
@@ -232,7 +232,7 @@ function _install_shared(target, opt)
os.mkdir(bindir)
local targetfile = target:targetfile()
- if target:is_plat("windows", "mingw") and target:is_shared() then
+ if target:has_implib() then
-- install *.lib for shared/windows (*.dll) target
-- @see https://github.com/xmake-io/xmake/issues/714
os.vcp(target:targetfile(), bindir)
diff --git a/xmake/rules/utils/inherit_links/inherit_links.lua b/xmake/rules/utils/inherit_links/inherit_links.lua
index 213c13f82..3f56dc46c 100644
--- a/xmake/rules/utils/inherit_links/inherit_links.lua
+++ b/xmake/rules/utils/inherit_links/inherit_links.lua
@@ -80,9 +80,8 @@ function main(target)
end
end
- local implibdir = target:implibdir()
- if implibdir then
- _add_export_value(target, "linkdirs", implibdir)
+ if target:has_implib() then
+ _add_export_value(target, "linkdirs", target:artifactdir("lib"))
else
_add_export_value(target, "linkdirs", path.directory(targetfile))
end