Skip to content

[enGrid 1.3] Building on Windows with MSVC2008

wyldckat edited this page Sep 2, 2012 · 1 revision
Note: The acronym used in this project for Microsoft Visual Studio C++ 2008 is MSVC2008.

These instructions have only been tested with Microsoft Visual Studio C++ 2008 Express (the free as in beer version).

The MSVC2008 Express version can be retrieved from here: Visual Studio 2008 Express Editions

Instructions for making it also build for the x64 architecture: Configure Microsoft Visual Studio 2008 Express to also build for Windows x64


Table of Contents

Getting Started

Open the Solution file engrid\src\windows\VisualCppExpress2008\enGrid-VC2008.sln in MSVC2008. There you will find the following projects:

Figure 1: The Solution Explorer in MSVC2008 showing the projects available for the solution enGrid-VC2008.
enGrid-VC2008
This is the project for the main enGrid executable.
libengrid-VC2008
This is the project for the core library of enGrid.
nglib
This is the project that builds the library nglib on which enGrid it is dependent on from NETGEN.
enGrid-VC2008-static
This project is useful for debugging purposes. It provides a static build of enGrid, i.e. it does not depend on those three previous projects. This project is alone in enGrid 1.2.0.
enGrid Installer
This project acts partially as a front end for building the enGrid Installer. It only builds when you specifically tell it to build. For editing the files therein, it would be best to use one of the dedicated graphical user interfaces from here: Development environments for NSIS. Recommended: HM NIS Edit
Right-clicking on each project, then selecting Reload project or Unload project, according to the state of the project, you can deactivate some projects so you can focus on the others. This is the reason why the static version is disabled on the image to the right, since it takes as long as the dynamic version of enGrid to build.

When available, the dynamic version is the one to be released, which makes things easier for the user to create plug-ins for enGrid.

Note: Parallel compiling is defined as default on these projects, in order to take full advantage of the machine.


Building enGrid

Simply go to the top menu and pick:

Build » Build Solution

When you wish to only (re)build one of the projects (a must for the enGrid Installer project):

  1. Go to the Solution explorer;
  2. Right-click on the desired project;
  3. Select from the pop-up menu Project Only the type of action you wish to take.

Running and Debugging in MSVC2008

Setting up the debugging environment was not possible to be done directly on the source code of the project files, so you'll have to define the following settings manually:

Figure 2: The Properties for the project engrid-VC2008 in MSVC2008. On this picture is visible the Debugging branch on the left tree.
Figure 3: The contents of the Environment setting.
  1. In the Solution Explorer, right click on the enGrid-VC2008 (or enGrid-VC2008-static) project (not the solution) and select Properties.
  2. Then on the tree branch Configuration Properties -> Debugging, modify the entry Environment to suit your development environment. On the picture on the right you can see a snapshot as an example of this Properties window:
    1. The arrow is pointing to the button to be clicked for setting the Environment.
    2. The ellipse on the top left indicates where you can switch between Release and Debug modes or even to apply the settings to all configurations.
    3. To the right of that ellipse is where you can switch between architectures, namely between Win32 and x64 modes or even to apply the settings to all architectures.
  3. In the Environment window (second picture on the right), copy the following text into it:
    • For the Win32 architecture:
      QTDIR=$(SolutionDir)\..\..\third_party\Qt
      PATH=$(SolutionDir)\..\..\third_party\Qt\bin;$(SolutionDir)\..\..\third_party\Qt\lib;$(SolutionDir)\..\..\third_party\VTK\bin;%PATH%
      
    • For the x64 architecture:
      QTDIR=$(SolutionDir)\..\..\third_party64\Qt
      PATH=$(SolutionDir)\..\..\third_party64\Qt\bin;$(SolutionDir)\..\..\third_party64\Qt\lib;$(SolutionDir)\..\..\third_party64\VTK\bin;%PATH%
      
  4. To finalize the edition, click on the button OK on each window.

Once these preparations are complete, go to the menu entry Debug where you'll find two modes:

Start Debugging
to be used when the build mode is in Debug mode.
Start without Debugging
to be used when the build mode is in Release mode.

Creating the Installer

After the whole solution is built, the installer must be built independently, as explained in section Building enGrid. The resulting installer application will be placed at the folder engrid\src\windows. The naming structure is:

enGrid_<version>_setup_<build name>.exe
Where:
<version>
is the version name and/or number.
<build name>
is the name of the build type, which should indicate the targeted architecture and compiler used.

Updating project files

On this chapter it will be explained the various details that need to be attended to whenever new source files are added (or perhaps removed).


Changing the File Structure in the Solution

With MSVC2008 Express, there isn't an automated way to add/remove the files to be used by MSVC's compiler. Therefore these have to added manually, to reflect the structure define in each project's .pro file. Additionally, special Qt object files will need to be added and configured for the respective build areas, where special rules are applied.

The handling of these files will be explained on the following sections.

Adding a new file to the project

Take for example, adding the file engrid/src/libengrid/brlcadreader.cpp to the library libengrid:

  1. Open the tree branch libengrid-VC2008 in the Solution Explorer.
  2. Right click on the Source Files branch and select Add -> Existing Item.
  3. Search for the file (as given in the example above) and press the Add button.
  4. Do the same for the respective brlcadreader.h, but on the tree branch Header Files

Handling of special Qt files

Continuing with the previous example, if the file brlcadreader.h has one or more class definitions with the macro Q_OBJECT, then this means that this file needs additional handling. For example, this is a quote from the file engrid/src/libengrid/guitransform.h:

class GuiTransform : public DialogOperation<Ui::GuiTransform, Operation>
{
  
  Q_OBJECT;
  
private: // attributes

If the header has got Q_OBJECT

These files need additional processing by Qt's dedicated applications for generating wrappers for the signal-slot system. The header files are currently processed automatically by the implemented rule system that these project files for MSVC2008 already have. But after Qt's applications do their magic, they generate moc_*.cpp files that have the necessary wrappers that still need to be built and linked with. These files will be placed in the respective project build folder. For example, for the project libengrid-VC2008 and release configuration, the respective build folder is engrid/src/windows/VisualCppExpress2008/libengrid-VC2008/Release.

These automatically generated moc_*.cpp files will only reveal themselves after the first build, where the linker will complain about missing objects. The to add these files, one must follow this procedure:

  1. In each project, under the filter Source Files\MOC, there are two folders: Release and Debug. Depending on the current configuration, one must add the newly generated moc_*.cpp file to the currently active configuration:
    Figure 4: Indicated in red is the current configuration.
  2. Then right-click on the newly added moc_*.cpp file in the Solution Explorer and select Properties;
  3. On the top left is the Configuration drop down box, where you should pick the opposite option:
    • If the newly added file is for the Release configuration, then pick the Debug;
    • If the newly added file is for the Debug configuration, then pick the Release.
  4. Then on the right panel, the one with the list of properties, change the entry Excluded From Build from No to Yes.
  5. Press the Apply or OK button.

If the header does not have Q_OBJECT

If the new header file does not have the macro Q_OBJECT, then you should disable it from compiling. To do so:

  1. Right-click on the respective header file in the Solution Explorer and select Properties;
  2. On the top left is the Configuration drop down box, where you should pick the option All Configurations;
  3. Then on the right panel, the one with the list of properties, change the entry Excluded From Build from No to Yes.
  4. Press the Apply or OK button.
This way the file will not be processed by Qt's applications, but it will still be visible to the .cpp files.


Updating enGrid version information

There are two important files for indicating the version information:

  • engrid/src/libengrid/engrid_version.h - where core of the version information is kept.
  • engrid/src/libengrid/resources/libengrid.rc - where the definitions are made for being linked into the final binaries, so the information is displayed on the properties of the binary file in Windows Explorer.
For editing *.rc files, it's somewhat easy to edit the text itself, but one can use the open-source XN Resource Editor.


Updating Installer scripts

This is a common section to all Windows builds, so this section has it's own page: [enGrid 1.3] Building the final installer for Windows with NSIS



go back to [enGrid 1.3] Building on Windows
Clone this wiki locally