Compiling - Windows

The officially supported Windows build platform for OpenCPN 2.6 beta and later is Microsoft Visual C++ 2010 Express. It is still possible to perform the build with Visual Studio 2008, but if you want to create installation packages, expect versioning problems.
Before you begin, update your Windows. If still using XP, Service Pack 3 is needed.


Preparing the toolchain


 

VC++ 2010 Express

Get it http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visua...
Run the setup and click through the installation wizard, Silverlight and SQL Server are not needed for OpenCPN, so you can save some time and space by not installing them.
After installation, register it (Help->Register Product), otherwise you will have just 30 days to use it.
If you are on XP or Vista, you can supposedly make VS 2010 run faster: http://news.softpedia.com/news/Speed-Up-Visual-Studio-2010-on-XP-SP3-and-Vista-SP2-152520.shtml

Service Pack 1

It is essential to perform ALL the updates you can, as if you don't install the Visual Studio 2010 Service Pack 1, you will not be able to convert the WX projects to VS 2010 format. Go to Help menu and select Check for Updates. It may be necessary to repeat this step.


VC++ 2008 Express Edition

You can skip this step now and get back to it later in case you experience problems converting the WX projects.
Get it from http://www.microsoft.com/visualstudio/en-us/products/2008-editions/express
Run the setup and click through the installation wizard, Silverlight and SQL Server are not needed for OpenCPN, so you can save some time and space by not installing them

Git (MSysGit)

Get it from http://code.google.com/p/msysgit/
The defaults for all the installation settings are fine except the following:
    * On the „Adjusting your PATH environment“, select „Run Git from the Windows Command Prompt“
    * On the „Choosing CR/LF behavior“ select „Commit line endings as they are“

If you want a tutorial, have a look at the series of articles starting at http://www.lostechies.com/blogs/jason_meridth/archive/2009/06/01/git-for...

Cmake

Get it from http://cmake.org/cmake/resources/software.html
While installing it's advisable to let the setup program add cmake to the system PATH variable


Gettext

Install Poedit from http://www.poedit.net/ - it's version of gettext is the best available out there.
Add gettext to your PATH - if you installed Poedit, right-click My Computer, select Properties... and on the Advanced tab click on Environment Variables button and add C:\Program Files\Poedit\bin to the PATH system variable

NSIS (Unicode)

Needed just in case you intend to build the installation package for OpenCPN.
Get it from http://code.google.com/p/unsis/downloads/list
The NSIS Unicode 2.46 setup file is also included in the GIT repository -> ..\buildwin\NSIS_Unicode\nsis-2.46-Unicode-setup.exe
Direct download link: http://code.google.com/p/unsis/downloads/detail?name=nsis-2.46.3-Unicode...

Download and install it. Due to a "bug" in CMake, which only looks at "HKEY_LOCAL_MACHINE\SOFTWARE\NSIS" for the installation location of NSIS and the Unicode version adds its registry key in "HKEY_LOCAL_MACHINE\SOFTWARE\NSIS\Unicode", there is some registry tweaking needed.

Just copy the value (it's the installation path) of the "HKEY_LOCAL_MACHINE\SOFTWARE\NSIS\Unicode" key to "HKEY_LOCAL_MACHINE\SOFTWARE\NSIS".
Alternatively you can just run the batch file 'CopyNSISUnicodeRegKey.bat' which is also included in the GIT repository -> ..\buildwin\NSIS_Unicode\CopyNSISUnicodeRegKey.bat

This means if you also want to use the ANSI NSIS version you first have to change the value of "HKEY_LOCAL_MACHINE\SOFTWARE\NSIS" registry key according to the installation path of the respective version you want to use.

To make the installer package use proper language name transaltions, it's necessary to modify file X:\Program Files\NSIS\Unicode\Contrib\Language files\Norwegian.nsh and change the line
!insertmacro LANGFILE "Norwegian" "Norwegian"
to
!insertmacro LANGFILE "Norwegian" "Norsk"

Pre-requisities


WxWidgets

Download from wxMSW-2.8.12-Setup.exe from http://www.wxwidgets.org/downloads/#latest_stable and install it
Open C:\${WXDIR}\build\msw\config.vc and change the line saying "UNICODE = 0" to UNICODE = 1

Convert the solution to VC++ 2010 format

Open C:\${WXDIR}\build\msw\wx_dll.dsw and answer Yes to all the project conversion questions.
Save the solution (Ctrl-S) You can ignore the warnings
If you keep getting the "Project files cannot be loaded. error is: X:\XXX\XXX\XXX.dsp: error: Project upgrade failed." errors, you have to take the intermediate step of converting the projects to VS2008 format - install VC++ 2008 as described earlier and

Convert the solution to VC++ 2008 format

Open C:\${WXDIR}\build\msw\wx_dll.dsw and answer Yes to all the project conversion questions.
Save the solution (Ctrl-S)
Close VC++ 2008
Run VC++ 2010
Open the solution (C:\${WXDIR}\build\msw\wx_dll.sln) and answer yes to all the questions of the conversion wizard
You can ignore the warnings
Save the solution

Necessary modifications

Go to the folder where you installed/unpacked wxWidgets and edit the file include\wx\msw\setup.h
Set:
     #define wxUSE_GRAPHICS_CONTEXT 1
     #define wxUSE_GLCANVAS       1 

In the properties of project core, add GDIPlus.lib into Configuration Properties -> Linker -> Input -> Additional Dependencies for both DLL Unicode Debug and DLL Unicode Release configurations
 


Compile Debug

Select DLL Unicode Debug from the configurations list and build the solution
odbc fails to compile – can be ignored as it's not used by OpenCPN

Compile Release

Select DLL Unicode Release from the configurations list and build the solution
odbc fails to compile – can be ignored as it's not used by OpenCPN

You should add C:\${WXDIR}\lib\vc_dll to your PATH environment variable. After doing it, you have to restart the running programs (cmd.exe, cmake-gui, VisualStudio etc.) to make sure they "see" the changed environment variables. If you are unsure, restart Windows and everything will be set. If you don't do it, you will have problems running your debug builds later.

If you have problems with cmake not finding your wxWidgets installation, try creating another environment variable called WXWIN with a value of C:\${WXDIR} (for example C:\wxWidgets-2.8.12) - it will help cmake find the libraries automatically. Again, don't forget to restart the running programs involved in the build.

Getting the OpenCPN source


Run cmd.exe or better, if you want to have the toolchain ready from the command line, „Visual Studio 2008 Command Prompt“ from Start menu → Programs → Microsoft Visual C++ 2008 Express Edition → Visual Studio Tools

To get the source for the first time, issue
git clone git://opencpn.git.sourceforge.net/gitroot/opencpn/opencpn

To update the code you cloned before, cd into the source directory and issue
git pull origin


Building the OpenCPN source


Create a directory named build under the topmost source directory

Configuring

From the command line:
cd into the build directory
issue
cmake -G „Visual Studio 10“ ..


Using Cmake-gui


Run „CMake (cmake-gui)“ from Start menu → Programs → Cmake 2.8

Fill in your source and build directories

Click on the Configure button

If you are asked to choose the generator, select „Visual Studio 9 2008“

The information which appeared is red and the Generate button stays disabled? Just hit Configure again...
Ignore GTK2_GTK_INCLUDE_DIR-NOTFOUND and wxwidgets_wxrc_EXECUTABLE_NOTFOUND

Click on the Generate button

Solution and project files should be created in your build directory

IMPORTANT suggestion:
Use CMAKE GUI tool to configure OpenCPN to verify that wxWidgets_LIB_DIR points to the {root}/lib/vc_dll directory. This check is necessary since the cmake FindWxWidgets module sometimes finds the wrong source and/or build config.

Compiling

From the command line:
Run „Visual Studio Command Prompt (2010)“ from Start menu → Programs → Microsoft Visual C++ 2008 Express Edition → Visual Studio Tools

cd into the build directory
issue
cmake -–build .

Wait for the build to complete.

You may get errors when building the plugins as they are built before opencpn (to be fixed in the configuration process). Simply running the build again fixes the problem.

From Visual Studio

Open the solution created by cmake (OpenCPN.sln)

Compile the whole solution or individual projects

You have to compile project opencpn before you can compile any plugins (to be fixed in the configuration process)

If you want to debug, don't forget to select opencpn as a start-up project and if you didn't add the WX DLL path to the PATH environment variable earlier, copy the needed WX DLLs to the build directory (Debug or Release, depending on which version you build). The DLLs can be found in C:\${WXDIR}\lib\vc_dll and you will need:

Debug: wxbase28ud_net_vc_custom.dll, wxbase28ud_vc_custom.dll, wxbase28ud_xml_vc_custom.dll, wxmsw28ud_adv_vc_custom.dll, wxmsw28ud_core_vc_custom.dll

Release: wxbase28u_net_vc_custom.dll, wxbase28u_vc_custom.dll, wxbase28u_xml_vc_custom.dll, wxmsw28u_adv_vc_custom.dll, wxmsw28u_core_vc_custom.dll
 

Creating the installer package


Build the PACKAGE project and opencpn_2.X.Y_setup.exe is created in your build directory (replace X with the release and Y with the build number)
Currently the installer packs the DLLs from the git repository into the package. You have to replace them with your custom built DLLs after the installation if you want to experiment with different versions and build settings of the wxWidgets libraries.