Installing STIR with CMake: Difference between revisions

From STIR
stir>Krthie
stir>Krthie
→‎Mac OS X: add link to XCode and section for manual downloads
Line 62: Line 62:


=== Mac OS X ===
=== Mac OS X ===
You need the development environment. It's probably a good idea to install [http://www.macports.org/ MacPorts]. Then you should be able to use the following:
You need the development environment. You would need for instance
* XCode https://developer.apple.com/xcode
It's probably a good idea to install [http://www.macports.org/ MacPorts]. Then you should be able to use the following:
<pre>
<pre>
sudo port install boost cmake
sudo port install boost cmake
</pre>
</pre>
Alternatively, you could install extra software manually. See [[Installing_STIR_with_CMake#Other_systems_or_manual_download]].


=== cygwin on Windows ===
=== cygwin on Windows ===

Revision as of 22:17, 13 July 2014

This page provides instructions on how to install STIR using CMake. You will need STIR 2.2 or later for this to work.

Introduction

CMake is a cross-platform tool for building projects. It allows STIR to have a unique set of files that describe the libraries, tests etc, independent of the platform that you are using.

Building a project with STIR involves three steps: you first need to install some external packages, then run CMake to generate files appropriate to your build system. Then you use your build system to actually do the compilation, testing, installation etc. A build system can be your IDE (e.g. Visual Studio), make on Unix/Linux etc.

You might want to check the CMake help pages for more information. For example,

Step 1: Download/install pre-requisites

More detailed instructions are in the STIR User's Guide, but the following might get you going.

STIR relies on a few external libraries which you need to install first.

  • Boost, a well-respected C++ library which forms the basis for many newer C++ features.
  • python is a scripting language. STIR currently only uses it in some of the SimSET scripts.
  • The ECAT Matrix library from Merence Sibomana and Christian Michel. Only used to read/write data from old CTI PET scanners such as ECAT HR+. You might find this library at a Louvain-la-Neuve university ftp-site. It also comes with GATE.


Unix-type systems

Linux systems use a package management system. Unfortunately, there are many different versions, and the packages have slightly different names. Here is what we know:

debian/Ubuntu or others using APT

apt-get install gcc g++ make  cmake-curses-gui libncurses-dev libx11-dev libboost-dev tcsh python

(prefix with sudo for Ubuntu). If you intend to build the python interface to STIR as well, you will need to add the python-dev package to the above list, and install some other useful packages. For instance

apt-get install python-dev ipython python-matplotlib mayavi2

If you will be compiling with MPI support, use

apt-get install mpi-default-dev mpi-default-bin

If you want to use ITK for extra IO capabilities (since STIR 3.0), use

apt-get install libinsighttoolkit4-dev libtiff5-dev

Fedora (and others?) using yum

The following might work when your system uses yum.

sudo yum install gcc gcc-c++ make cmake cmake-gui ncurses-devel  libX11-devel boost boost-devel tcsh python

If this fails, try to issue one "yum install" command for every package.

Arch using pacman

The following might work when your system uses pacman.

$ su
# pacman -Sy gcc make cmake cmake-gui ncurses  libx11 boost boost-libs tcsh python

If this fails, try to issue one "pacman -Ss" command for every package.

Mac OS X

You need the development environment. You would need for instance

It's probably a good idea to install MacPorts. Then you should be able to use the following:

sudo port install boost cmake

Alternatively, you could install extra software manually. See Installing_STIR_with_CMake#Other_systems_or_manual_download.

cygwin on Windows

Use cygwin's setup to install gcc4, gcc4-g++, make, cmake, libncurses-devel, libX11-devel, libboost-devel, tcsh, python.

Other systems or manual download

You can use these also if you don't have super-user permission.

  • Download CMake from http://www.cmake.org and install.
  • Download Boost from http://www.boost.org. Currently, STIR only uses the include files from Boost so you do not need to build the boost libraries, only untar/unzip the boost package. You can put this anywhere you like, as long as you set the BOOST_ROOT flag accordingly (See below).
  • Download SWIG http://www.swig.org if you want to use SWIG to build an interface between STIR and Python (or soon MATLAB). Clearly, you would need Python then as well.

Step 2: Run cmake

Launching CMake

If you have Windows or MacOSX, CMake comes as an application with a nice GUI. After launching it, you first select the source directory (STIR) and then a build directory. It's recommended to build one level up from STIR. Call it anything you like, e.g. STIR-bin. (On Unix/Linux/MacOSX you will probably be using make to build things. In that case, you want different build directories for every type of build (Debug or Release) you want to make. On Windows when using Visual Studio, you can build different versions from one CMake configuration).

On Unix/linux (or MacOSX from a terminal window), you have to use a slightly more basic user interface. You would launch this as follows.

mkdir STIR-bin
cd STIR-bin
mkdir Release
cd Release
ccmake ../../STIR

As an alternative for Unix/linux users, one can install cmake-gui. Instead of "ccmake" one executes cmake-gui.

cmake-gui ../../STIR

Configuring the STIR build

Once CMake has started, you have to press the 'Configure' button (or c key). In this step, CMake will try to find out as much as it can about your set-up. For instance, it will check what your default compiler is, where the C++ include files are located, if you have X windows (and the curses library installed), if you have the boost C++ library etc.

You might get a "help" screen with some information, which you'll need to close (after reading the information of course). For example, if some required libraries are missing, it will tell you. e.g. saying that FindBoost.cmake cannot find boost and that you need to set the BOOST_ROOT variable. You then get back to a screen with the configuration variables, where you can adjust things. For example, if you installed boost somewhere where cmake didn't find it, you can edit its location there (set BOOST_ROOT to where you extracted boost).

Most of the variables should normally be fine. You need to set 'CMAKE_BUILD_TYPE' and probably want to change 'CMAKE_INSTALL_PREFIX'.

If you change one of the variables, you will have to configure again. For example, on my Linux system, the variables end up to something like this.

 AVW_ROOT_DIR                                                                  
 BOOST_ROOT                                                                    
 BUILD_SHARED_LIBS                OFF                                          
 CMAKE_BUILD_TYPE                 Release
 CMAKE_INSTALL_PREFIX             /home/kris/                
 CURSES_CURSES_H_PATH             /usr/include                                 
 CURSES_FORM_LIBRARY              /usr/lib/libform.so                          
 CURSES_HAVE_CURSES_H             /usr/include/curses.h                        
 DISABLE_AVW                      OFF                                          
 DISABLE_LLN_MATRIX               OFF                                          
 DISABLE_RDF                      OFF                         
 DISABLE_STIR_LOCAL               OFF                          
 GRAPHICS                         X                                            
 LLN_INCLUDE_DIRS                 /home/kris/devel/lln/ecat                    
 LLN_LIBRARIES                    /home/kris/devel/lln/ecat/debuggcc_64/libecat.a
 RDF_INCLUDE_DIRS                 RDF_INCLUDE_DIRS-NOTFOUND                    
 RDF_LIBRARIES                    RDF_LIBRARIES-NOTFOUND                       
 STIR_LOCAL                       /home/kris/devel/STIR/local        
 STIR_MPI                         OFF                                           
 STIR_OPENMP                      OFF                                          

A lot of these were set by CMake itself. Each variable has a one-line help message (which you can see by hovering over it in the CMake GUI, or by moving the cursor to the line with the variable in ccmake). See the next section for some info on STIR specific variables.

The 'LLN*' variables refer to the ECAT LLN library. The 'AVW_ROOT_DIR' variable refers to the location of the AnalyzeAVW commercial library. The 'RDF*' variables refer to a GE proprietary library to read GE PET Raw Data Files. From STIR 3.0 you will also see 'ITK_DIR' to use the ITK library. If you have any of these, setting these variables appropriately gives you some extra IO capabilities in STIR.


Once you are happy, you have to press generate. After this, you can quit CMake.

Configuration flags

  • The 'DISABLE_*' variables allow you to disable some features, even if you have the necessary libraries.
  • 'GRAPHICS' can be set to specify the type of graphics output. See the STIR User's Guide.
  • 'STIR_MPI' switches on the use of the MPI library for reconstruction. This will then look for MPI libraries on your system. See the STIR User's guide for how to run executables compiled with MPI.
  • 'STIR_OPENMP' switches on the use fo OPENMP reconstruction. This will then look for OPENMP libraries on your system if necessary.
  • 'STIR_LOCAL' can be used to extend STIR with your own files. This needs further documentation.

Changing optimisation flags

You might want to change the compiler flags for optimal performance. For example, with GCC, it is probably a good idea to enable the -Ofast (from gcc 4.6) and -march=native flags. Intel C++ should benefit from the -fast flag. You can do this by changing the CMAKE_CXX_FLAGS_RELEASE setting. To do this, you will have to toggle Advanced Mode on.

Stage 3: actual compilation

The previous step used CMake to generate files for the build system appropriate for your OS. Now, you need to use the build system to compile STIR. We just list the 2 most common ones:

Unix-type systems: make

CMake will have created a series of directories in STIR-bin with a series of Makefiles. To build STIR, you just type

make

If there are compilation problems, you might want to see the compilation commands:

make VERBOSE=1

Run the tests (see also next section).

make test

You would normally finish with

make install

Windows and other systems with an IDE for compilation

CMake will have created a series of directories in the build directory with the necessary projects files. For example, for Visual studio, there will be a STIR.sln with targets ALL_BUILD, INSTALL, RUN_TESTS (and projects for every for every library and executable). You would open the STIR solution, and build the relevant target. Remember to set the type of build (Release or Debug) first from your GUI.

Stage 4: testing via the build system

The previous step used CMake to generate files for the build system appropriate for your OS. As already indicated there, you should use the build system to test STIR. We list the 2 most common (?) cases:

Unix-type systems: make

Still in the build directory, you type

make test

(Note that the Makefiles generated by cmake have test as an independent target, not depending on all. Therefore, if you change the source code, you need to make first, before doing make test.)

If one of the tests fails, you can normally find a log in Testing/Temporary/LastTest.log. You should check this out, and if you're stuck, post it to the stir-users mailing list.

If you want to run only a single test, you can do that as follows

ctest -R name

You can use regular expressions to match the names of any test you want to run. Further options and more details can be found at [1].

Windows and other systems with an IDE for compilation

As in the previous section, there should be a RUN_TESTS target available via your GUI. You should build that one. (Or you can build and run any of the test_* targets if you want to run only a single test).

Stage 5: Using the recon_test_pack

Don't forget to download the recon_test_pack from the STIR web-site, unpack it, and read its README.txt. Note that running these tests will be easier if you first install STIR. You can then pass the installation directory as an argument to the test scripts (or batch files).

Content license

All content on this wiki uses the Creative Commons Attribution-ShareAlike 3.0 Unported License File:CreativeCommons-BY-SA-Logo.png