summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-02 22:52:26 +0800
committerruki <[email protected]>2025-12-02 22:52:26 +0800
commita3f3678d1705dac4106dc95883d264534db159e2 (patch)
treeda53e9eeb1689c79678f1e3488e6ec08382843f1
parent5c4b98ecca5a0c437a1bb5679e4046f752ed1a42 (diff)
improve objc configs
-rw-r--r--xmake/rules/c++/config/optimization.lua31
-rw-r--r--xmake/rules/c++/config/sanitizer.lua2
-rw-r--r--xmake/rules/c++/openmp/load.lua1
-rw-r--r--xmake/rules/c++/openmp/xmake.lua5
-rw-r--r--xmake/rules/objc++/config/main.lua10
-rw-r--r--xmake/rules/objc++/xmake.lua2
6 files changed, 33 insertions, 18 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
+
diff --git a/xmake/rules/c++/config/sanitizer.lua b/xmake/rules/c++/config/sanitizer.lua
index b6fe0df7e..aeea8492f 100644
--- a/xmake/rules/c++/config/sanitizer.lua
+++ b/xmake/rules/c++/config/sanitizer.lua
@@ -22,7 +22,6 @@
import("core.project.project")
import("lib.detect.find_tool")
import("core.base.semver")
-import("core.base.path")
-- add build sanitizer
function _add_build_sanitizer(target, sourcekind, checkmode)
@@ -47,7 +46,6 @@ function _add_build_sanitizer(target, sourcekind, checkmode)
end
end
--- main entry
function main(target, sourcekind)
local sanitizer = false
for _, checkmode in ipairs({"address", "thread", "memory", "leak", "undefined"}) do
diff --git a/xmake/rules/c++/openmp/load.lua b/xmake/rules/c++/openmp/load.lua
index 7e4969ff0..a1ced6cac 100644
--- a/xmake/rules/c++/openmp/load.lua
+++ b/xmake/rules/c++/openmp/load.lua
@@ -39,4 +39,3 @@ function main(target, sourcekind)
target:add(flag_name, "-Qopenmp")
end
end
-
diff --git a/xmake/rules/c++/openmp/xmake.lua b/xmake/rules/c++/openmp/xmake.lua
index e7a554c5d..052ad5370 100644
--- a/xmake/rules/c++/openmp/xmake.lua
+++ b/xmake/rules/c++/openmp/xmake.lua
@@ -20,13 +20,12 @@
-- define rule: c.openmp
rule("c.openmp")
- on_load(function (target)
+ on_config(function (target)
import("load")(target, "cc")
end)
-- define rule: c++.openmp
rule("c++.openmp")
- on_load(function (target)
+ on_config(function (target)
import("load")(target, "cxx")
end)
-
diff --git a/xmake/rules/objc++/config/main.lua b/xmake/rules/objc++/config/main.lua
index 45755edb8..43d2b0096 100644
--- a/xmake/rules/objc++/config/main.lua
+++ b/xmake/rules/objc++/config/main.lua
@@ -20,14 +20,18 @@
-- imports
import("rules.objc++.config.basic", {rootdir = os.programdir(), alias = "config_basic"})
-import("rules.c++.config", {rootdir = os.programdir(), alias = "config_cxx"})
+import("rules.c++.config.optimization", {rootdir = os.programdir(), alias = "config_optimization"})
+import("rules.c++.config.sanitizer", {rootdir = os.programdir(), alias = "config_sanitizer"})
-- main entry
function main(target, sourcekind)
-- handle objc++ basic configs
config_basic(target, sourcekind)
- -- handle c++ configs (optimization, sanitizer, etc.)
- config_cxx(target, sourcekind)
+ -- handle optimization.lto
+ config_optimization(target, sourcekind)
+
+ -- handle sanitizer
+ config_sanitizer(target, sourcekind)
end
diff --git a/xmake/rules/objc++/xmake.lua b/xmake/rules/objc++/xmake.lua
index 2ff0ecb8c..321aa131a 100644
--- a/xmake/rules/objc++/xmake.lua
+++ b/xmake/rules/objc++/xmake.lua
@@ -23,7 +23,6 @@ rule("objc.build")
set_sourcekinds("mm")
add_deps("objc.build.pcheader")
on_config(function (target)
- -- handle all configs
import("rules.objc++.config")(target, "mm")
end)
on_build_files("private.action.build.object", {jobgraph = true, batch = true, distcc = true})
@@ -33,7 +32,6 @@ rule("objc++.build")
set_sourcekinds("mxx")
add_deps("objc++.build.pcheader")
on_config(function (target)
- -- handle all configs
import("rules.objc++.config")(target, "mxx")
end)
on_build_files("private.action.build.object", {jobgraph = true, batch = true, distcc = true})