summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-10-18 22:17:25 +0800
committerruki <[email protected]>2021-10-18 22:17:25 +0800
commit105117735be22a14c32d136681b5f08916625fb4 (patch)
tree05d596d0709d55742fad0a5bf3154b17a6c9db5b
parent2f8bf766dfeb9103e5ab9a1ccc7936a5bc04aa9c (diff)
add c.unity_build
-rw-r--r--tests/projects/c/unity_build/xmake.lua2
-rw-r--r--xmake/rules/c++/unity_build/unity_build.lua2
-rw-r--r--xmake/rules/c++/unity_build/xmake.lua38
3 files changed, 30 insertions, 12 deletions
diff --git a/tests/projects/c/unity_build/xmake.lua b/tests/projects/c/unity_build/xmake.lua
index 447960db5..89166a312 100644
--- a/tests/projects/c/unity_build/xmake.lua
+++ b/tests/projects/c/unity_build/xmake.lua
@@ -1,7 +1,7 @@
target("test")
set_kind("binary")
add_includedirs("src")
- add_rules("c++.unity_build", {batchsize = 2})
+ add_rules("c.unity_build", {batchsize = 2})
add_files("src/*.c", "src/*.cpp")
add_files("src/foo/*.c", {unity_group = "foo"})
add_files("src/bar/*.c", {unity_group = "bar"})
diff --git a/xmake/rules/c++/unity_build/unity_build.lua b/xmake/rules/c++/unity_build/unity_build.lua
index e28e5aff3..96b53001e 100644
--- a/xmake/rules/c++/unity_build/unity_build.lua
+++ b/xmake/rules/c++/unity_build/unity_build.lua
@@ -67,7 +67,7 @@ end
function main(target, sourcebatch)
-- get unit batch sources
- local extraconf = target:extraconf("rules", "c++.unity_build")
+ local extraconf = target:extraconf("rules", sourcebatch.sourcekind == "cxx" and "c++.unity_build" or "c.unity_build")
local batchsize = extraconf and extraconf.batchsize
local id = 1
local count = 0
diff --git a/xmake/rules/c++/unity_build/xmake.lua b/xmake/rules/c++/unity_build/xmake.lua
index b03a383ae..e0dfa9660 100644
--- a/xmake/rules/c++/unity_build/xmake.lua
+++ b/xmake/rules/c++/unity_build/xmake.lua
@@ -18,16 +18,36 @@
-- @file xmake.lua
--
+rule("c.unity_build")
+ after_load(function (target)
+ import("unity_build")
+ local sourcebatches = target:sourcebatches()
+ if sourcebatches then
+ local sourcebatch = sourcebatches["c.build"]
+ if sourcebatch then
+ unity_build(target, sourcebatch)
+ end
+ end
+ end)
+ before_build(function (target, opt)
+ import("unity_build")
+ local sourcebatches = target:sourcebatches()
+ if sourcebatches then
+ local sourcebatch = sourcebatches["c.build"]
+ if sourcebatch then
+ unity_build.generate_unityfiles(target, sourcebatch, opt)
+ end
+ end
+ end)
+
rule("c++.unity_build")
after_load(function (target)
import("unity_build")
local sourcebatches = target:sourcebatches()
if sourcebatches then
- for _, rulename in ipairs({"c.build", "c++.build"}) do
- local sourcebatch = sourcebatches[rulename]
- if sourcebatch then
- unity_build(target, sourcebatch)
- end
+ local sourcebatch = sourcebatches["c++.build"]
+ if sourcebatch then
+ unity_build(target, sourcebatch)
end
end
end)
@@ -35,11 +55,9 @@ rule("c++.unity_build")
import("unity_build")
local sourcebatches = target:sourcebatches()
if sourcebatches then
- for _, rulename in ipairs({"c.build", "c++.build"}) do
- local sourcebatch = sourcebatches[rulename]
- if sourcebatch then
- unity_build.generate_unityfiles(target, sourcebatch, opt)
- end
+ local sourcebatch = sourcebatches["c++.build"]
+ if sourcebatch then
+ unity_build.generate_unityfiles(target, sourcebatch, opt)
end
end
end)