From 279f21bb5b3cb43a02c4d0d469730c259a8e130b Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 28 May 2020 18:51:46 -0400 Subject: [PATCH] Configure now enables SystemC if it is installed as a system headers. --- Changes | 3 +++ configure.ac | 14 ++++++++++++ examples/make_tracing_sc/Makefile_obj | 4 ++-- include/verilated.mk.in | 4 ++-- src/V3EmitMk.cpp | 9 +++++++- src/V3Options.cpp | 32 +++++++++++++++------------ src/V3Options.h | 2 ++ src/config_build.h.in | 4 ++++ test_regress/driver.pl | 8 ++++--- 9 files changed, 58 insertions(+), 22 deletions(-) diff --git a/Changes b/Changes index 2d8f45a68..0123f85f9 100644 --- a/Changes +++ b/Changes @@ -8,6 +8,9 @@ The contributors that suggested a given feature are shown in []. Thanks! ** OPT_FAST is now -Os by default. See the BENCHMARKING & OPTIMIZATION part of the manual if you experience issues with compilation speed. +*** Configure now enables SystemC if it is installed as a system headers, + e.g. with 'apt-get install systemc-dev'. + *** Add --waiver-output flag that writes a verilator config file (.vlt) with waivers to the warnings emitted during a Verilator run. diff --git a/configure.ac b/configure.ac index 066b6f47d..e9cf799a6 100644 --- a/configure.ac +++ b/configure.ac @@ -442,6 +442,20 @@ AC_CHECK_MEMBER([struct stat.st_mtim.tv_nsec], [AC_DEFINE([HAVE_STAT_NSEC],[1],[Defined if struct stat has st_mtim.tv_nsec])], [], [#include ]) +# HAVE_SYSTEMC +# - If found the default search path has it, so support is always enabled. +# - If not found or not system-wide, user can set SYSTEMC_INCLUDE. +# AC_CHECK_HEADERS seems to not locate on Travis-CI but include does work. +AC_MSG_CHECKING([whether SystemC is found (in system path)]) +AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[#include + ]],[])], + [_my_result=yes + AC_DEFINE([HAVE_SYSTEMC_H],[1],[Defined if have systemc.h])], + [_my_result=no]) +AC_MSG_RESULT($_my_result) +AC_SUBST(HAVE_SYSTEMC_H) + # Checks for system services # Other install directories diff --git a/examples/make_tracing_sc/Makefile_obj b/examples/make_tracing_sc/Makefile_obj index a2a4d2757..a2d175a27 100644 --- a/examples/make_tracing_sc/Makefile_obj +++ b/examples/make_tracing_sc/Makefile_obj @@ -37,8 +37,8 @@ endif # If you build your own rules from scratch, note you need to include # SystemC as follows (Vtop.mk file includes verilated.mk with these # already). -# CPPFLAGS += $(SYSTEMC_CXX_FLAGS) -I$(SYSTEMC_INCLUDE) -# LDFLAGS += $(SYSTEMC_CXX_FLAGS) -L$(SYSTEMC_LIBDIR) +# CPPFLAGS += $(SYSTEMC_CXX_FLAGS) $(addprefix -I, $(SYSTEMC_INCLUDE)) +# LDFLAGS += $(SYSTEMC_CXX_FLAGS) $(addprefix -L, $(SYSTEMC_LIBDIR)) # See the benchmarking section of bin/verilator. # Support class optimizations. This includes the tracing and symbol table. diff --git a/include/verilated.mk.in b/include/verilated.mk.in index 6922a8b53..3a8487c2d 100644 --- a/include/verilated.mk.in +++ b/include/verilated.mk.in @@ -105,8 +105,8 @@ OPT_GLOBAL = -Os ##### SystemC builds ifeq ($(VM_SC),1) - CPPFLAGS += $(SYSTEMC_CXX_FLAGS) -I$(SYSTEMC_INCLUDE) - LDFLAGS += $(SYSTEMC_CXX_FLAGS) -L$(SYSTEMC_LIBDIR) + CPPFLAGS += $(SYSTEMC_CXX_FLAGS) $(addprefix -I, $(SYSTEMC_INCLUDE)) + LDFLAGS += $(SYSTEMC_CXX_FLAGS) $(addprefix -L, $(SYSTEMC_LIBDIR)) SC_LIBS = -lsystemc ifneq ($(wildcard $(SYSTEMC_LIBDIR)/*numeric_bit*),) # Systemc 1.2.1beta diff --git a/src/V3EmitMk.cpp b/src/V3EmitMk.cpp index 40887aa93..e148bb1a0 100644 --- a/src/V3EmitMk.cpp +++ b/src/V3EmitMk.cpp @@ -160,6 +160,13 @@ public: of.puts("# SystemC library directory with libsystemc.a (from $SYSTEMC_LIBDIR)\n"); of.puts(string("SYSTEMC_LIBDIR ?= ") + V3Options::getenvSYSTEMC_LIBDIR() + "\n"); + // Only check it if we really need the value + if (v3Global.opt.usingSystemCLibs() && !V3Options::systemCFound()) { + v3fatal("Need $SYSTEMC_INCLUDE in environment or when Verilator configured,\n" + "and need $SYSTEMC_LIBDIR in environment or when Verilator configured\n" + "Probably System-C isn't installed, see http://www.systemc.org\n"); + } + of.puts("\n### Switches...\n"); of.puts("# SystemC output mode? 0/1 (from --sc)\n"); of.puts(string("VM_SC = ") + ((v3Global.opt.systemC()) ? "1" : "0") + "\n"); @@ -234,7 +241,7 @@ public: of.puts("\n### Link rules... (from --exe)\n"); of.puts(v3Global.opt.exeName() + ": $(VK_USER_OBJS) $(VK_GLOBAL_OBJS) $(VM_PREFIX)__ALL.a\n"); - of.puts("\t$(LINK) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ $(LIBS) $(SC_LIBS)\n"); + of.puts("\t$(LINK) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) $(LIBS) $(SC_LIBS) -o $@\n"); of.puts("\n"); } diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 0c88e6030..abf45a1ec 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -540,13 +540,6 @@ string V3Options::getenvSYSTEMC_INCLUDE() { string sc = getenvSYSTEMC(); if (sc != "") var = sc + "/include"; } - // Only correct or check it if we really need the value - if (v3Global.opt.usingSystemCLibs()) { - if (var == "") { - v3fatal("Need $SYSTEMC_INCLUDE in environment or when Verilator configured\n" - "Probably System-C isn't installed, see http://www.systemc.org\n"); - } - } return var; } @@ -561,13 +554,6 @@ string V3Options::getenvSYSTEMC_LIBDIR() { string arch = getenvSYSTEMC_ARCH(); if (sc != "" && arch != "") var = sc + "/lib-" + arch; } - // Only correct or check it if we really need the value - if (v3Global.opt.usingSystemCLibs()) { - if (var == "") { - v3fatal("Need $SYSTEMC_LIBDIR in environment or when Verilator configured\n" - "Probably System-C isn't installed, see http://www.systemc.org\n"); - } - } return var; } @@ -581,6 +567,19 @@ string V3Options::getenvVERILATOR_ROOT() { return var; } +bool V3Options::systemCSystemWide() { +#ifdef HAVE_SYSTEMC_H + return true; +#else + return false; +#endif +} + +bool V3Options::systemCFound() { + return (systemCSystemWide() + || (!getenvSYSTEMC_INCLUDE().empty() && !getenvSYSTEMC_LIBDIR().empty())); +} + //###################################################################### // V3 Options notification methods @@ -1514,6 +1513,7 @@ void V3Options::showVersion(bool verbose) { cout << " SYSTEMC_INCLUDE = " << DEFENV_SYSTEMC_INCLUDE << endl; cout << " SYSTEMC_LIBDIR = " << DEFENV_SYSTEMC_LIBDIR << endl; cout << " VERILATOR_ROOT = " << DEFENV_VERILATOR_ROOT << endl; + cout << " SystemC system-wide = " << cvtToStr(systemCSystemWide()) << endl; cout << endl; cout << "Environment:\n"; @@ -1526,6 +1526,10 @@ void V3Options::showVersion(bool verbose) { cout << " VERILATOR_ROOT = " << V3Os::getenvStr("VERILATOR_ROOT", "") << endl; // wrapper uses this: cout << " VERILATOR_BIN = " << V3Os::getenvStr("VERILATOR_BIN", "") << endl; + + cout << endl; + cout << "Features (based on environment or compiled-in support):\n"; + cout << " SystemC found = " << cvtToStr(systemCFound()) << endl; } //====================================================================== diff --git a/src/V3Options.h b/src/V3Options.h index af90dfbbf..2d9e42608 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -596,6 +596,8 @@ public: static string getenvSYSTEMC_INCLUDE(); static string getenvSYSTEMC_LIBDIR(); static string getenvVERILATOR_ROOT(); + static bool systemCSystemWide(); + static bool systemCFound(); // SystemC installed, or environment points to it // METHODS (file utilities using these options) string fileExists(const string& filename); diff --git a/src/config_build.h.in b/src/config_build.h.in index 02c915300..250ac1f96 100644 --- a/src/config_build.h.in +++ b/src/config_build.h.in @@ -77,6 +77,10 @@ using std::make_pair; // Define if struct stat has st_mtim.tv_nsec (from configure) #undef HAVE_STAT_NSEC +// Define if SystemC found +// - If defined, the default search path has it, so support is always enabled. +// - If undef, not system-wide, user can set SYSTEMC_INCLUDE. +#undef HAVE_SYSTEMC_H //********************************************************************** //**** OS and compiler specifics diff --git a/test_regress/driver.pl b/test_regress/driver.pl index cfe11b859..9a4dc39d4 100755 --- a/test_regress/driver.pl +++ b/test_regress/driver.pl @@ -1413,8 +1413,9 @@ sub sc { } sub have_sc { - #my $self = shift; - return 1 if (defined $ENV{SYSTEMC} || defined $ENV{SYSTEMC_INCLUDE}); + my $self = (ref $_[0]? shift : $Self); + return 1 if (defined $ENV{SYSTEMC} || defined $ENV{SYSTEMC_INCLUDE} || $ENV{CFG_HAVE_SYSTEMC}); + return 1 if $self->verilator_version =~ /systemc found *= *1/i; return 0; } @@ -2030,8 +2031,9 @@ sub _read_inputs_vhdl { our $_Verilator_Version; sub verilator_version { + # Returns verbose version, line 1 contains actual version if (!defined $_Verilator_Version) { - my @args = ("perl", "$ENV{VERILATOR_ROOT}/bin/verilator", "--version"); + my @args = ("perl", "$ENV{VERILATOR_ROOT}/bin/verilator", "-V"); my $args = join(' ',@args); $_Verilator_Version = `$args`; $_Verilator_Version or die "can't fork: $! ".join(' ',@args);