Difference between revisions of "VTK/GitMSBuild"

From KitwarePublic
< VTK
Jump to navigationJump to search
(Created page with "== 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 f...")
 
Line 97: Line 97:
 
|}
 
|}
 
Now create some scripts to facilitate pulling data from the git repositories and building using MSBuild.
 
Now create some scripts to facilitate pulling data from the git repositories and building using MSBuild.
 +
 +
=== Scripts and Batch files ===
 +
Create the following script, calling it pull.sh and putting it in %KITWARE_PATH%\src:
 +
<pre>
 +
#!/bin/bash
 +
# Pull all git repositories in the directory this is running in and
 +
# any specified repositories in subdirectories.
 +
 +
# Author: Andrew Maclean
 +
# Date: 2010-04-30
 +
# Last Modified: 2010-12-17
 +
# Reason: Handles System V version of ls which generates 9 fields
 +
#        and the Berkley version of ls which generates 8 fields.
 +
# Last Modified: 2011-03-18
 +
# Reason: Made pulling a function so that subdirectories can be accessed.
 +
#        A log directory will be created in each directory.
 +
 +
pull()
 +
{
 +
# Runs a git checkout into each of the subdirectories.
 +
# We are assuming that each of the subdirectories is
 +
# legitimate and that git has been set up for each directory.
 +
outDir="$PWD/log"
 +
[ -d "$outDir" ] || mkdir $outDir
 +
 +
for fn in $dirs
 +
do
 +
(
 +
    output="$outDir/${fn}.log"
 +
    # remove old log files
 +
    rm -f $output 2>/dev/null
 +
 +
    cd $fn || exit 1
 +
    [ -d .git ] || {
 +
        echo "Error: no .git directory for $fn"
 +
        exit 1
 +
    }
 +
 +
    echo "Pulling  $fn"
 +
    echo "Started:  `date`" >> $output
 +
    git pull --rebase 2>&1  >> $output
 +
    # update submodules (if they exist)
 +
    mods=$(git submodule | wc -l)
 +
    [ "$mods" != 0 ] && git submodule update 2>&1 >> $output
 +
 +
    # update hooks (if they exist)
 +
    hooks=$(git branch -a -l | grep hooks | wc -l)
 +
    if [ "$hooks" != 0 ]
 +
    then
 +
        ( cd .git/hooks && git pull .. remotes/origin/hooks 2>&1 >> $output )
 +
    fi
 +
 +
    echo "Finished: `date`" >> $output
 +
)
 +
done
 +
}
 +
 +
pull_data()
 +
{
 +
# Runs a git checkout into each of the subdirectories.
 +
# We are assuming that each of the subdirectories is
 +
# legitimate and that git has been set up for each directory.
 +
outDir="$PWD/log"
 +
[ -d "$outDir" ] || mkdir $outDir
 +
 +
for fn in $dirs
 +
do
 +
(
 +
    output="$outDir/${fn}.log"
 +
    # remove old log files
 +
    rm -f $output 2>/dev/null
 +
 +
    cd $fn || exit 1
 +
    [ -d .git ] || {
 +
        echo "Error: no .git directory for $fn"
 +
        exit 1
 +
    }
 +
 +
    echo "Pulling  $fn"
 +
    echo "Started:  `date`" >> $output
 +
    git pull --rebase 2>&1  >> $output
 +
 +
    echo "Finished: `date`" >> $output
 +
)
 +
done
 +
}
 +
 +
 +
#---------------- main -------------------
 +
main()
 +
{
 +
# We need CMake VTK ParaView ITK
 +
# dirs=$(ls -l |awk '/^d/ {print $NF}' | awk '$0 ~ /(^CMake$|^VTK$|^ParaView$|^ITK$)/ {print $0}')
 +
dirs=$(ls -l |awk '/^d/ {print $NF}' | awk '$0 ~ /(^VTK$)/ {print $0}')
 +
pull $dirs
 +
# We need VTKData ParaViewData wikiexamples ITKApps
 +
# dirs=$(ls -l |awk '/^d/ {print $NF}' | awk '$0 ~ /(^VTKData$|^VTKLargeData$|^ParaViewData$|^wikiexamples$|^ITKApps$)/ {print $0}')
 +
dirs=$(ls -l |awk '/^d/ {print $NF}' | awk '$0 ~ /(^VTKData$|^VTKLargeData$|^WikiExamples$)/ {print $0}')
 +
pull_data $dirs
 +
}
 +
 +
main
 +
echo "Finished pulling."
 +
</pre>
 +
This script will pull VTK etc. into the directories of the same name. Thus automatically updating any changed files.
 +
 +
To use it go to %KITWARE_PATH% in explorer and right-click on src selecting Git Bash Here, when the window opens, type:
 +
<pre>
 +
./pull.sh
 +
</pre>
 +
This script is valid for any linux system and also for Mac OS.

Revision as of 22:12, 21 March 2012

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.

Scripts and Batch files

Create the following script, calling it pull.sh and putting it in %KITWARE_PATH%\src:

#!/bin/bash
# Pull all git repositories in the directory this is running in and 
# any specified repositories in subdirectories.

# Author: Andrew Maclean
# Date: 2010-04-30
# Last Modified: 2010-12-17
# Reason: Handles System V version of ls which generates 9 fields
#         and the Berkley version of ls which generates 8 fields. 
# Last Modified: 2011-03-18
# Reason: Made pulling a function so that subdirectories can be accessed.
#         A log directory will be created in each directory. 

pull()
{
	# Runs a git checkout into each of the subdirectories.
	# We are assuming that each of the subdirectories is
	# legitimate and that git has been set up for each directory.
	outDir="$PWD/log"
	[ -d "$outDir" ] || mkdir $outDir

	for fn in $dirs
	do
	(
	    output="$outDir/${fn}.log"
	    # remove old log files
	    rm -f $output 2>/dev/null

	    cd $fn || exit 1
	    [ -d .git ] || {
        	echo "Error: no .git directory for $fn"
	        exit 1
	    }

	    echo "Pulling  $fn"
	    echo "Started:  `date`" >> $output
	    git pull --rebase 2>&1  >> $output
 	    # update submodules (if they exist)
	    mods=$(git submodule | wc -l)
	    [ "$mods" != 0 ] && git submodule update 2>&1 >> $output

	    # update hooks (if they exist)
	    hooks=$(git branch -a -l | grep hooks | wc -l)
	    if [ "$hooks" != 0 ]
	    then
        	( cd .git/hooks && git pull .. remotes/origin/hooks 2>&1 >> $output )
	    fi

	    echo "Finished: `date`" >> $output
	)
	done
}

pull_data()
{
	# Runs a git checkout into each of the subdirectories.
	# We are assuming that each of the subdirectories is
	# legitimate and that git has been set up for each directory.
	outDir="$PWD/log"
	[ -d "$outDir" ] || mkdir $outDir

	for fn in $dirs
	do
	(
	    output="$outDir/${fn}.log"
	    # remove old log files
	    rm -f $output 2>/dev/null

	    cd $fn || exit 1
	    [ -d .git ] || {
        	echo "Error: no .git directory for $fn"
	        exit 1
	    }

	    echo "Pulling  $fn"
	    echo "Started:  `date`" >> $output
	    git pull --rebase 2>&1  >> $output

	    echo "Finished: `date`" >> $output
	)
	done
}


#---------------- main -------------------
main()
{
	# We need CMake VTK ParaView ITK
	# dirs=$(ls -l |awk '/^d/ {print $NF}' | awk '$0 ~ /(^CMake$|^VTK$|^ParaView$|^ITK$)/ {print $0}')
	dirs=$(ls -l |awk '/^d/ {print $NF}' | awk '$0 ~ /(^VTK$)/ {print $0}')
	pull $dirs
	# We need VTKData ParaViewData wikiexamples ITKApps
	# dirs=$(ls -l |awk '/^d/ {print $NF}' | awk '$0 ~ /(^VTKData$|^VTKLargeData$|^ParaViewData$|^wikiexamples$|^ITKApps$)/ {print $0}')
	dirs=$(ls -l |awk '/^d/ {print $NF}' | awk '$0 ~ /(^VTKData$|^VTKLargeData$|^WikiExamples$)/ {print $0}')
	pull_data $dirs
}

main
echo "Finished pulling."

This script will pull VTK etc. into the directories of the same name. Thus automatically updating any changed files.

To use it go to %KITWARE_PATH% in explorer and right-click on src selecting Git Bash Here, when the window opens, type:

./pull.sh

This script is valid for any linux system and also for Mac OS.