summaryrefslogtreecommitdiff
path: root/xmake/rules/cppfront
diff options
context:
space:
mode:
authorcarols <[email protected]>2024-04-07 21:10:39 +0800
committercarols <[email protected]>2024-04-07 21:14:13 +0800
commit4044b796efabe9d22ab4208bebe484c18492bf06 (patch)
tree1b49aa62d95436a8eb1505a7d4c69c3d170f647c /xmake/rules/cppfront
parent014639a6dc483e72a9184504f466b9a464dc9748 (diff)
Add Add cppfront's header(*.h2) support,use add_deps instead of on_buildcmd_file,
Diffstat (limited to 'xmake/rules/cppfront')
-rw-r--r--xmake/rules/cppfront/xmake.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/xmake/rules/cppfront/xmake.lua b/xmake/rules/cppfront/xmake.lua
index 90153df85..4cd6a9675 100644
--- a/xmake/rules/cppfront/xmake.lua
+++ b/xmake/rules/cppfront/xmake.lua
@@ -18,9 +18,38 @@
-- @file xmake.lua
--
+rule("cppfront.build.h2")
+ set_extensions(".h2")
+
+ on_buildcmd_file(function (target, batchcmds, sourcefile_h2, opt)
+
+ -- get cppfront
+ import("lib.detect.find_tool")
+ local cppfront = assert(find_tool("cppfront", {check = "-h"}), "cppfront not found!")
+
+ -- get h header file for h2
+ local sourcefile_h = target:autogenfile((sourcefile_h2:gsub(".h2$", ".h")))
+ local basedir = path.directory(sourcefile_h)
+
+ -- add commands
+ local argv = {"-o", path(sourcefile_h), path(sourcefile_h2)}
+ batchcmds:show_progress(opt.progress, "${color.build.object}compiling.cpp2 %s", sourcefile_h2)
+ batchcmds:mkdir(basedir)
+ batchcmds:vrunv(cppfront.program, argv)
+
+ -- add deps
+ batchcmds:add_depfiles(sourcefile_h2)
+ batchcmds:set_depmtime(os.mtime(sourcefile_h))
+ batchcmds:set_depcache(target:dependfile(sourcefile_h))
+ end)
+
-- define rule: cppfront.build
rule("cppfront.build")
set_extensions(".cpp2")
+
+ -- .h2 must compile before .cpp2
+ add_deps("cppfront.build.h2", {order = true})
+
on_load(function (target)
-- only cppfront source files? we need to patch cxx source kind for linker
local sourcekinds = target:sourcekinds()
@@ -66,6 +95,9 @@ rule("cppfront.build")
-- define rule: cppfront
rule("cppfront")
+ -- add_build.h2 rules
+ add_deps("cppfront.build.h2")
+
-- add build rules
add_deps("cppfront.build")