diff options
| author | carols <[email protected]> | 2024-04-07 21:10:39 +0800 |
|---|---|---|
| committer | carols <[email protected]> | 2024-04-07 21:14:13 +0800 |
| commit | 4044b796efabe9d22ab4208bebe484c18492bf06 (patch) | |
| tree | 1b49aa62d95436a8eb1505a7d4c69c3d170f647c | |
| parent | 014639a6dc483e72a9184504f466b9a464dc9748 (diff) | |
Add Add cppfront's header(*.h2) support,use add_deps instead of on_buildcmd_file,
| -rw-r--r-- | tests/projects/cppfront/console/src/main.cpp2 | 6 | ||||
| -rw-r--r-- | tests/projects/cppfront/console/src/println.h2 | 4 | ||||
| -rw-r--r-- | tests/projects/cppfront/console/xmake.lua | 1 | ||||
| -rw-r--r-- | xmake/rules/cppfront/xmake.lua | 32 |
4 files changed, 39 insertions, 4 deletions
diff --git a/tests/projects/cppfront/console/src/main.cpp2 b/tests/projects/cppfront/console/src/main.cpp2 index 1ab54b94b..1c8bf1c0e 100644 --- a/tests/projects/cppfront/console/src/main.cpp2 +++ b/tests/projects/cppfront/console/src/main.cpp2 @@ -1,7 +1,5 @@ +#include "println.h2" main: () -> int = println("Hello world!\n"); -println: (msg: _) -> int = { - std::cout << msg; - return 0; -} + diff --git a/tests/projects/cppfront/console/src/println.h2 b/tests/projects/cppfront/console/src/println.h2 new file mode 100644 index 000000000..24c244da4 --- /dev/null +++ b/tests/projects/cppfront/console/src/println.h2 @@ -0,0 +1,4 @@ +println: (msg: _) -> int = { + std::cout << msg; + return 0; +} diff --git a/tests/projects/cppfront/console/xmake.lua b/tests/projects/cppfront/console/xmake.lua index 65b68cd6e..4c99bfadb 100644 --- a/tests/projects/cppfront/console/xmake.lua +++ b/tests/projects/cppfront/console/xmake.lua @@ -6,5 +6,6 @@ target("test") add_rules("cppfront") set_kind("binary") add_files("src/*.cpp2") + add_files("src/*.h2") add_packages("cppfront") 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") |
