Cross compiling ParaView3 and VTK

From KitwarePublic
Jump to navigationJump to search

To cross compile ParaView3 and/or VTK you need ParaView3/VTK from cvs and cmake cvs (as of July 2007). The process of crosscompiling VTK is similar to the process of crosscompiling ParaView, so I'll focus on ParaView3, but it can be applied just the same way to crosscompiling VTK.

At first you need to set up the required cross compiling toolchain, how this is done is described here.

You will need an installation directory for all your cross compiled software, a good choice might be $HOME/bgl-install/ .

Building Mesa

If the target system doesn't have any OpenGL libraries or Mesa already installed, or if it doesn't has any display capabilities at all, you need to install the Mesa libraries, which offer an OSMesa component, the Offscreen-Mesa, so that the rendering goes into a memory buffer. You can get the Mesa sources from, the download section is at .

Building Mesa 7.0.1 or newer for BlueGene

Starting with version 7.0.1 building Mesa for BlueGene with the GNU toolchain nis supported out of the box.

All you have to do is to adjust the installation directory, this is done by modifying the INSTALL_DIR in configs/default, otherwise the cross compiled mesa will be installed to /usr/local/, which doesn't make sense. So search the entry for INSTALL_DIR and modify it to something like this:

# Installation directories (for make install)
INSTALL_DIR = /your/home/dir/bgl-install

Then you can simply build and install it. For building Mesa you need to call make with the configuration you want, so for BlueGene it looks like the following:

$ make bluegene-osmesa
$ make install

For similar systems it is probably the easiest way to reuse the bluegene-osmesa configuration file and adjust it to the specific system (e.g. using the right compiler).

If you want to use the IBM xlc toolchain support for this will be included in the next Mesa release, i.e. Mesa > 7.0.1, or you can get it now from the Mesa git repository:, follow link "Source code repository". The configuration name for this is "bluegene-xlc-osmesa".

Building Mesa 7.0.1 or newer for Cray Xt3/Catamount

You can build Mesa for Catamount using the Portland Group toolchain, but you have to modify one of the Mesa configuration files accordingly, e.g. configs/bluegene-osmesa:

# Configuration for building only libOSMesa on BlueGene, no Xlib driver
# This doesn't really have a lot of dependencies, so it should be usable
# on other (gcc-based) systems too.
# It uses static linking and disables multithreading.

include $(TOP)/configs/default

CONFIG_NAME = bluegene-osmesa

# Compiler and flags
CC = cc
CFLAGS = -target=catamount -O3 -fPIC -fastsse -Mnontemporal -Mprefetch=distance:8,nta -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE
CXXFLAGS = -target=catamount -O3 -fPIC -fastsse -Mnontemporal -Mprefetch=distance:8,nta -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURC



# Directories
SRC_DIRS = mesa glu
DRIVER_DIRS = osmesa
PROGRAM_DIRS = osdemos

# Dependencies

Then you can build it with "make bluegen-osmesa". Once this is tested that the resulting library actually works, please submit the configuration to so it will be included in the official Mesa releases (or let me know so I will do it, Alex).

Mesa 7.6.1 Cray XT4 Compute Node Linux (CNL)

Change the compiler lines in $MESA_SRC/config/linux-osmesa-static to read as follows:

 CC = cc
  1. make linux-osmesa-static
  2. make install DESTDIR=/my/install/dir

Building Python

Go to this page for information how to build Python with CMake. This includes instruction for building Python for IBM BlueGene/L and Cray Xt3/Catamount.


Cray XT4

copy CRAYXT_COMPUTE_LINUX.cmake to $cmake_install_dir/share/cmake2.x/Modules/Platform/

 #CRAYXT_COMPUTE_LINUX.cmake contents
 #Compute Node Linux, which runs on the compute nodes of Cray XT machines
 SET(CMAKE_SHARED_LIBRARY_C_FLAGS "")            # -pic 
 SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")       # +s, flag for exe link to use shared lib
 SET(CMAKE_SHARED_LIBRARY_PREFIX "lib")          # lib
 SET(CMAKE_EXECUTABLE_SUFFIX "")                 # .exe

Toolchains for crosscompiling


Following is the contents of a toolchain file:

# the name of the target operating system

# set the compiler
set(CMAKE_C_COMPILER cc -target=linux)
set(CMAKE_CXX_COMPILER CC -target=linux)

# set the search path for the environment coming with the compiler
# and a directory where you can install your own compiled software

# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment


cc and CC are the wrapped versions of the compiler on the front end nodes to build for the back end nodes. The wrapping can be seen by doing a cc -v or CC -v. The wrappings contain the correct directories and libraries for mpi and cpu optimization.


The directories listed here will be part of the search path for includes and libraries. These ROOT_PATHS will contain lib and include directories that will get searched. Therefore things like $MPI_HOME and $MESA_HOME would be listed here allowing cmake to find the includes and libraries in $HOMES/include and $HOMES/lib. Putting these items here spares you having to put explicit options in the cmake command line...




Building ParaView/VTK

Building a native ParaView

When building ParaView, some executables are executed which are built during the same build. Since the executables built for the target platform (generally) cannot run on the build host, two build trees are required, a native buildtree and the cross compiling build tree.

~/src/ $ cd ParaView3
~/src/ParaView3/ $ mkdir build-native
~/src/ParaView3/ $ mkdir build-bluegene

Make sure you turn all required options in build-native, e.g. if you need Python wrapping for the target platform you also need to enable Python wrapping in build-native/.

At first build the native version. If you don't need the Qt GUI, disable the option PARAVIEW_BUILD_QT_GUI. Using ccmake is recommended, there it is much easier to adjust the options than using cmake only.

~/src/ParaView3/build-native $ ccmake ..
~/src/ParaView3/build-native $ make
~/src/ParaView3/build-native $

Building ParaView for a target platform which is already supported

In cross compiling mode, ParaView loads the package ParaView3CompileTools via FIND_PACKAGE(ParaView3CompileTools REQUIRED). To find the package "ParaView3CompileTools", the ParaView3CompileTools_DIR variable has to be set to the build directory of the native build. In this directory a file named ParaView3CompileToolsConfig.cmake has been created during the build.

If you run CMake for cross compiling, it will finish with several error message, one for each TRY_RUN() which was found during the CMake run. When cross compiling the cross compiled executables usually can't run on the build host, so TRY_RUN() can't work. Instead the results for the TRY_RUN() commands have to be filled in manually. If you are building ParaView for BlueGene, this has already been done for you and you can just use the results:

~/src/ParaView3/build-bluegene $ ccmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-BlueGeneL-gcc.cmake -DParaView3CompileTools_DIR=~/src/ParaView3/build-native -C ~/src/ParaView3/CMake/TryRunResults-ParaView3-bgl-gcc.cmake ..

You can build ParaView also using the IBM xlc toolchain, you just need to replace TryRunResults-ParaView3-bgl-gcc.cmake with TryRunResults-ParaView3-bgl-xlc.cmake and specifiy a toolchain file for xlc instead gcc. The next step is to select the desired options in ccmake. If you want Python wrapping, but don't need a GUI, select the following options using ccmake:


E.g. on BlueGene make sure the following options are already set as shown below, this should happen automatically:


Building ParaView for Cray Xt3/Catamount

This is work in progress. Most things are similar to BlueGene, no shared libs, multithreading etc. So to get it build the file ParaView3/CMake/TryRunResults-ParaView3-bgl-gcc.cmake can be used here to for the beginning. The big difference is that Catamount doesn't support any sockets. You can find information about building software for Catamount with CMake on , including the required toolchain file.

Important: make sure you build ParaView with the same toolchain as you used for Mesa (i.e. PGI), otherwise there will be conflicts at least with -lm.

So basically you do the same thing as for BlueGene:

~/src/ParaView3/build-catamount $ ccmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchains/Toolchain-Catamount.cmake -DParaView3CompileTools_DIR=~/src/ParaView3/build-native -C ~/src/ParaView3/CMake/TryRunResults-ParaView3-bgl-gcc.cmake ..
  • Additionally the CMake option VTK_USE_METAIO (not METAIO_FOR_VTK !) has to be disabled.

In VTK/Parallel/VTKParallelCMakeTests.cmake there is now a cmake variable HAVE_SOCKETS, which is set to FALSE for Catamount. This is used to define a macro when building vtkSocket.cxx to skip the implementation and just return failure from all methods. This will allow applications that use sockets to link. At least non-sockets features of the applications will work.

There is a problem with large file support, dirent and readdir for Catamount, readdir is #defined to readdir64 if large file support is enabled, but dirent is still dirent and not dirent64. I inserted the following code once in kwsys/Directory.cxx and additionally in some more files in ParaView/VTK/. I guess that's not the best way to deal with this problem:

/* There is a problem with the Portland compiler, large file
support and glibc/Linux system headers:
#if defined(__PGI) && defined(__USE_FILE_OFFSET64)
# define dirent dirent64

Building ParaView for a new target platform

In the case you are cross compiling ParaView for a platform where there are no TryRunResults in ParaView/CMake/ you need to create this file yourself. This works as follows:

~/src/ParaView3/build-myplatform $ ccmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-MyPlatform-gcc.cmake -DParaView3CompileTools_DIR=~/src/ParaView3/build-native ..

You can do this in ccmake, but there is a better way. CMake will have created a file ${CMAKE_BINARY_DIR}/TryRunResults.cmake. This is a CMake script which already contains SET() commands for all required variables which TRY_RUN() couldn't figure out, accompanied by quite verbose comments which should help you in figuring out the correct results for the target platform. Copy this file to a save location (i.e. outside the build dir) and edit it:

~/src/ParaView3/build-myplatform $ cp TryRunResults.cmake ../ParaView3-MyPlatform-TryRunResults.cmake 
~/src/ParaView3/build-myplatform $ edit ../ParaView3-MyPlatform-TryRunResults.cmake 
~/src/ParaView3/build-myplatform $ ccmake -C ../ParaView3-MyPlatform-TryRunResults.cmake  .
~/src/ParaView3/build-myplatform $ make

The variables are:

  • CMAKE_REQUIRE_LARGE_FILE_SUPPORT ; enter 1 if your system doesn't have problems with large files
  • SHARED_LIBRARY_PATH_TYPE ; unused, set it to 0
  • SHARED_LIBRARY_PATH_TYPE__TRYRUN_OUTPUT ; enter the name of the environment variable on the target platform, which sets the search path for shared libraries, e.g. LD_LIBRARY_PATH on Linux . If the target system doesn't have shared libraries, set it to "".
  • VTK_TYPE_CHAR_IS_SIGNED ; if a char is signed by default on the target platform, enter 1 here, otherwise 0
  • VTK_ANSI_STREAM_EOF_RESULT ; if the stream library doesn't have bugs, enter 0 here, otherwise check VTK/CMake/vtkTestStreamEOF.cxx
  • KWSYS_LFS_WORKS ; if large file support doesn't have problems, enter 0 here
  • KWSYS_LFS_WORKS__TRYRUN_OUTPUT ; unused, ignore it
  • HDF5_PRINTF_LL_TEST_RUN ; set it to 0
  • HDF5_PRINTF_LL_TEST_RUN__TRYRUN_OUTPUT ; set it to "PRINTF_LL_WIDTH=[ll]" , where "ll" is the printf format option for 64 bit integers

As in the example shown above, you use this file to preload the cmake cache.

XT4 ParaView 3.6.2

ParaView3/VTK/CMake/vtkUseX.cmake looks like, added the 2nd to last line in the big IF block: SET(VTK_USE_X_OPTIONAL 1) This was required to not require a GL library...

                   "Build classes for the X11 window system." OFF

Make a change to the source code to handle shared library goo:

 diff -r original-ParaView3/VTK/Utilities/kwsys/DynamicLoader.cxx ParaView3/VTK/Utilities/kwsys/DynamicLoader.cxx
 < #if defined(__gnu_blrts__) || defined(__LIBCATAMOUNT__)
 > #if defined(__gnu_blrts__) || defined(__LIBCATAMOUNT__) || defined(__CRAYXT_COMPUTE_LINUX_TARGET)
 cmake \
 -DCMAKE_TOOLCHAIN_FILE=~/Toolchains/Toolchain-Linux.cmake  \
 -DParaView3CompileTools_DIR=../servicenodebin/ \
 -CTryRunResults-ParaView3-CNL-gcc.cmake \
 -DOSMESA_LIBRARY=/ccs/proj/paraview/mesa/7.6.1-jag/usr/local/lib/libOSMesa.a  \
 -DOSMESA_INCLUDE_DIR=/ccs/proj/paraview/mesa/7.6.1-jag/usr/local/include  \
 -DCMAKE_INSTALL_PREFIX=/ccs/proj/paraview/paraview/xt5_3.6.2  \
 -DMPI_LIBRARY=/opt/mpt/3.5.0/xt/mpich2-gnu/lib/libmpich.a \
 -DMPI_INCLUDE_PATH=/opt/mpt/3.5.0/xt/mpich2-gnu/include/  \

ParaView: [Welcome | Site Map]