30 November 2014

SystemC on OS X

Aren't you tired of logging into a Linux server, or resorting to a virtual machine to use SystemC? Wouldn't you rather be using your shiny Mac and the awesome Clang C++ compiler? This is how you can do it.

Install Apple's "Command Line Tools". You have two options: install Xcode (a big download), or just the command line tools (a much smaller download). If your goal is simply building SystemC applications at the command line, then I recommend the latter.

Install Apple's "Command Line Tools" by launching Terminal, entering

$ xcode-select --install

then clicking Install. After that, you'll have make, clang and more available at the command line.

Build and install Accellera's SystemC implementation. Download the latest release from the Accellera Downloads page (annoyingly, you'll have to provide a few personal details) and extract the contents of the .zip file.

I like to keep a copy of the SystemC source code available, because it can be useful for debugging or understanding how something works. Therefore, I move the extracted folder (systemc-2.3.1) into ~/Work/Other. That's where I keep source code for third party libraries. However, you can put it wherever you like.

Open Terminal, change into the extracted folder (systemc-2.3.1), and execute:

$ mkdir build  
$ cd build  
$ export CXX=clang++  
$ ../configure --with-arch-suffix=  
$ make install

The --with-arch-suffix= option prevents a -macosx64 suffix being add to the lib folder name, allowing your build scripts to be simpler.

After that process, the salient include and lib folders should be available within the systemc-2.3.1 folder.

Configure your build environment. There are many ways you can do this; I have a simple approach that I believe is close to what the SystemC maintainers envisioned. I define two environment variables in my .bash_profile (executed for every new Terminal session on OS X):

export CXX="clang++ -fcolor-diagnostics"  
export SYSTEMC_HOME=~/Work/Other/systemc-2.3.1

Build a SystemC application. You could use Make, the quintessential build tool, which you get with Apple's "Command Line Tools", or any one of the plethora of other options. I use SCons with SConstruct files that look something like this:

import os  
env = Environment(CXX=os.environ["CXX"],  
env.Program("main.cpp", LIBS="systemc")

View trace (VCD) files. Scansion is a nice tool for this. GTKWave is another option, but it's a bit clunky.

Now you're rocking!