Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]


Build-time variants

It is a common requirement to be able to build more than one variant of a program from a single set of source code. For example, you might have evaluation and full variants of a program that are identical in most respects, but which differ in a few features; or might want to build a program for more than one platform, with some features being present on platform but not on the other.

A traditional way to handle this requirement is to use the pre-preprocessor to conditionally include sections of code depending on whether a macro is set or not. For example:

#ifdef MY_FLAG
    // code that is compiled if MY_FLAG exists
#else
 // code that is compiled if MY_FLAG doesn't exists
#endif

Note that this is not always the best approach, as it can make code difficult to read and maintain. Alternative approaches to consider can include:

However, if conditional compilation is needed, you can configure the build tools to read a file that defines the macros to use. To do this:

When you use bldmake or abld on the command line, the build tools look for the variant.cfg file, and set any macros defined in the specified file. By adding/removing/changing the variant.cfg file in your build environment, you can alter which macros are set, and so how your project is built.

For IDE builds, the macros are set when the IDE project file is created, and not changed unless you recreate the IDE project file.

Note that you can use the macros in bld.inf and .mmp files as well as in C++ files: this allows you to conditionally specify projects, source files, etc.