## Compiling WinMerge

Compiling sources is usually the first thing you want to do. Source packages for different versions are available from SourceForge.net downloads or from Subversion repository. See readme-Subversion.html for more information about Subversion repository and using it.

### Table of Contents

1. Environment
2. Project Files
3. Compiling expat
4. Compiling SCEW
5. Compiling PCRE
6. Compiling WinMerge executables
7. Shell Extension (64-bit)
8. Visual Studio 2005 & 2008 Manifest File
9. Building 64-bit version

### Environment

#### Supported Compilers

Compiling WinMerge requires commercial edition of the Visual Studio. Free Express Editions cannot be used since they don't include MFC. WinMerge uses MFC for the GUI.

- Visual Studio 2003.Net + Service Pack 1
- Visual Studio 2005 (occasional checks for compiling) (Service Pack 1 recommended)
- Visual Studio 2008 (Service Pack 1 recommended) [used for releases]
- Visual Studio 2010

#### Libraries

WinMerge executable depends on Expat XML parser, SCEW and PCRE libraries. All are in the source tree (in `/Externals` -folder), and need to be compiled before compiling WinMerge executable.

Visual Studio 2008 and later: You'll need to convert library workspace and project files to new format before compiling.

To convert workspace/project files, just open them into Visual Studio and let the Visual Studio to convert. Files are:

- `WinMerge.sln`
- `Externals\expat\expat.sln`
- `Externals\scew\win32\scew.vcproj`
- `Externals\pcre\pcre.sln`

There is a Python script `/Tools/Scripts/UpgradeProjects.py` which updates most solution/project files.

#### Additional requirements (out of source tree)

- HTML Help Workshop (either stand-alone or from Platform SDK)
  Download it from : HTMLHelp download.
- Platform SDK or Windows SDK:
  - Platform SDK Windows 2003 SP1 - Download and install
  - Windows SDK - Download and install
  Visual Studio 2003.Net and later come with Platform SDK but you may still want more recent version...
- Installer needs own tools, documented in readme-InnoSetup.html
- Manual needs Docbook tools, documented in readme-manual.html

##### Platform SDK components

Needed Platform SDK components:

- Microsoft Windows Core SDK - obviously..
- Microsoft Data Access Services (MDAC) SDK - for some ODBC etc headers needed by other PSDK headers..
- Microsoft Web Workshop (IE) SDK - for IE/Shell headers

If you installed PSDK separately, don't forget to add the PSDK paths to Visual Studio's Include and Library directories. The easiest way is to use the "Visual Studio Registration\Register PSDK directories with Visual Studio" item from the "Platform SDK" start menu folder.

### Project files

Project file for WinMerge executable (in `/Src`) and other projects like ShellExtension (in `/ShellExtension`) have their own project files. There is no one single project/workspace file to compile all projects.

The Visual Studio project and solution files for VS2005 come with the WinMerge sources. Newer versions of Visual Studio can open that file too, they just ask if one wants to convert to the new version. The reason we don't ship project files for all Visual Studio versions is we have no resources to keep all versions up to date. People can't test all versions themselves, and easily forget to update at least one file. So we easily end up in a situation where there is no properly working project file at all...

After opening the project file you need to add the HTML Help Workshop path as additional include- and library-path.

NOTE: There might be problems compiling/debugging with Visual Studio 2003 when using HTML Help WorkShop from the Platform SDK in Visual Studio directory. Download and install HTML Workshop as stand-alone and include headers and libraries from standalone directory. The probable cause is that including files from Platform SDK directories breaks things.

### Compiling expat

expat is in `/Externals/expat` folder in source tree. To compile expat:

- Open Visual Studio solution `/Externals/expat/expat.sln`. If you are using Visual Studio 2008 or later you need to convert the file to the new format when Visual Studio opens the file.
- Select from Visual Studio menu Build / Batch Build
- Select either debug or release targets.
- Select Rebuild All

After build finishes, selected (debug or release) lib and dll files are in `/Build/expat`. WinMerge executable's project file picks them from there.

### Compiling scew

scew is in `/Externals/scew` folder in source tree. To compile scew:

- Open Visual Studio project file `/Externals/scew/win32/scew.vcproj` If you are using Visual Studio 2008 or later you need to convert the file to the new format when Visual Studio opens the file.
- Select from Visual Studio menu Build / Batch Build
- Make sure all targets are selected
- Select Rebuild All

### Compiling PCRE

PCRE is in `/Externals/pcre` folder in source tree. PCRE uses CMake (http://www.cmake.org/) to create project- and solution-files. There are ready-made files in our source tree.

To compile PCRE:

- Open Visual Studio solution file `/Externals/pcre/Win32/pcre.sln` If you are using Visual Studio 2008 or later you need to convert the file to the new format when Visual Studio opens the file.
- Select the `MinSizeRel`-target.
- Build the `pcre`-project

After build finishes, lib and dll files are in `/Build/pcre`. WinMerge executable's project file picks them from there.

If you want to re-build PCRE from the scratch, including project files, see file `Externals/pcre/NON-UNIX-USE`. There are instructions for running CMake and using it to configure PCRE.

When configuring PCRE, remember to set these two options:

- Build shared libraries (to create DLL files, not static libraries)
- Enable using `ANYCRLF` or `ANY` as linefeed style. Current build uses `ANY`.
- Enable using UTF-8

After CMake finishes, there are project files in the folder you selected as a build folder. However all paths in the files are absolute, not relative. If you want to make these files useful for other users you'll need to convert all paths to relative paths. In addition you need to remove custom build rules for building `CMakeLists.txt`. That rule tries to run CMake to re-generate some files.

### Compiling WinMerge executable targets

There are several targets available for compiling different projects. Targets used for compiling releases are:

- `WinMergeU.exe` : UnicodeRelease
- `ShellExtensionU.dll` : Unicode Release MinDependency
- Plugin dlls : Unicode Release MinDependency

### Shell Extension (64-bit)

Visual Studio 2005 and later come with 64-bit compiler. To compile 64-bit ShellExtension, open the `ShellExtension.vcproj` -project file and select X64 Debug or X64 Release -target. Then compile as usual.

If you are compiling in 32-bit Windows you get error about registering but that is expected to happen.

64-bit ShellExtension is registered to 64-bit Windows just like counterparts in 32-bit world:
`regsvr ShellExtensionX64.dll`

### Visual Studio 2005 & 2008 Manifest File

When the VC6 project file (.dsp) is converted to a Visual Studio 2005 or 2008 project, the visual styles do not get enabled. The problem is Visual Studio 2005 and 2008 automatically generates and embeds a manifest file for the executable, but that generated manifest does not include all needed properties to enable visual styles. The solution is to add WinMerge's manifest file as additional manifest.

From project properties, set
`Manifest Tool / Input and Output / Additional Manifest Files` -property value to:
`$(InputDir)\res\$(TargetFileName).manifest`

There is a Python script `Tools/Scripts/fix_manifest.py` which does the conversion. Note that the script re-formats the project file XML structure when saving so do not generate patches without first opening and saving the project file with Visual Studio.

See also Manifests in VS2005-- What are they? -thread in Microsoft forum.

### Building 64-bit version

64-bit versions are not supported. We provide project files for building 64-bit version of WinMerge so people can start testing and experimenting it. But it is still a long way to make actual releases of 64-bit versions.

Project files for 64-bit versions (at the moment) work only with VS2008. There might be later project files compatible with VS2005, but don't count on it. The project files are named as `[projectname]X64.vcproj`.

#### Bugs and patches

Submit bugs about 64-bit builds to our bug tracker as usual. But also expect they are given low priority. Likewise patches can be submitted to our patch tracker.