summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-01-14 00:43:42 +0800
committerruki <[email protected]>2023-01-14 00:43:42 +0800
commit8ad3149ead285bc6d347e5d573dc1240dfe29adc (patch)
treeb25e567ed6df7f5cddd20a437c3c104fd421caae
parent75b97c2509fd3d8eeec884c01c3eb6fc3635459a (diff)
generate cpp for verilator
-rw-r--r--xmake/rules/verilator/xmake.lua21
1 files changed, 20 insertions, 1 deletions
diff --git a/xmake/rules/verilator/xmake.lua b/xmake/rules/verilator/xmake.lua
index d2d8b9d5d..a6c71c57c 100644
--- a/xmake/rules/verilator/xmake.lua
+++ b/xmake/rules/verilator/xmake.lua
@@ -24,6 +24,25 @@ rule("verilator.binary")
target:set("kind", "binary")
end)
- on_buildcmd_files(function(target, batchcmds, sourcebatch, opt)
+ before_buildcmd_files(function(target, batchcmds, sourcebatch, opt)
+ local toolchain = assert(target:toolchain("verilator"), 'we need set_toolchains("verilator") in target("%s")', target:name())
+ local verilator = assert(toolchain:config("verilator"), "verilator not found!")
+ local autogendir = path.join(target:autogendir(), "rules", "verilator")
+ local targetname = target:name()
+ local cmakefile = path.join(autogendir, targetname .. ".cmake")
+
+ local argv = {"--cc", "--make", "cmake", "--prefix", targetname, "--Mdir", path(autogendir)}
+ local sourcefiles = sourcebatch.sourcefiles
+ for _, sourcefile in ipairs(sourcefiles) do
+ batchcmds:show_progress(opt.progress, "${color.build.target}compiling.verilator %s", path.filename(sourcefile))
+ end
+ table.join2(argv, sourcefiles)
+
+ -- generate c++ sourcefiles
+ batchcmds:mkdir(autogendir)
+ batchcmds:vrunv(verilator, argv)
+ batchcmds:add_depfiles(sourcefiles)
+ batchcmds:set_depmtime(os.mtime(cmakefile))
+ batchcmds:set_depcache(target:dependfile(cmakefile))
end)