diff options
| author | ruki <[email protected]> | 2025-12-02 22:52:26 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-12-02 22:52:26 +0800 |
| commit | a3f3678d1705dac4106dc95883d264534db159e2 (patch) | |
| tree | da53e9eeb1689c79678f1e3488e6ec08382843f1 /xmake/rules/c++/config/optimization.lua | |
| parent | 5c4b98ecca5a0c437a1bb5679e4046f752ed1a42 (diff) | |
improve objc configs
Diffstat (limited to 'xmake/rules/c++/config/optimization.lua')
| -rw-r--r-- | xmake/rules/c++/config/optimization.lua | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/xmake/rules/c++/config/optimization.lua b/xmake/rules/c++/config/optimization.lua index 44b6ce755..4332bd833 100644 --- a/xmake/rules/c++/config/optimization.lua +++ b/xmake/rules/c++/config/optimization.lua @@ -23,14 +23,16 @@ import("core.tool.compiler") import("core.project.project") -- add lto optimization -function main(target, sourcekind) - if not (target:policy("build.optimization.lto") or project.policy("build.optimization.lto")) then - return - end - +function _add_lto_optimization(target, sourcekind) -- add cflags local _, cc = target:tool(sourcekind) - local cflag = sourcekind == "cxx" and "cxxflags" or "cflags" + local flagnames = { + cc = "cflags", + cxx = "cxxflags", + mm = "mflags", + mxx = "mxxflags" + } + local cflag = flagnames[sourcekind] or (sourcekind == "cxx" and "cxxflags" or "cflags") if cc == "cl" then target:add(cflag, "-GL") elseif cc == "clang" or cc == "clangxx" or cc == "clang_cl" then @@ -70,7 +72,14 @@ function main(target, sourcekind) -- @see https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html local optimize = target:get("optimize") if optimize then - local optimize_flags = compiler.map_flags(sourcekind == "cc" and "c" or "cxx", "optimize", optimize) + local lang_map = { + cc = "c", + cxx = "cxx", + mm = "c", + mxx = "cxx" + } + local lang = lang_map[sourcekind] or "cxx" + local optimize_flags = compiler.map_flags(lang, "optimize", optimize) target:add("ldflags", optimize_flags) target:add("shflags", optimize_flags) end @@ -90,3 +99,11 @@ function main(target, sourcekind) end end +-- main entry +function main(target, sourcekind) + -- handle lto optimization + if target:policy("build.optimization.lto") or project.policy("build.optimization.lto") then + _add_lto_optimization(target, sourcekind) + end +end + |
