-
System Requirements
-
Installation Notes for CMake
2.1 Sources for Compilers and Related Tools
2.2 Installation Steps
2.3 Cross compilation
2.4 Finding and Using SystemC with CMake
-
Installation Notes for Windows using Visual Studio C++
3.1 Microsoft Visual Studio C++ 2019 (compiler version 16.0) or later
3.2 Creating SystemC Applications
3.3 Building against a SystemC DLL
-
Known Problems
-
Resources
SystemC can be installed on the following platforms:
-
Linux
- Architectures
- x86_64 (64-bit)
- x86 (32-bit) application running on x86_64 (64-bit) kernel
(
../configure --host=i686-linux-gnu)
- Compilers
- GNU C++ compiler
- Clang C++ compiler
- or compatible
- Architectures
-
macOS
- Architectures
- Apple Silicon
- x86_64 (64-bit)
- Compilers
- Clang C++ compiler
- or compatible
- Architectures
-
Windows
- Compatibility layer
- MinGW / MSYS
- Architectures
- x86_64 (64-bit)
- Compilers
- GNU C++ compiler
- or compatible
- Visual Studio C++
- Win32 (32-bit)
- x64 (64-bit)
- Static library, DLL
- Compatibility layer
Note 1: IEEE Std. 1666-2023 mandates C++17 as the baseline for SystemC implementations, see RELEASENOTES.md. Make sure to configure your compiler accordingly (see below).
Note 2: Not all combinations are equally well-tested and some combinations may not work as expected. Please report your findings by following the instructions in the CONTRIBUTING file.
Note 3: CMake is the recommended build flow SystemC. Installation using the legacy GNU Autotools build flow can be found here.
To build, install, and use SystemC, you need the following tools:
- GNU C++ compiler (version 9.3 or later), or Clang C++ compiler (version 13.0 or later), or Visual Studio C++ (version msvc16 (2019) or later)
- GNU Make (make) or Ninja
- CMake
GCC, Clang, make, Ninja, and CMake are free software that you can obtain from the following sources:
- GCC https://www.gnu.org/software/gcc/index.html
- Clang https://clang.llvm.org/
- make https://www.gnu.org/software/make/make.html
- Ninja https://ninja-build.org/
- CMake https://cmake.org/
The CMake build scripts are compatible with CMake >=3.5 and have been tested on the following OS/processor/compiler platforms:
- macOS >= 13.6 until 15.4 (Xcode/AppleClang): x86_64, Apple Silicon, universal binary
- Linux (GCC, Clang): i386, x86_64
- Linux (GCC): aarch64
- Windows (MSYS2 with the MinGW-W32 or MinGW-W64 GCC toolchains, Visual C++): x86 (Win32), AMD64 (x64)
Typically, the following steps need to be followed to compile the sources using CMake:
-
Download and install CMake from this website (Linux distributions provide often a package).
-
Create a build subdirectory:
$ pwd .../systemc/ $ mkdir build -
Launch the interactive cmake console program
ccmake(on Unix) or the CMake GUI (Unix, macOS, Windows) and specify the source (.../systemc) and build directory (.../systemc/build). For the console basedccmake, this is done by changing into the build directory and launchingccmakewith the relative path to the source root directory as an argument:$ cd build/ $ ccmake ..For cmake-gui, the same approach works:
$ cd build/ $ cmake-gui ..Alternatively, the CMake GUI allows to directly enter the paths to the sources and build directory in the top of its main window.
-
Configure the sources by pressing 'c' or clicking on "Configure". Depending on the operating system, CMake will ask the user what it should generate Makefiles or IDE project files (Eclipse, Xcode, Kdevelop, Microsoft Visual Studio C++). CMake will parse the file
CMakeLists.txtin the source root directory and configure the sources accordingly carrying out all necessary platform-specific checks.The CMake build scripts detect the actual features provided by the target (Unix or Windows) platform. On Unix (including macOS), shared libraries can be built. If the QuickThreads library provides support for the target processor, it will be automatically used. Otherwise, we rely on Pthreads on Unix and Fiber on Windows. By default, the SystemC library installation will follow the GNU standard installation layout so that also other SystemC libraries (SystemC, SCV, TLM, AMS extensions) can be installed into the same directory hierarchy (Unix:
/opt/systemc/; Windows:$ENV{ProgramFiles}/SystemC/). The target platform's conventions are respected meaning usuallyinclude/for the headers andlib/,lib64/, orlib/<multiarch-tuple>/for the libraries. Thelib-${SYSTEMC_TARGET_ARCH})/convention is not used by default, as${SYSTEMC_TARGET_ARCH}does not reliably encode the OS/processor/compiler tuple.The build process can be configured through the configuration variables offered to the user in the CMake console and GUI (
ccmakeandcmake-gui, respectively). Each variable is annotated with a brief documentation string. The most important variables are:-
BUILD_SHARED_LIBSBuild shared instead of static libraries (default:ONif not targeting Windows). -
BUILD_SOURCE_DOCUMENTATIONBuild source code documentation using Doxygen (default:OFF). -
ENABLE_EXAMPLESAdd build targets for all examples under theexamples/folder, add composite targetsall-examplesandcheck-examplesto build and run all of them (default:ON). -
ENABLE_REGRESSIONAdd build targets for all regression tests under thetests/folder, add composite targetsall-testsandcheck-teststo build and run all of them (default:OFF). -
CMAKE_BUILD_TYPESpecifies the build type on single-configuration generators. (default:Release). -
CMAKE_CXX_STANDARDC++ standard to build all targets. (default:17). -
CMAKE_CXX_STANDARD_REQUIREDThe with CMAKE_CXX_STANDARD selected C++ standard is a requirement. (default:ON). -
CMAKE_INSTALL_PREFIXRoot directory of the SystemC libraries installation (defaults to$ENV{SYSTEMC_HOME}if set to an absolute path and otherwise to either/opt/systemc/(Unix-like platforms including CYGWIN),$ENV{ProgramFiles}/SystemC/(on Windows systems), or${CMAKE_INSTALL_PREFIX}/systemc. -
CMAKE_OSX_ARCHITECTURESArchitectures for cross-compilation on macOS (default: empty, i.e., only for the system processor). -
CMAKE_VERBOSE_MAKEFILEGenerate a verbose Makefile (default:OFF). -
ENABLE_WARNINGS_AS_ERRORSTreat compiler warnings as errors on supported compilers (default:OFF). -
DISABLE_COPYRIGHT_MESSAGEDo not print the copyright message when starting the application. (default:OFF). -
ENABLE_ASSERTIONSAlways enable thesc_assertexpressions (default:ON). -
ENABLE_PTHREADSUse POSIX threads for SystemC processes instead of QuickThreads on Unix or Fiber on Windows. -
SystemC_TARGET_ARCHTarget architecture according to the Accellera SystemC conventions set either from$ENV{SYSTEMC_TARGET_ARCH},$ENV{SYSTEMC_ARCH}, or detected by CMake. -
INSTALL_TO_LIB_BUILD_TYPE_DIRInstall the libraries tolib-${CMAKE_BUILD_TYPE}to enable parallel installation of the different build variants. (default:OFF). -
INSTALL_TO_LIB_TARGET_ARCH_DIRInstall the libraries tolib-<target-arch>to facilitate linking applications, which build systems assume to find SystemC inlib-<target-arch>. (default:OFF). -
INSTALL_LIB_TARGET_ARCH_SYMLINKOn Unix, install a symlinklib-<target-arch>tolib-${CMAKE_BUILD_TYPE}facilitating the linking of user code, which build system assumes to find the SystemC libraries underlib-<target-arch>. (default:OFF).
Other configuration variables will be proposed by CMake depending on the OS and detected processor, compiler, and libraries. For more information, please refer to the CMake documentation.
The configuration step needs to be repeated until no new configuration variables appear.
-
-
Generate the Makefiles or IDE project files by pressing 'g' or clicking on "Generate".
-
Compile, test, and install the libraries using make or the IDE:
$ make $ make check $ sudo make install
More documentation on using CMake is available from the the CMake Wiki.
CMake supports cross compilation on a host system for a different target architecture. Depending on the scenario, different approaches can be used.
This section is primarily relevant for users of 64-bit versions of Linux and Windows.
On 64-bit platforms like Linux x86_64 and Windows AMD64, the OS
provides usually for backward-compatibility the capability to execute
64-bit and 32-bit applications. To this end, it provides 32-bit and
64-bit versions of all runtime libraries (on Linux, they can be
usually found in the lib/ and lib64/ directories). On these platforms,
the GCC toolchain is usually installed in a multi-lib variant, which
supports the compilation and linking of 64-bit and 32-bit applications
and libraries. The word width of the target architecture is simply
chosen with the -m64 or -m32 option, which has to be consistently
passed at each compiler and linker call.
Therefore, it is in principle sufficient to add -m32 to the
corresponding CMake variables containing the flags to be passed to the
linker and compiler:
CMAKE_C_FLAGS
CMAKE_CXX_FLAGS
CMAKE_EXE_LINKER_FLAGS
CMAKE_MODULE_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS
CMAKE_STATIC_LINKER_FLAGS
These flags should be already set upon the first CMake invocation in a
new build directory, as most system introspection results are cached
over multiple CMake runs. You can do so via the -D<VAR>=<VALUE>
option of cmake, ccmake, and cmake-gui.
In a similar way, the particular C or C++ compiler can be chosen by providing the name (optionally preceded by the path) of the compiler executables:
CMAKE_C_COMPILER
CMAKE_CXX_COMPILER
However, it is very handy to know that CMake honors the standard
environment variables CC (C compiler), CXX (C++ compiler), CFLAGS
(C compiler flags), CXXFLAGS (C++ compiler flags), and LDFLAGS (linker
flags), which are also used by other tools such as GNU Make, to
initialize the above variables upon its first call in a new build
directory. Note, that CPPFLAGS is currently ignored by CMake, see
this issue.
On certain platforms, CMake might have trouble to find the right
library for the target processor architecture when using
find_package() or find_library() in the CMake scripts. In that case, it
can help to explicitly set the following global property in your CMake
file before issuing any find_package() or find_library() in your CMake
script:
set_property (GLOBAL FIND_LIBRARY_USE_LIB64_PATHS <TRUE|FALSE>)
If set to TRUE, it will look for the library in lib64/ instead of lib/.
This property is usually automatically set on platforms known to need
it, but depending on the chosen compiler options, it may need adjustment.
On macOS, a similar approach as in
Section 3.1
can be adopted. However,
it has to be noted that Apple's versions of GCC and Clang don't support
-m32 and -m64, but the more flexible -arch <arm64|x86_64>
parameter. The latter can be even repeated several times on the command
line to create universal binaries able to run on several processor
architectures. CMake has native support for this command line option,
which value can be set centrally in the CMake scripts and will be then
passed on to the compilers and linker.
It is sufficient to set the variable CMAKE_OSX_ARCHITECTURES to the
desired target architecture(s). Multiple architectures are separated
with a ;. You can do so already on the command line
$ cmake .. -DCMAKE_OSX_ARCHITECTURES='x86_64;arm64'
or in variable editors of ccmake and cmake-gui.
If you are using MacPorts or Homebrew versions of GCC, you will have to make sure that you install universal variants of the compiler toolchain. Then, you can follow the instruction in Section 3.1.
As CMake cannot guess the target system, a number of variables have to
be preset so that the correct compiler toolchain and libraries are
found. It is recommended to do this with a so-called toolchain file,
which is passed as an argument to cmake, ccmake or cmake-gui using the
option -DCMAKE_TOOLCHAIN_FILE=<path-to-file>. The file in CMake
syntax has to define the following variables:
CMAKE_SYSTEM_NAME(mandatory), e.g., "Linux", "Windows", "Darwin"CMAKE_SYSTEM_VERSION(optional)`CMAKE_SYSTEM_PROCESSOR(optional), e.g., "i386", "x86_64"CMAKE_C_COMPILER(mandatory), name of C compiler executableCMAKE_CXX_COMPILER(mandatory), name of C compiler executableCMAKE_FIND_ROOT_PATH(optional), root to target include and library directoriesCMAKE_FIND_ROOT_PATH_MODE_PROGRAM, either "NEVER", "ONLY", or "BOTH" (default)CMAKE_FIND_ROOT_PATH_MODE_LIBRARY, either "NEVER", "ONLY", or "BOTH" (default)CMAKE_FIND_ROOT_PATH_MODE_INCLUDE, either "NEVER", "ONLY", or "BOTH" (default)
The necessary steps are discussed in detail on the CMake Cross Compiling page.
The CMake build scripts install CMake package config files to facilitate finding
the SystemC and TLM libraries. The packages are called SystemCLanguage and
SystemCTLM. As the TLM support is compiled into the SystemC library, the package
SystemCTLM just finds the matching SystemC library as a dependency. As SystemC
is usually installed in its own directory tree, you have to tell CMake where to
look for the package config files by setting the variable CMAKE_PREFIX_PATH to
the root directory of your SystemC installation before calling find_package().
The SystemCLanguage package provides the imported target SystemC::systemc to
which an application or library should link to. Linking to an imported target
ensures that all necessary preprocessor definitions, compiler options, and
transitive link libraries are used when compiling and linking the application.
The SystemCLanguage package exports a number of variables:
-
SystemC_TARGET_ARCHTarget architecture according to the Accellera SystemC conventions -
SystemC_CXX_STANDARDPreferred C++ standard -
SystemC_CXX_STANDARD_REQUIREDDetermine whether the selected C++ standard is a requirement
The SystemC_CXX_STANDARD and SystemC_CXX_STANDARD_REQUIRED variables should be
used to initialize the respective CMAKE_CXX_STANDARD and
CMAKE_CXX_STANDARD_REQUIRED variables in the CMake build scripts of the
application/library. Alternatively, the CXX_STANDARD and CXX_STANDARD_REQUIRED
target properties can be set directly.
As an example, here is a minimal CMakeLists.txt to compile the simple_perf
SystemC example as a stand-alone application:
--- Start: CMakeLists.txt ---
cmake_minimum_required(VERSION 3.16)
project(simple_perf CXX)
set (CMAKE_PREFIX_PATH /opt/systemc)
find_package(SystemCLanguage CONFIG REQUIRED)
set (CMAKE_CXX_STANDARD ${SystemC_CXX_STANDARD} CACHE STRING
"C++ standard to build all targets. Minimum version is C++17.")
set (CMAKE_CXX_STANDARD_REQUIRED ${SystemC_CXX_STANDARD_REQUIRED} CACHE BOOL
"The with CMAKE_CXX_STANDARD selected C++ standard is a requirement.")
add_executable(simple_perf simple_perf.cpp)
target_link_libraries(simple_perf SystemC::systemc)
--- End: CMakeLists.txt ---
This release has been tested on Visual C++ version 2019 running Windows 10.
Note: This section covers the installation based on Microsoft Visual C++. For Cygwin or MinGW-based installations, see Section 2.
Note: If you experience spurious errors about missing files in the downloaded archive, please make sure to download the release from the Accellera public SystemC repository and use an extractor supporting tar.gz archives.
The download directory contains two subdirectories: msvc16 and
examples/build-msvc.
The msvc16 directory contains the project and workspace files to
compile the systemc.lib library. Double-click on the SystemC.sln
file to launch Visual C++ 2019 with the workspace file. The workspace file
will have the proper switches set to compile for Visual C++ 2019.
Select Build SystemC under the Build menu or press F7 to build
systemc.lib.
The examples/build-msvc directory contains the project and workspace
files to compile the SystemC examples. Go to one of the examples
subdirectories and double-click on the .vcxproj file to launch Visual C++
with the workspace file. The workspace file will have the proper switches
set to compile for Visual C++ 2019. Select Build <example>.exe under the
Build menu or press F7 to build the example executable.
For convenience, a combined solution file SystemC_examples.sln with
all example projects can be found in the examples/build-msvc directory.
A similar solution file tlm_examples.sln for the TLM examples is available
as well.
The provided project files are prepared for both the 32-bit (Win32) and 64-bit (x64) configurations. Please refer to the Microsoft Visual Studio documentation for details about 64-bit builds.
In addition to building static libraries for SystemC, the provided project
files include support for building a SystemC DLL (configurations DebugDLL,
ReleaseDLL).
-
Start Visual Studio. From the Start Page select New Project and Win32 Console Project. Type the project name and select a suitable location then click OK.
-
Select the Application Settings page of the Win32 Application Wizard and make sure the 'Empty project' box is ticked. Click 'Finish' to complete the wizard.
-
Add new/existing C++ files to the project and edit code.
-
Display the project Property Pages by selecting 'Properties...' from the Project menu.
-
From the C/C++ tab, select the Language properties and set 'Enable Run-Time Type Info' to Yes.
-
From the C/C++ tab, select the Command Line properties and add
/vmgto the 'Additional Options:' box. -
From the Linker tab, select the Input properties and type
systemc.libin the 'Additional Dependencies' box. -
Click OK.
Also make sure that the compiler and linker can find the SystemC header and library files respectively. There are two ways to do this:
To update the include file and library directory search paths for all projects:
-
Select Tools -> Options... and the Projects -> VC++ Directories tab
-
Select show directories for: Library files
-
Select the 'New' icon and browse to:
C:\systemc-3.0.0\msvc16\systemc\debug -
Select show directories for: Include files
-
Select the 'New' icon and browse to:
C:\systemc-3.0.0\src
To add the include file and library directory search paths for the current project only:
-
Display the project Property Pages by selecting 'Properties...' from the Project menu.
-
From the C/C++ tab, select the General properties and type the path to the SystemC
srcdirectory in the text entry field labeled 'Additional include directories' (e.g., the examples use..\..\..\src). -
From the Linker tab, select the General properties and type the path to the SystemC library:
...\systemc-3.0.0\msvc16\systemc\debugin the 'Additional Library Directories:' box. -
Click OK.
In order to link your application against a DLL-build of SystemC (build
configurations DebugDLL, ReleaseDLL in the SystemC library build),
several changes are needed.
-
Adjust the linker library directory settings to reference
DebugDLL(orReleaseDLL) instead ofDebugorRelease, respectively:...\systemc-3.0.0\msvc16\systemc\DebugDLL -
Add the preprocessor switch
SC_WIN_DLLto your project's properties (C/C++ -> Preprocessor -> Preprocessor Definitions). -
When running the simulation, you need to add the location of the SystemC DLL to your
PATHvariable.
- The CMake build scripts require more thorough testing of the various build configurations on as many platforms as possible. For the moment, testing has been primarily done on macOS (x86_64 and i686), Linux (x86_64 and i686) and Windows 10 using Visual Studio 2019 (16) (Win32 and x64).