VTK/GitMSBuild
Building VTK using Git and MSBuild
Preliminary steps
We are going to create a script called pull.sh that will automatically pull down onto your computer the files from the VTK and WikiExamples git repositories. THis assumes that you have Git installed on your system.
Then we will create file called build.cmd that will build debug and release versions of VTK and WikiExamples. It will use MSBuild to build the software and set the number of CPU's to use to the maximum on your system. This file has the ability to perform separate configurations such as 32-bit or 64-bit. To do this we will create a link to this file called build-x64 that passes a parameter to build.cmd specifying a 64-bit build. Of course you can edit this is as you want, for example, setting a 32-bit build instead.
The key advantage of this process is that the pulling and building process is then largely automated.
By using scripting in this manner we can easily change or add more builds and change build types. In the following discussion we will be doing a 64-bit build. However as mentioned above the scripts have been written so that a 32-bit build can be done by changing just one link.
VTK and the WikiExamples will be built for both release and debug with the release and debug versions being in separate trees. Thus there will be a different build directory for each build configuration. The advantage of this is that there is one tree for each build and we have a clean separation of the build types. You can also extend the scripting to deal with both 32-bit ad 64-bit builds on the same machine. This means that when you are building your own code, using these libraries, you can easily have a debug version and a release version. This will be demonstrated in the WikiExamples build.
If you have express versions of the compiler and want to use the 64-bit version make sure you have the correct Windows SDK installed. This link may provide useful information for VS2008: [1]
Keeping in mind that we are keeping separate source and build/release trees the following directory structure will be used:
%KITWARE_PATH%\build\VTK\Release |
%KITWARE_PATH%\build\VTK\Debug |
%KITWARE_PATH%\build\WikiExamples\Release |
%KITWARE_PATH%\build\WikiExamples\Debug |
%KITWARE_PATH%\src\VTK |
%KITWARE_PATH%\src\WikiExamples |
%KITWARE_PATH%\src\VTKData |
%KITWARE_PATH%\src\VTKLargeData |
Where %KITWARE_PATH% will be the root path e.g C:\Kitware or C:\Users\<your username>\Code\Kitware, you can choose whatever you prefer here.
Before proceeding you will need to set some environment variables.
Environment variables
Set the following environment variables:
KITWARE_PATH | This will be the root path e.g C:\Kitware or C:\Users\<your username>\Code\Kitware you can choose whatever you prefer here |
VTK_BIN | %KITWARE_PATH%\build\VTK\Release\bin |
VTK_DATA_ROOT | %KITWARE_PATH%\src\VTKData |
VTK_ROOT | %KITWARE_PATH%\src\VTK |
The VTK_BIN environment variable will be the default one for all your builds. If you want a debug build then you will change it as outlined below.
You normally want the release variables to be available to the system, so add the following path to the PATH environment variable:
%KITWARE_PATH%\build\VTK\Release\bin\Release
However if you are interested in having debug variables available to the system then you must add the following path to the PATH environment variable:
%KITWARE_PATH%\build\VTK\Release\bin\Debug
You cannot have both paths in the PATH environment variable. Use either one or the other.
Now create the following directories:
%KITWARE_PATH%\src |
%KITWARE_PATH%\build\VTK\Debug |
%KITWARE_PATH%\build\VTK\Release |
%KITWARE_PATH%\build\WikiExamples\Debug |
%KITWARE_PATH%\build\WikiExamples\Release |
Download VTKsource and VTKData (optionally VTKLargeData) via Git access into %KITWARE_PATH%\src see:
http://www.vtk.org/Wiki/VTK/Git
Download WikiExamples via Git access into %KITWARE_PATH%\src see:
http://www.vtk.org/Wiki/VTK/Examples
Then in the source directory you should have the following folders:
%KITWARE_PATH%\src\VTK |
%KITWARE_PATH%\src\VTKData |
%KITWARE_PATH%\src\VTKLargeData |
%KITWARE_PATH%\src\WikiExamples |
Now create some scripts to facilitate pulling data from the git repositories and building using MSBuild.