This section details how to build your own development version of Slicer. You can also use it if you wish to run a version from the CVS repository. It details what support libraries that you need to install first, how to get the Slicer code from CVS, and how to build it all.
These instructions were originally written for UNIX/Linux machines. Windows requires a similar setup if you are using cygwin, which provides a UNIX-like command prompt.

The build process that the developers use assumes that third-party sources (Tcl and VTK) are built in subdirectories of slicer2/Lib/[osname]. This procedure assumes that arrangement.

You can also refer to the alternate instructions for Building Slicer 2.4 if you wish to build the release from sources.

1. Set Up

You need some software on your machine before starting.
If you check out the Slicer code from CVS first, you can run the tcl script found in slicer2/Scripts/genlib.tcl and it will build the support software for you (assuming you have a compiler and a cvs client available).

On Solaris especially, you must build VTK (and ITK) against the same version of Tcl that you will be using to run Slicer. Tcl, VTK, and Slicer must all be compiled with the same compiler.
For Windows, chances are good that the precompiled binaries were compiled with Microsoft Visual Studio, though there may be version issues.

The classes that Slicer adds to VTK are found in the directory slicer2/Base/cxx.

2. Get Slicer2


You will need to check the source code out from CVS in order to get the latest version. In an xterm or a cygwin window, do the following:

cvs -d :pserver:anonymous@cvs.spl.harvard.edu:/projects/cvs/slicer login
cvs -d :pserver:anonymous@cvs.spl.harvard.edu:/projects/cvs/slicer checkout slicer2

The password for the anonymous (read only) account is bwhspl. Replace anonymous with your user name if you have a CVS account.
If, under cygwin, you have problems logging into the CVS server because your cvspass file couldn't be found, set your HOME variable to the path to your cygwin home directory and use the tcsh shell instead of bash.

Make a sub directory in the slicer2/Base/builds directory named for your operating system: solaris8, redhat7.3, Win32VC7 are the current valid operating system values. If you change this, you will need to edit slicer2/slicer_variables.tcl to reset your operating system version. At run time, the launcher will look in the subdirectory for the operating system on which you are running the program in order to load the library files.

Then point cmake or CMakeSetup.exe to slicer2/Base as the source and your new builds directory as the destination, and point it to your vtk4.x build and you should be ready to compile.

3. Compile Slicer2


We have provided a convenient script to allow one step configuring and building of Slicer. slicer2/Scripts/cmaker.tcl contains the commands to set up cmake and then start the compilation after cmake generates your make files. cmaker.tcl sources the slicer2/slicer_variables.tcl file, which sets up the environment variables needed for the compilation (and run) step.
Edit slicer_variables.tcl with your favourite text editor and set the variables for your platform. The variables that need to be set are at the bottom of the file, switched on the operating system. SLICER_HOME is set automatically from the directory that the slicer_variables.tcl file is in. At the SPL, under SunOS, we use:

set VTK_DIR /projects/birn/slicer2/Lib/solaris8/vtk/VTK-build-[version]
set VTK_SRC_DIR /projects/birn/slicer2/Lib/solaris8/vtk/VTK-[version]
set ITK_BINARY_PATH /projects/birn/itk/itk-1.2/itk-build
set COMPILER_PATH "/local/os/bin" set COMPILER "g++"

For Windows, you will need to point the COMPILER variable to the MS Visual Studio compiler, cl.exe. Slicer will pick up the Tcl settings from VTK.

Then execute:

slicer2/Scripts/cmaker.tcl

This will configure and build the Slicer core against the version of VTK that you supplied. It will also compile the distributed Modules in the slicer2/Modules subdirectory and any others that you specify (see Adding a Module for more details). Slicer inherits CMake settings from VTK, which inherits some CMake settings from Tcl, which is why all three must be compiled with the same compiler.

3.5. Compiling Slicer2 the Hard Way


For finer control over the build process:

cd slicer2/Base/builds
mkdir [my-os]
cd slicer2/Base/builds/[my-os]
ccmake -i ../../

NOTE: Replace [my-os] with the name and version of your operating system, for example, solaris8 or redhat7.3 or Win32VC7.
You will need to point ccmake to either the installed or the built versions of VTK, as you would have set above while editing slicer_variables.tcl. You must point to the proper tcl library, following the example from the SPL system:

Make sure WRAP_TCL is set to ON, and you are configured to use tkwidget, patented, local, shared, hybrid.

Once you're happy with your settings, you will need to type c to configure (repeat until all fields are filled in) and then g to generate make files.
ccmake writes a file called CMakeCache.txt. If you have errors using ccmake or compiling you may wish to edit that file directly, and then simply run cmake, which will read the file. However, it is often better to erase all subdirectories and start again.

Then run make in the slicer2/Base/builds/[my-os] directory. Repeat for any modules that you wish to build, starting in slicer2/Base/vtkCustomModule if you wish a practice directory.

4. Running Slicer


Edit slicer2/slicer_variables.tcl to reflect your local setup. Make sure that the environment variables VTK_DIR, ITK_BINARY_PATH, TCL_BIN_DIR, and TCL_LIB_DIR are pointing at the right directories. If you installed the support packages in slicer2/Lib or built them using the genlib.tcl script, you shouldn't need to make any changes.

The slicer2/slicer2-[os]-[arch] executables from cvs will read in launch.tcl and bootstrap Slicer. (NOTE: There is no need to run Scripts/make-launchers.tcl since most of the launch process is now in launch.tcl and cvs has the pre-made launchers.) Execute the file labeled for your operating system to start Slicer.

5. Running Tests of the slicer code


You need to have downloaded VTK4 data from http://prdownloads.sourceforge.net/vtk/VTKData-4.2.tar.gz?download. Then set the environment variable VTK_DATA_ROOT to point to where you installed it.
The launch.tcl script will accept a path to a Tcl script to execute, instead of the Slicer user interface. You can call it via:

cd ${SLICER_HOME}/Base/tests
../../slicer-[os]-[arch] ./TestImageCloseUp2D.tcl

You can also run the tests from VTK. Set the following environment variables appropriately, as they are set automatically in the slicer2 launching script, but we by-pass that script for the test:

SLICER_HOME /path_to_slicer2/slicer2
TCL_LIBRARY /path_to_lib/tcl8.4
TK_LIBRARY /path_to_lib/tk8.4
VTK_DATA_ROOT /projects/VTKData/
LD_LIBRARY_PATH ${SLICER_HOME}/Base/builds/[my-os]/bin:${LD_LIBRARY_PATH}
TCLLIBPATH "${SLICER_HOME}/Base/Wrapping/Tcl/vtkSlicerBase /usr/local/src/vtk4/VTK/Wrapping/Tcl"

To run TestImageCloseUp2D.tcl, for example, do the following:

cd ${SLICER_HOME}/Base/tests
vtk TestImageCloseUp2D.tcl