summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-01-31 21:48:54 +0800
committerGitHub <[email protected]>2025-01-31 21:48:54 +0800
commite0b9b189f0c7e8b1438ecfe923d5b6d5a42ef5f2 (patch)
tree2b50990081c6ae86ff74c3c0d18fcd033a19512c
parent1c95d287f8bf7b80afc30e68ceb7f438afcccb7a (diff)
parentf0365d5685f1a3a5006d022f206e1e40d3bcca22 (diff)
Merge pull request #6129 from chriku/fix_capnproto
#5426 after_load for capnproto
-rw-r--r--xmake/rules/capnproto/capnp.lua42
-rw-r--r--xmake/rules/capnproto/xmake.lua4
2 files changed, 39 insertions, 7 deletions
diff --git a/xmake/rules/capnproto/capnp.lua b/xmake/rules/capnproto/capnp.lua
index 747608755..5f8643f64 100644
--- a/xmake/rules/capnproto/capnp.lua
+++ b/xmake/rules/capnproto/capnp.lua
@@ -38,8 +38,40 @@ function _get_capnp(target)
end
-- generate build commands
-function buildcmd(target, batchcmds, sourcefile_capnp, opt)
+function load(target)
+ -- get the first sourcefile
+ local sourcefile_capnp
+ local sourcebatch = target:sourcebatches()["capnproto.cpp"]
+ if sourcebatch and sourcebatch.sourcefiles then
+ sourcefile_capnp = sourcebatch.sourcefiles[1]
+ end
+ if not sourcefile_capnp then
+ return
+ end
+ -- get c/c++ source file for capnproto
+ local prefixdir
+ local public
+ local fileconfig = target:fileconfig(sourcefile_capnp)
+ if fileconfig then
+ public = fileconfig.capnp_public
+ prefixdir = fileconfig.capnp_rootdir
+ end
+ local rootdir = path.join(target:autogendir(), "rules", "capnproto")
+ local filename = path.basename(sourcefile_capnp) .. ".capnp.c++"
+ local sourcefile_cx = target:autogenfile(sourcefile_capnp, {rootdir = rootdir, filename = filename})
+ local sourcefile_dir = prefixdir and path.join(rootdir, prefixdir) or path.directory(sourcefile_cx)
+
+ -- add includedirs
+ target:add("includedirs", sourcefile_dir, {public = true})
+
+ -- add objectfile, @see https://github.com/xmake-io/xmake/issues/5426
+ local objectfile = target:objectfile(sourcefile_cx)
+ table.insert(target:objectfiles(), objectfile)
+end
+
+-- generate build commands
+function buildcmd(target, batchcmds, sourcefile_capnp, opt)
-- get capnp
local capnp = _get_capnp(target)
@@ -56,12 +88,8 @@ function buildcmd(target, batchcmds, sourcefile_capnp, opt)
local sourcefile_cx = target:autogenfile(sourcefile_capnp, {rootdir = rootdir, filename = filename})
local sourcefile_dir = prefixdir and path.join(rootdir, prefixdir) or path.directory(sourcefile_cx)
- -- add includedirs
- target:add("includedirs", sourcefile_dir, {public = public})
-
-- add objectfile
local objectfile = target:objectfile(sourcefile_cx)
- table.insert(target:objectfiles(), objectfile)
-- add commands
batchcmds:mkdir(sourcefile_dir)
@@ -77,10 +105,10 @@ function buildcmd(target, batchcmds, sourcefile_capnp, opt)
table.insert(argv, path(prefixdir, function (p) return "--src-prefix=" .. p end))
end
table.insert(argv, "-o")
- table.insert(argv, path(sourcefile_dir, function (p) return "c++:" .. p end))
+ table.insert(argv, path(rootdir, function (p) return "c++:" .. p end))
table.insert(argv, path(sourcefile_capnp))
batchcmds:vrunv(capnp, argv)
- local configs = {includedirs = sourcefile_dir, languages = "c++14"}
+ local configs = {includedirs = sourcefile_dir, languages = (fileconfig and fileconfig.cpp_version) or "c++14"}
if target:is_plat("windows") then
configs.cxflags = "/TP"
end
diff --git a/xmake/rules/capnproto/xmake.lua b/xmake/rules/capnproto/xmake.lua
index 651c5bd47..81491baa1 100644
--- a/xmake/rules/capnproto/xmake.lua
+++ b/xmake/rules/capnproto/xmake.lua
@@ -20,7 +20,11 @@
-- define rule: capnproto.cpp
rule("capnproto.cpp")
+ add_deps("c++")
set_extensions(".capnp")
+ after_load(function (target)
+ return import("capnp").load(target)
+ end)
before_buildcmd_file(function (target, batchcmds, sourcefile_capnp, opt)
return import("capnp").buildcmd(target, batchcmds, sourcefile_capnp, opt)
end)