Conditional Compiler Options

This is an old revision of Conditional Compiler Options, edited by Mattias2 at . The current revision is 46177.

/* Proposal for adding new IDE macros */

This page collects ideas of how to implement conditional compiler options in lazarus.

First it should be collected the cases, where conditional compiler options are needed.

Case studies

Conditional Package Requirement: VirtualTreeView / multilog

Make it possible to define a package requirement as optional (Should be available both to package and program). Concrete situation: VirtualTreeView requires multilog package to help debug code. In a release it is not desired to have such dependency. Currently there are two possibilities:

An idea is to have groups of conditional requirements. Each group would have a define value associated to be used at compile time (e.g: 'DEBUG_CODE') and child packages. Each group would have an enabled flag. If group is enabled, the child packages are added as requirements and the define value passed with -d to the compiler.

Target specific units - Doable via FPC directives, no lazarus extras needed

Concrete situation: LCL extensions package has a unit (OleUtils) that implements TOLEStream. It only makes sense in Windows. Currently the unit is added in all widgetsets but all code is wrapped around a ifdef Windows define so is seen as a dummy unit in other widgetsets.

Notes:

Special build modes

Any application will desire different options for at least 2 possibilities:

So, any application should already come with those 2 options, and legacy applications could have them added automatically.

To have a trully flexible system any number of compilation modes should be supported (maybe >= 1 to have at least one). One idea to implement this system would be having any mode use all options set on the dialog, but also have a list of which options it will override to a custom value.

An extra idea is having the build options available on the Project -> Build menu

We could have: Project -> Build mode -> Debug; Release; Etc (submenu with all build modes), like Xcode has.

Arbitrary number of build modes - Virtual Magnifying Glass

One case where an arbitrary number of build modes would be excelent is the Virtual Magnifying Glass. Because Mac OS X requires special build options which can't be used on other operating systems, the magnifier could have the following options:

The Mac Qt4 options need to add "-framework Qt4Intf -lobjc" to the extra linker options and active the extra linker options.

The Mac Carbon options need to add "-framework carbon" to the extra linker options and active the extra linker options.

LCL Widgetsets

At the moment the LCLWidgetSet options is hardwired. It would be great if this could be done by the conditionals, because

For this is needed:

Proposal for adding new IDE macros

Proposal for conditional package requirements

Proposal for conditional linker, custom, search path options

Proposal for static compiler sets

Basically this proposal is just an improvement of the Save/Load compiler options.

What will not be implemented

Example: Use a package only under windows

A package/project should use a package only under windows (not wince).

When the above is implemented, it will work like this:

 $(TargetOS)='windows'

Example: Add framework linker option under Mac OS X

A package requires a special --framework option under Mac OS X. For example a package 'testpkg' should add the linker option --framework=opengl under OS X.

When the above is implemented, it will work like this:

 if $(TargetOS)='darwin'
   Result:=--framework=opengl
 $(TestPkgLinkerOption)

Example: Compile the project in Release/Debug mode

A project should have two different sets of compiler options for debugging and release.

When the above is implemented, it will work like this:

Example: Compile the project and all packages in Release mode

When the above is implemented, it will work like this: