Necessity of writing 'include "uvm_macros.svh"

In reply to EnRoute_zt:

Compiler directives like the `define macros to not exist in any scope like a package. There are processed before recognizing any SystemVerilog syntax. They only exist while the current unit of code is being compiled (the compilation unit).

So it the answer to your question depends on whether the uvm_pkg was compiled as part of a separate compilation unit from where the code the imports the uvm_pkg, or not. Usually people use pre-compiled libraries for the uvm_pkg, so you need to do both the import and `include.

For the other case when everything is compiled as a single compilation unit, it doesn’t matter if you repeat the `include because there are compile guards in the uvm_macros.svh file that prevent redefinition warnings.

So you might as well `include in both cases just to keep your code more adaptable.