From 4044b796efabe9d22ab4208bebe484c18492bf06 Mon Sep 17 00:00:00 2001 From: carols Date: Sun, 7 Apr 2024 21:10:39 +0800 Subject: Add Add cppfront's header(*.h2) support,use add_deps instead of on_buildcmd_file, --- xmake/rules/cppfront/xmake.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'xmake/rules/cppfront/xmake.lua') 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") -- cgit v1.3.1