I´m trying to port a Verilator TB from Make to CMake. My CMakeLists looks like this:
add_executable(example ./src/my_tb.cpp)
list(APPEND rtl_sources ../rtl/some_pkg.sv ../rtl/some_module.sv ../rtl/top_core.sv)
verilate(example
VERILATOR_ARGS -Wall --Wno-fatal --sv
INCLUDE_DIRS "./src"
SOURCES ${rtl_sources}
TOP_MODULE top_core)
When I run this, the verilate command ignores the TOP_MODULE
parameter and creates "Vsome_pkg.h"
and related files. This means that my cpp TB will not build, because it expects to include "Vtop_core.h"
.
I cannot move top_core.sv
to the head of the filelist because it uses the package; the filelist needs to reflect the RTL dependencies, as far as I can tell, otherwise verilate fails.
In the Make version of mt TB, I invoke verilate with --top top_core
and it all works just fine.
My verilator version is 5.018 and the Verilator reference documentation I´m using is for 5.017.
Also, I made a few experiments and TOP_MODULE
fails if I use a non-existent module name, so it definitely is being read by the verilate command; yet somehow it´s being ignored.
I am a complete newcomer to CMake (I started the port today because I need to improve my TB with C++ libraries that in practice demand CMake) so I am pretty sure I am missing something basic.
Any help in spotting what I´m missing will be greatly appreciated!
SUMMARY: I expected the verilate command to use my TOP_MODULE argument and generate "Vtop_core.h" and related files.
Instead, it apparently ignored TOP_MODULE and used the first element of SOURCES as top module.
UPDATE: I just noticed that the executed command line for verilate looks like this:
Verilator command: "/ucrt64/bin/verilator_bin.exe --compiler gcc --prefix Vsome_pkg
--Mdir [...]/build/CMakeFiles/example.dir/Vsome_pkg.dir
--make cmake --top top_core --cc
-y ./src -Wall --Wno-fatal
../rtl/some_pkg.sv ../rtl/some_module.sv ../rtl/top_core.sv"
(newlines added for readability)
So the --top
argument is included in the command, but it can´t override the --Mdir
and --prefix
arguments.
More comments to follow as I do a few trials...
FURTHER UPDATE
If I add this to my verilate command
PREFIX Vtop_core
...then the whole thing works; verilate creates the Vtop_core.h and related files and the build now fails for a different and probably unrelated reason.
So this change fixes my problem. But it looks kinda hacky.
I´ll do a few more trials and will auto-respond this question later on, but if anyone can shed any light on this, it will help me a lot!
Adding parameter
PREFIX Vtop_core
to the verilate command fixes the issue.I am pretty sure this is not the canonic way to use SV packages in a CMake-enabled Verilator TB but it works.