summaryrefslogtreecommitdiff
path: root/xmake/rules
diff options
context:
space:
mode:
authorruki <[email protected]>2023-01-14 10:31:52 +0800
committerruki <[email protected]>2023-01-14 10:31:52 +0800
commit096498b2d1cb6b813a4545ffc407ebceddf596e4 (patch)
treed2c73cc40691096cb0c641aa6b7b9fdb8c13e82c /xmake/rules
parent3b840b5a71c8f99849381343a28a1ef81a76d4aa (diff)
build passed
Diffstat (limited to 'xmake/rules')
-rw-r--r--xmake/rules/verilator/xmake.lua28
1 files changed, 25 insertions, 3 deletions
diff --git a/xmake/rules/verilator/xmake.lua b/xmake/rules/verilator/xmake.lua
index 5b706f675..4e9823c09 100644
--- a/xmake/rules/verilator/xmake.lua
+++ b/xmake/rules/verilator/xmake.lua
@@ -45,6 +45,8 @@ endmodule]])
-- parse some configurations from cmakefile
local verilator_root
+ local global_classes
+ local targetname = target:name()
io.gsub(cmakefile, "set%((%S-) (.-)%)", function (key, values)
if key == "VERILATOR_ROOT" then
verilator_root = values:match("\"(.-)\" CACHE PATH")
@@ -54,8 +56,12 @@ endmodule]])
end
end)
assert(verilator_root, "the verilator root directory not found!")
+ target:data_set("verilator.root", verilator_root)
-- add includedirs
+ if not os.isfile(autogendir) then
+ os.mkdir(autogendir)
+ end
target:add("includedirs", autogendir)
target:add("includedirs", path.join(verilator_root, "include"))
target:add("includedirs", path.join(verilator_root, "include", "vltstd"))
@@ -83,7 +89,6 @@ endmodule]])
-- add syslinks
if target:is_plat("linux", "macosx") then
target:add("syslinks", "pthread")
- target:add("ldflags", "-fcoroutines")
end
os.rm(tmpdir)
@@ -105,7 +110,6 @@ endmodule]])
table.join2(argv, sourcefiles)
-- generate c++ sourcefiles
- batchcmds:mkdir(autogendir)
batchcmds:vrunv(verilator, argv)
batchcmds:add_depfiles(sourcefiles)
batchcmds:set_depmtime(os.mtime(cmakefile))
@@ -117,10 +121,28 @@ endmodule]])
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 dependfile = path.join(autogendir, targetname .. ".build.d")
+ local verilator_root = assert(target:data("verilator.root"), "no verilator_root!")
+
+ -- parse some configurations from cmakefile
+ local global_classes = {}
+ io.gsub(cmakefile, "set%((%S-) (.-)%)", function (key, values)
+ if key == targetname .. "_GLOBAL" then
+ -- get global class source files
+ -- set(hello_GLOBAL "${VERILATOR_ROOT}/include/verilated.cpp" "${VERILATOR_ROOT}/include/verilated_threads.cpp")
+ for classfile in values:gmatch("\"(.-)\"") do
+ classfile = classfile:gsub("%${VERILATOR_ROOT}", verilator_root)
+ if os.isfile(classfile) then
+ table.insert(global_classes, classfile)
+ end
+ end
+ end
+ end)
- -- TODO we need get correct files list
+ -- get compiled source files
local sourcefiles = os.files(path.join(autogendir, "*.cpp"))
+ table.join2(sourcefiles, global_classes)
-- do build
for _, sourcefile in ipairs(sourcefiles) do