summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-08-09 23:48:46 +0800
committerruki <[email protected]>2023-08-09 23:48:46 +0800
commit3660a7f4d4ef298fd4dff2092f19fa981fcd354d (patch)
tree2c405a8a05583871b1238bbfbe0ef0ed53399bc2
parent682560e43ac5ac6610d16cbf4aacfcb505c3e8f8 (diff)
improve to pass flags to packages #4046
-rw-r--r--xmake/core/package/package.lua13
-rw-r--r--xmake/modules/package/tools/cmake.lua2
-rw-r--r--xmake/modules/package/tools/xmake.lua4
-rw-r--r--xmake/modules/private/action/require/impl/package.lua2
4 files changed, 21 insertions, 0 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 6efded860..36a9aba9f 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -2086,6 +2086,19 @@ function _instance:_generate_build_configs(configs, opt)
if opt.sourcekind == "cxx" and configs.exceptions == nil and self:has_tool("cxx", "cl") then
configs.exceptions = "cxx"
end
+
+ -- pass user flags to on_test, because some flags need be passed to ldflags in on_test
+ -- e.g. add_requireconfs("**", {configs = {cxflags = "/fsanitize=address", ldflags = "/fsanitize=address"}})
+ --
+ -- @see https://github.com/xmake-io/xmake/issues/4046
+ --
+ for name, flags in pairs(self:configs()) do
+ if name:endswith("flags") and self:extraconf("configs", name, "builtin") then
+ configs[name] = table.wrap(configs[name] or {})
+ table.join2(configs[name], flags)
+ end
+ end
+
if configs and (configs.ldflags or configs.shflags) then
configs.force = {ldflags = configs.ldflags, shflags = configs.shflags}
configs.ldflags = nil
diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua
index d30ecb52c..fcf8b16de 100644
--- a/xmake/modules/package/tools/cmake.lua
+++ b/xmake/modules/package/tools/cmake.lua
@@ -225,6 +225,7 @@ function _get_ldflags(package, opt)
table.join2(result, _map_linkflags(package, "binary", {"cxx"}, "syslink", package:build_getenv("syslinks")))
table.join2(result, _map_linkflags(package, "binary", {"cxx"}, "linkdir", package:build_getenv("linkdirs")))
end
+ table.join2(result, package:config("ldflags"))
if package:config("lto") then
table.join2(result, package:_generate_lto_configs().ldflags)
end
@@ -247,6 +248,7 @@ function _get_shflags(package, opt)
table.join2(result, _map_linkflags(package, "shared", {"cxx"}, "syslink", package:build_getenv("syslinks")))
table.join2(result, _map_linkflags(package, "shared", {"cxx"}, "linkdir", package:build_getenv("linkdirs")))
end
+ table.join2(result, package:config("shflags"))
if package:config("lto") then
table.join2(result, package:_generate_lto_configs().shflags)
end
diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua
index 477dd35c8..0594d0f6b 100644
--- a/xmake/modules/package/tools/xmake.lua
+++ b/xmake/modules/package/tools/xmake.lua
@@ -198,6 +198,7 @@ function _get_configs(package, configs, opt)
local cxxflags = table.join(table.wrap(package:config("cxxflags")), get_config("cxxflags"))
local asflags = table.join(table.wrap(package:config("asflags")), get_config("asflags"))
local ldflags = table.join(table.wrap(package:config("ldflags")), get_config("ldflags"))
+ local shflags = table.join(table.wrap(package:config("shflags")), get_config("shflags"))
table.insert(configs, "--plat=" .. package:plat())
table.insert(configs, "--arch=" .. package:arch())
if configs.mode == nil then
@@ -266,6 +267,9 @@ function _get_configs(package, configs, opt)
if ldflags and #ldflags > 0 then
table.insert(configs, "--ldflags=" .. table.concat(ldflags, ' '))
end
+ if shflags and #shflags > 0 then
+ table.insert(configs, "--shflags=" .. table.concat(shflags, ' '))
+ end
local buildir = opt.buildir or package:buildir()
if buildir then
table.insert(configs, "--buildir=" .. buildir)
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index 17723fbaa..c35f37174 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -338,6 +338,8 @@ function _add_package_configurations(package)
package:add("configs", "cxflags", {builtin = true, description = "Set the C/C++ compiler flags."})
package:add("configs", "cxxflags", {builtin = true, description = "Set the C++ compiler flags."})
package:add("configs", "asflags", {builtin = true, description = "Set the assembler flags."})
+ package:add("configs", "ldflags", {builtin = true, description = "Set the binary linker flags."})
+ package:add("configs", "shflags", {builtin = true, description = "Set the shared library linker flags."})
end
-- select package version