summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-07-02 18:28:36 +0800
committerruki <[email protected]>2022-07-02 18:28:36 +0800
commit2d3649aa6b19c568d807a87775febb497965e0b7 (patch)
treea5d91c9ae8bc00318d6e1a0ba0722869d895df59
parent07343396c6a800583b4bc0015475df8412825b18 (diff)
improve to test packages
-rw-r--r--xmake/core/package/package.lua58
1 files changed, 49 insertions, 9 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 0de198b90..e04d6be0f 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -1690,8 +1690,39 @@ function _instance:resourcedir(name)
end
end
+-- generate lto configs
+function _instance:_generate_lto_configs(sourcekind)
+
+ -- add cflags
+ local configs = {}
+ local _, cc = self:tool(sourcekind)
+ local cflag = sourcekind == "cxx" and "cxxflags" or "cflags"
+ if cc == "cl" then
+ configs[cflag] = "-GL"
+ elseif cc == "clang" or cc == "clangxx" then
+ configs[cflag] = "-flto=thin"
+ elseif cc == "gcc" or cc == "gxx" then
+ configs[cflag] = "-flto"
+ end
+
+ -- add ldflags and shflags
+ local _, ld = self:tool("ld")
+ if ld == "cl" then
+ configs.ldflags = "-LTCG"
+ configs.shflags = "-LTCG"
+ elseif ld == "clang" or ld == "clangxx" then
+ configs.ldflags = "-flto=thin"
+ configs.shflags = "-flto=thin"
+ elseif ld == "gcc" or ld == "gxx" then
+ configs.ldflags = "-flto"
+ configs.shflags = "-flto"
+ end
+ return configs
+end
+
-- generate building configs for has_xxx/check_xxx
-function _instance:_generate_build_configs(configs)
+function _instance:_generate_build_configs(configs, opt)
+ opt = opt or {}
configs = table.join(self:fetch_linkdeps(), configs)
if self:is_plat("windows") then
local ld = self:build_getenv("ld")
@@ -1705,6 +1736,15 @@ function _instance:_generate_build_configs(configs)
end
end
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
+ end
if configs and (configs.ldflags or configs.shflags) then
configs.force = {ldflags = configs.ldflags, shflags = configs.shflags}
configs.ldflags = nil
@@ -1723,7 +1763,7 @@ end
function _instance:has_cfuncs(funcs, opt)
opt = opt or {}
opt.target = self
- opt.configs = self:_generate_build_configs(opt.configs)
+ opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cc"})
return sandbox_module.import("lib.detect.has_cfuncs", {anonymous = true})(funcs, opt)
end
@@ -1737,7 +1777,7 @@ end
function _instance:has_cxxfuncs(funcs, opt)
opt = opt or {}
opt.target = self
- opt.configs = self:_generate_build_configs(opt.configs)
+ opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cxx"})
return sandbox_module.import("lib.detect.has_cxxfuncs", {anonymous = true})(funcs, opt)
end
@@ -1751,7 +1791,7 @@ end
function _instance:has_ctypes(types, opt)
opt = opt or {}
opt.target = self
- opt.configs = self:_generate_build_configs(opt.configs)
+ opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cc"})
return sandbox_module.import("lib.detect.has_ctypes", {anonymous = true})(types, opt)
end
@@ -1765,7 +1805,7 @@ end
function _instance:has_cxxtypes(types, opt)
opt = opt or {}
opt.target = self
- opt.configs = self:_generate_build_configs(opt.configs)
+ opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cxx"})
return sandbox_module.import("lib.detect.has_cxxtypes", {anonymous = true})(types, opt)
end
@@ -1779,7 +1819,7 @@ end
function _instance:has_cincludes(includes, opt)
opt = opt or {}
opt.target = self
- opt.configs = self:_generate_build_configs(opt.configs)
+ opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cc"})
return sandbox_module.import("lib.detect.has_cincludes", {anonymous = true})(includes, opt)
end
@@ -1793,7 +1833,7 @@ end
function _instance:has_cxxincludes(includes, opt)
opt = opt or {}
opt.target = self
- opt.configs = self:_generate_build_configs(opt.configs)
+ opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cxx"})
return sandbox_module.import("lib.detect.has_cxxincludes", {anonymous = true})(includes, opt)
end
@@ -1807,7 +1847,7 @@ end
function _instance:check_csnippets(snippets, opt)
opt = opt or {}
opt.target = self
- opt.configs = self:_generate_build_configs(opt.configs)
+ opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cc"})
return sandbox_module.import("lib.detect.check_csnippets", {anonymous = true})(snippets, opt)
end
@@ -1821,7 +1861,7 @@ end
function _instance:check_cxxsnippets(snippets, opt)
opt = opt or {}
opt.target = self
- opt.configs = self:_generate_build_configs(opt.configs)
+ opt.configs = self:_generate_build_configs(opt.configs, {sourcekind = "cxx"})
return sandbox_module.import("lib.detect.check_cxxsnippets", {anonymous = true})(snippets, opt)
end