Programming Reference:Project Settings

From BCI2000 Wiki
Jump to: navigation, search

This page applies when you use the Borland compiler to build BCI2000. It deals with project settings, i.e. compiler/linker switches which are typically stored in IDE project files.

Generally, BCI2000 code tries to be portable, i.e. independent of machine type (little/big endian, byte lengths); where this is not feasible, it tests for necessary conditions at compile time. However, some aspects of compiler configuration need to be taken care of manually, and kept consistent across a number of project files.

Pre-Compiled Headers

Most modern compilers offer a feature to store so-called "Pre-Compiled Headers (PCHs)". During the compilation process, parsing header files is responsible for a large amount of compiling time; at the same time, most source files include rather similar sets of header files. Thus, caching parsed headers offers a way to significantly speed up compiles and builds.

Unfortunately, PCHs may become invalid when compiler settings change, leading to the following situations when the same PCH cache is used by multiple project with differing header sets, or compiler settings:

  1. Obsolete PCHs are detected correctly; as a consequence, PCHs are frequently recreated, resulting in slow builds.
  2. Obsolete PCHs are not detected; as a consequence, linking or runtime errors may occur. Obviously, this is the worse situation, because the reason for the errors is quite difficult to understand.

PCH Policy in BCI2000

The general BCI2000 policy regarding PCHs consists of three elements:

  • There is a specialized set of headers to include into PCHs, located at
    BCI2000/shared/config/PCHIncludes, which contains a list of #includes.
  • In each BCI2000 cpp file, the first lines of code are
#include "PCHIncludes.h"
#pragma hdrstop
The first line includes the set of header files, and the #pragma tells the Borland compiler _not_ to add any further #includes to the set of PCHs.
  • For BCI2000, the PCH cache itself is located at BCI2000/shared/obj/bci2000.csm.
    • For online components, the PCH project setting is to use PCHs, with the cache file named above.
    • For tools, PCH configuration should be set to "none".
The rationale for this is that experimenting with compiler settings makes less sense for online components than it does for tools, and online components make up most of the BCI2000 code. So the ratio of speedup to inconsistency trouble would be minimized that way.

See also

Programming Reference:Cpp Coding Style