VTK/CSharp/ActiViz/Build

From KitwarePublic
< VTK
Jump to: navigation, search

Current Status

There is an updated version of the wrappers under review for VTK6 with new modular source base: http://www.vtk.org/Wiki/VTK/CSharp/ComingSoon

See this related message on the status of gccxml: http://public.kitware.com/pipermail/gccxml/2010-November/001435.html

Build ActiViz.NET with Visual Studio Express C++ 2008

Preface: There's no need to build ActiViz.NET. You can download precompiled, ready to install versions (32-bit and 64-bit Windows XP and later) here:[1]
In case you would like to build your own ActiViz.NET control from scratch then you are at the right place.

Prerequisites to build ActiViz.NET

CMake (the cross-platform, open-source build system)

you can download it from: http://www.cmake.org

Concurrent Versions System (CVS)

It's a command line tool required at mummy configure time because it retrieves a snapshot of CableSwig for the source code to the cable libraries.

For windows you can download it from http://ftp.gnu.org/non-gnu/cvs/binary/stable/x86-woe/cvs-1-11-22.zip (contains nothing but a executable)

Once downloaded unzip the archive and copy the executable to a folder which is defined in the PATH environment variable.

Git client

A git client is needed to download the latest mummy and ActiViz sources.

you can download it from: http://msysgit.github.com/

Source control software (SVN)

(I'm not sure whether it's really necessary because I had it installed already and never tried to build vtk and ActiViz without svn.exe). You probably get an error message or a warning in case it will be necessary.

you can download it from: http://tortoisesvn.net/

Make sure you install the command line client tools during setup

Python

Python is required at ActiViz .NET build time to convert VTK tcl tests to C#.

you can download it from: http://www.python.org/getit/windows/

XML output extension to the C++ front-end of GCC

Check out the latest develop version:

cvs -d:pserver:anoncvs@www.gccxml.org:/cvsroot/GCC_XML login

(just press enter when prompted for a password)

Follow this command by checking out the source code:

cvs -d:pserver:anoncvs@www.gccxml.org:/cvsroot/GCC_XML co gccxml

vtk 5.8.0 source

you can download it from: http://www.vtk.org/VTK/resources/software.html#previous

mummy

Needed to wrap unmanaged c++ dlls with managed dlls.

Use git to retrieve mummy source code:

git clone git://public.kitware.com/mummy.git

ActiViz.NET source

Use git to retrieve ActiViz.NET source code:

git clone git://public.kitware.com/activizdotnet.git

Visual Studio 2005 or 2008 (gccxml does not yet work with Visual Studio 2010)

A signing key to produce "strong name signed" .NET Framework binaries.

If you don't have your own strong name signing key, you can disable strong name validation on the machine that you want to build and test it on. However, to install your unsigned build on another machine, they will also have to disable strong name validation. It's a good idea to sign your .NET binaries if you're going to be re-distributing them.

Documentation tools

Doxygen

you can download it from: http://www.stack.nl/~dimitri/doxygen/

GraphViz

you can download it from: http://www.graphviz.org/

Directory structure

This directory structure is only intended as a suggestion:

VTK CSharp ActiViz Build FolderStructure.png

Configure and build vtk

Define where to search for the source code of vtk and where to build the binaries for vtk.

VTK CSharp ActiViz Build Cmake01.png

Click Configure. In the following dialog choose the compiler. Select for instance Visual Studio 9 2008. Note: If you want to build ActiViz with Visual Studio choose either Visual Studio 8 2005 or Visual Studio 9 2008. ActiViz cannot be build with Visual Studio 10 since gccxml.exe does not yet work with Visual Studio 2010.

VTK CSharp ActiViz Build Cmake02.png

Click Finish.

Click Configure. CMake first check your compiler capabilities, then trying to find the required tools and gather other informations. This may take a while.

When finished you see a bunch of entries.

Verify and adjust following entries
CMAKE_INSTALL_PREFIX C:/VTK/VTK-5.8.0-install Where binaries are installed
CVSCOMMAND C:/Windows/cvs.exe Wherever you copied cvs.exe to (folder must be set in environment variable PATH)
GITCOMMAND C:/Program Files/Git/bin/git.exe
PYTHON_EXECTUABLE C:/Program Files/Python26/python.exe
SPC_COMMAND C:/Program Files/Git/bin/scp.exe
SVN_COMMAND C:/Program Files/TortoiseSVN/bin/svn.exe
VTK_DATA_ROOT C:/VTK/vtkdata Needed for final tests
VTK_LARGE_DATA_ROOT C:/VTK/vtkdata/VTKLargeData Not necessarily needed

Enable following entries
BUILD_SHARED_LIBS ON Necessary
VTK_USE_PARALLEL ON Not necessarily needed, but then you must change a line in cmakelist.txt when building ActiViz (see section 1.5 Configure and build ActiViz.NET)

Useful settings, but not necessarily needed
BUILD_DOCUMENTATION ON
BUILD_EXAMPLES ON
BUILD_TESTING ON
HDF5_BUILD_HL_LIB ON Not necessarily needed, but then you must change a line in cmakelist.txt when building ActiViz (see section 1.5 Configure and build ActiViz.NET)

Click Configure again.

Having VTK_USE_PARALLEL set to on only one line should be marked in red color after this Configure run:

VTK_USE_MPI

If MPI isn't installed on your machine or you just don't want to use it leave this entry unchecked, and click Configure again.

In case everything seems to be configured properly (nothing is marked in red) click Generate.

Now goto your build folder (in this example c:\vtk\vtk-5.8.0-build) and open VTK.sln with Visual Studio C++ 2008. Select Release as your solution configuration, in solution explorer right click on ALL_BUILD and choose Build. Relax and take a cup of tea or coffee. The build process may take a while.

When the build has been successful you should find the following dlls in your bin folder (for this example c:\vtk\vtk-5.8.0-build\bin\Release):

Cosmo.dll
MapReduceMPI.dll
mpistubs.dll
(VPIC.dll)  // only if VTK_USE_PARALLEL is set to on
vtkalglib.dll
vtkCharts.dll
vtkCommon.dll
vtkDICOMParser.dll
vtkexoIIc.dll
vtkexpat.dll
vtkFiltering.dll
vtkfreetype.dll
vtkftgl.dll
vtkGenericFiltering.dll
vtkGeovis.dll
vtkGraphics.dll
vtkhdf5.dll
(vtkhdf5_hl.dll)  // only if HDF5_BUILD_HL_LIB is set to on
vtkHybrid.dll
vtkImaging.dll
vtkInfovis.dll
vtkIO.dll
vtkjpeg.dll
vtklibxml2.dll
vtkmetaio.dll
vtkNetCDF.dll
vtkNetCDF_cxx.dll
vtkParallel.dll
vtkpng.dll
vtkproj4.dll
vtkRendering.dll
vtksys.dll
vtktiff.dll
vtkverdict.dll
vtkViews.dll
vtkVolumeRendering.dll
vtkWidgets.dll
vtkzlib.dll

Configure and build gccxml

gccxml source should be downloaded from the current CVS trunk (http://www.gccxml.org/HTML/Download.html)

cvs -d :pserver:anoncvs@www.gccxml.org:/cvsroot/GCC_XML login
cvs -d :pserver:anoncvs@www.gccxml.org:/cvsroot/GCC_XML co gccxml

Then run CMake and select your gccxml source path and define a path for the binaries. Click Configure. The only thing you may want to adjust is the path where gccxml is going to be installed:

Adjust following entries
CMAKE_INSTALL_PREFIX C:/Program Files/gccxml

Click Generate.

Goto to your Build folder and open gccxml.sln with Visual Studio C++ 2008. Select Release as your solution configuration, in solution explorer right click on ALL_BUILD and choose Build.

After the binaries have been build right click on INSTALL in solution explorer to install the binaries into the folder you've defined above.

As a final step you must configure your gccxml installation with gccxml_vcconfig.bat. This batch file is located in the bin folder of your installation folder (e.g. C:\Program Files\gccxml\bin). Open a cmd shell as an administrator in the bin folder and run gccxml_vcconfig.bat. Note that if you receive errors finding the "VC9\Include" directory, that indicates you have not run the cmd shell as administrator.


Configure and build Mummy

First of all you should create a signing key to produce "strong name signed" .NET Framework binaries. Assuming Windows SDK is installed, open a windows sdk prompt, and type

sn -k WhateverNameYouWant.snk

(for instance: jk.mummy.Runtime.snk).

Now that we have a signing key we must tell Cmake to use this key and where to find it. Insert the following statement into cmakelist.txt, located in the root of your mummy source folder (on my machine it's located at c:\VTK\ActiViz\mummy\cmakelist.txt):

GET_FILENAME_COMPONENT(Mummy_SNKEYFILE "${CMAKE_CURRENT_SOURCE_DIR}/Runtime/jk.mummy.Runtime.snk" ABSOLUTE)

Make sure the snk file can be found at this location.

During the configuration run you may want to verify the content of ${CMAKE_CURRENT_SOURCE_DIR} with the following line in cmakelist.txt:

Message(STATUS "current source dir : '${CMAKE_CURRENT_SOURCE_DIR}'...")

Also you may ask yourself where to enter these statements in cmakelist.txt. Somewhere between the definition of ${CMAKE_CURRENT_SOURCE_DIR} and first usage of ${Mummy_SNKEYFILE}.
I put it right before the line

# Echo selected CMake/configuration settings:

The line can be found near line # 140.

This configuration should be good enough to build Kitware.mummy.Runtime.dll and Kitware.mummy.Runtime.Unmanaged.dll successful, which in fact are the only two files we will need for ActiViz to work properly.

In case you want the mummy-examples to be build successful as well you must

1. add these lines mummy/CMakeLists.txt

SET(gccxml_compiler "${CMAKE_CXX_COMPILER}")
IF(MSVC80)
  SET(gccxml_compiler "msvc8")
ENDIF(MSVC80)
IF(MSVC90)
  SET(gccxml_compiler "msvc9")
ENDIF(MSVC90)
SET (GCCXML_EXTRA_D_ARGS "_HAS_TR1=0")

Note:

  • This must be at the top of the file or else the variable GCCXML_EXTRA_D_ARGS will not be set for CMakeLists.txt. Best to add after CMAKE_MINIMUM_REQUIRED line.
  • gccxml don't understand cl as the compiler name, but "cl" is the content of ${CMAKE_CXX_COMPILER}.
    If you ommit the first 7 lines you'get the following warning:
    Compiler "cl" specified, but more than one of MSVC 6, 7, 7.1, 8, 9, and 10 are installed.
    Please specify "msvc6", "msvc7", "msvc71", "msvc8", "msvc8ex", "msvc9", or "msvc10" for the GCCXML_COMPILER setting.
    Using MSVC 9 because it was used to build GCC-XML.
  • If you ommit the last line you'll get a bunch of following nice error messages:
    C:/Program Files/Microsoft Visual Studio 9.0/VC/include/xxresult:102: error: redefinition of 'struct std::tr1::_Result_of1<_Rx (_Arg0::*)(), _Farg0&>'
    C:/Program Files/Microsoft Visual Studio 9.0/VC/include/xxresult:94: error: previous definition of 'struct std::tr1::_Result_of1<_Rx (_Arg0::*)(), _Farg0&>'

2. edit CMakeLists.txt in mummy subfolder Examples\Vehicles\wrappers\csharpmummy:

Find the following paragraph (near line # 82):

ADD_CUSTOM_COMMAND(
      OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xml/${cxxclass}.xml
      COMMAND ${gccxml_EXECUTABLE}
      ARGS
        -fxml=${CMAKE_CURRENT_BINARY_DIR}/xml/${cxxclass}.xml
        -fxml-start=_cable_
        ${gccxml_include_args} -DCABLE_CONFIGURATION
        --gccxml-compiler ${CMAKE_CXX_COMPILER}
        ${CMAKE_CURRENT_BINARY_DIR}/xml/${cxxclass}_gccxml.cxx
      DEPENDS
        ${CMAKE_CURRENT_BINARY_DIR}/xml/${cxxclass}_gccxml.cxx
        ${header_fullpath}
        ${gccxml_EXECUTABLE}
      )

and replace it with:

   
ADD_CUSTOM_COMMAND(
      OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xml/${cxxclass}.xml
      COMMAND ${gccxml_EXECUTABLE}
      ARGS
        -fxml=${CMAKE_CURRENT_BINARY_DIR}/xml/${cxxclass}.xml
        -fxml-start=_cable_
        ${gccxml_include_args} -DCABLE_CONFIGURATION
        --gccxml-compiler ${gccxml_compiler}
        ${CMAKE_CURRENT_BINARY_DIR}/xml/${cxxclass}_gccxml.cxx
        -D${GCCXML_EXTRA_D_ARGS}
      DEPENDS
        ${CMAKE_CURRENT_BINARY_DIR}/xml/${cxxclass}_gccxml.cxx
        ${header_fullpath}
        ${gccxml_EXECUTABLE}
      )


Having the examples for mummy you can verify mummy has been properly build and installed and is working the way it should prior to the installation of ActiViz. Sounds like a good idea to me.

Note:

  • During the Cmake configuration run a CableSwig source tree is checked out. It should not be necessary to mention to be online. :D
  • If the parent directory is named exactly "ActiViz" then the external source trees are created as siblings of "ActiViz" - otherwise they are created as siblings of mummys source directory.

Configure and build ActiViz.NET

First of all you should create a signing key to produce "strong name signed" .NET Framework binaries. Assuming Windows SDK is installed, open a windows sdk prompt, and type

sn -k WhateverNameYouWant.snk

(for instance: jk.VTK.snk).

Caution: You cannot use the same signing key file used for mummy!

Now that we have a signing key we must tell CMake to use this key and where to find it. Find the following paragraph in cmakelist.txt (the one in the root folder of your activizdotnet sourcetree, for instance C:\VTK\ActiViz\activizdotnet\cmakelist.txt):

IF(NOT DEFINED AVDN_SNKEYFILE)
  GET_FILENAME_COMPONENT(AVDN_SNKEYFILE "${CMAKE_CURRENT_SOURCE_DIR}/Kitware.VTK.pub.snk" ABSOLUTE)
ENDIF(NOT DEFINED AVDN_SNKEYFILE)

and insert the following line above the found paragraph:

GET_FILENAME_COMPONENT(AVDN_SNKEYFILE "${CMAKE_CURRENT_SOURCE_DIR}/jk.VTK.snk" ABSOLUTE)

Don't forget to replace jk.VTK.snk with the name of your snk file and ensure your snk file can be found at this location.

Again we must make some adjustments to the gccxml command. Search the following paragraph:

SET(gccxml_compiler "${CMAKE_CXX_COMPILER}")
IF(MSVC80)
  SET(gccxml_compiler "msvc8")
ENDIF(MSVC80)
IF(MSVC90)
  SET(gccxml_compiler "msvc9")
ENDIF(MSVC90)
MESSAGE(STATUS "gccxml_compiler='${gccxml_compiler}'...")

Insert the following line right below the found paragraph:

SET (GCCXML_EXTRA_D_ARGS "_HAS_TR1=0")

Now find the following paragraph:

        ADD_CUSTOM_COMMAND(
          OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xml/${cxxclass}.xml
          COMMAND ${gccxml_EXECUTABLE}
          ARGS
            -fxml=${CMAKE_CURRENT_BINARY_DIR}/xml/${cxxclass}.xml
            -fxml-start=_cable_
            ${gccxml_include_args} -DCABLE_CONFIGURATION
            --gccxml-compiler ${gccxml_compiler}
            ${CMAKE_CURRENT_BINARY_DIR}/xml/${cxxclass}_gccxml.cxx
          DEPENDS
            ${CMAKE_CURRENT_BINARY_DIR}/xml/${cxxclass}_gccxml.cxx
            ${header}
            ${gccxml_EXECUTABLE}
        )

and replace it with

        ADD_CUSTOM_COMMAND(
          OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xml/${cxxclass}.xml
          COMMAND ${gccxml_EXECUTABLE}
          ARGS
            -fxml=${CMAKE_CURRENT_BINARY_DIR}/xml/${cxxclass}.xml
            -fxml-start=_cable_
            ${gccxml_include_args} -DCABLE_CONFIGURATION
            --gccxml-compiler ${gccxml_compiler}
            ${CMAKE_CURRENT_BINARY_DIR}/xml/${cxxclass}_gccxml.cxx
            -D${GCCXML_EXTRA_D_ARGS}
          DEPENDS
            ${CMAKE_CURRENT_BINARY_DIR}/xml/${cxxclass}_gccxml.cxx
            ${header}
            ${gccxml_EXECUTABLE}
        )

As a last adjustment we have to remove a reference to LsDyna.dll. Find the line

      # Add extra utility DLLs the kit DLLs depend on:

Then remove LsDyna from the following statement (comes right after the found line)

      SET(vtkListOfDLLs ${vtkListOfDLLs}
        LSDyna
        Cosmo
        VPIC
        vtkhdf5_hl
        vtkalglib
        vtkDICOMParser
        vtkexoIIc
        vtkftgl
        vtkhdf5
        vtkmetaio
        vtkNetCDF
        vtkNetCDF_cxx
        vtksys
        vtkverdict
      )

Note:

  • In case you compiled vtk while setting VTK_USE_PARALLEL to OFF remove VPIC too.
  • In case you compiled vtk while setting HDF5_BUILD_HL_LIB to OFF remove vtkhdf5_hl and vtkhdf5 too.
  • Cosmo can be removed as well.
  • I'm pretty quite sure that other libs can be removed as well, depending on particular vtk cmake settings. You may have to experiment with it.


Okay, now we are ready to perform our first CMake configuration run. When finished you see a bunch of entries.

Verify and adjust following entries
AVDN_INSTALL_PREFIX c:/VTK/ActiViz/activiz-install where binaries are installed during the INSTALL build
GITCOMMAND C:/Program Files/Git/bin/git.exe
PYTHON_EXECUTABLE C:/Program Files/Python26/python.exe
SPC_COMMAND C:/Program Files/Git/bin/scp.exe
SVN_COMMAND C:/Program Files/TortoiseSVN/bin/svn.exe
CVSCOMMAND C:/Windows/cvs.exe wherever you copied cvs.exe to (folder must be set in environment variable PATH)
gccxml_EXECUTABLE C:/Program Files/gccxml/bin/gccxml.exe
mummy_DIR C:/VTK/ActiViz/mummy-build/share/mummy-1.0.2
mummy_EXECUTABLE C:/VTK/ActiViz/mummy-build/bin/Release/mummy.exe
VTK_DIR C:/VTK/vtk-5.8.0-build

Enable/Disable following entries
AVDN_BUILD_CSHARP_DEBUG OFF switch it to on in case you want to debug ActiViz

useful settings, but not necessarely needed
GENERATE_DOXYGEN ON create doxygen documentation
BUILD_TESTING ON create test applications

Configure and generate.

Goto to your Build folder and open ActiVizDotNet.sln with Visual Studio C++ 2008. Select Release as your solution configuration, in solution explorer right click on ALL_BUILD and choose Build. After the binaries have been build right click on INSTALL in solution explorer to install the binaries into the folder you've defined above.

That's all folks.