summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-07-15 00:14:24 +0800
committerruki <[email protected]>2026-07-15 00:14:24 +0800
commit90c7049fa21ba559b905240fa0d3b527400095f5 (patch)
tree6b688fe3b56a6a2b62d21925d7c094112bf9cb27
parent67956c49b5220d967572a3cdfa9b7c96052eec04 (diff)
add pic to package test
-rw-r--r--xmake/core/package/package.lua68
1 files changed, 38 insertions, 30 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 7a38b812f..0d164ce95 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -2459,10 +2459,18 @@ function _instance:_generate_sanitizer_configs(checkmode, sourcekind)
return toolchain_utils.get_sanitizer_flags(self, {checkmode = checkmode, sourcekind = sourcekind})
end
--- generate building configs for has_xxx/check_xxx
-function _instance:_generate_build_configs(configs, opt)
- opt = opt or {}
- configs = table.join(self:fetch_librarydeps() or {}, configs)
+-- generate pic configs, e.g. -fPIC for the shared/relocatable compile in on_test/check_xxx (wasm ..)
+function _instance:_generate_pic_configs(sourcekind)
+ local configs = {}
+ if not self:is_plat("windows", "mingw") and
+ self:has_tool(sourcekind, "gcc", "gxx", "clang", "clangxx", "emcc", "emxx") then
+ configs.cxflags = "-fPIC"
+ end
+ return configs
+end
+
+-- generate runtime configs, e.g. -MD/-MT runtime flags
+function _instance:_generate_runtime_configs(sourcekind)
-- since we are ignoring the runtimes of the headeronly library,
-- we can only get the runtimes from the dependency library to detect the link.
local runtimes = self:runtimes()
@@ -2474,43 +2482,43 @@ function _instance:_generate_build_configs(configs, opt)
end
end
end
+ local configs = {}
if runtimes then
-- @note we need to patch package:sourcekinds(), because it wiil be called nf_runtime for gcc/clang
- local sourcekind = opt.sourcekind or "cxx"
self.sourcekinds = function (self)
return sourcekind
end
- local compiler = self:compiler(sourcekind)
- local cxflags = compiler:map_flags("runtime", runtimes, {target = self})
- configs.cxflags = table.wrap(configs.cxflags)
- table.insert(configs.cxflags, cxflags)
+ configs.cxflags = self:compiler(sourcekind):map_flags("runtime", runtimes, {target = self})
+ configs.ldflags = self:linker("binary", sourcekind):map_flags("runtime", runtimes, {target = self})
+ configs.shflags = self:linker("shared", sourcekind):map_flags("runtime", runtimes, {target = self})
+ self.sourcekinds = nil
+ end
+ return configs
+end
- local ldflags = self:linker("binary", sourcekind):map_flags("runtime", runtimes, {target = self})
- configs.ldflags = table.wrap(configs.ldflags)
- table.insert(configs.ldflags, ldflags)
+-- generate building configs for has_xxx/check_xxx
+function _instance:_generate_build_configs(configs, opt)
+ opt = opt or {}
+ configs = table.join(self:fetch_librarydeps() or {}, configs)
- local shflags = self:linker("shared", sourcekind):map_flags("runtime", runtimes, {target = self})
- configs.shflags = table.wrap(configs.shflags)
- table.insert(configs.shflags, shflags)
- self.sourcekinds = nil
+ -- merge the sub configs (e.g. {cxflags = ..., ldflags = ...}) into the result
+ local function _merge(subconfigs)
+ for k, v in pairs(subconfigs) do
+ configs[k] = table.wrap(configs[k] or {})
+ table.join2(configs[k], v)
+ end
+ end
+
+ local sourcekind = opt.sourcekind or "cxx"
+ _merge(self:_generate_runtime_configs(sourcekind))
+ if self:config("pic") ~= false then
+ _merge(self:_generate_pic_configs(sourcekind))
end
if self:config("lto") then
- local configs_lto = self:_generate_lto_configs(opt.sourcekind or "cxx")
- if configs_lto then
- for k, v in pairs(configs_lto) do
- configs[k] = table.wrap(configs[k] or {})
- table.join2(configs[k], v)
- end
- end
+ _merge(self:_generate_lto_configs(sourcekind))
end
if self:config("asan") then
- local configs_asan = self:_generate_sanitizer_configs("address", opt.sourcekind or "cxx")
- if configs_asan then
- for k, v in pairs(configs_asan) do
- configs[k] = table.wrap(configs[k] or {})
- table.join2(configs[k], v)
- end
- end
+ _merge(self:_generate_sanitizer_configs("address", sourcekind))
end
-- enable exceptions for msvc by default
if opt.sourcekind == "cxx" and configs.exceptions == nil and self:has_tool("cxx", "cl") then