Difference between revisions of "Conditional Compiler Options"
(→Target specific units: refactored to show the discussion) |
|||
Line 26: | Line 26: | ||
==Target specific units== | ==Target specific units== | ||
− | Make units packages/projects optional according to | + | Make units packages/projects optional according to OS. |
Concrete situation: LCL extensions package has a unit (OleUtils) that | Concrete situation: LCL extensions package has a unit (OleUtils) that | ||
− | implements TOLEStream. It only makes sense in | + | implements TOLEStream. It only makes sense in Windows. Currently the unit |
is added in all widgetsets but all code is wrapped around a ifdef | 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. | Windows define so is seen as a dummy unit in other widgetsets. | ||
Line 34: | Line 34: | ||
Notes: | Notes: | ||
*All units should be added to the package, independent if they are used. If a unit should not always be compiled in (not added to the uses section of the package), just unset the 'uses unit' checkbox. | *All units should be added to the package, independent if they are used. If a unit should not always be compiled in (not added to the uses section of the package), just unset the 'uses unit' checkbox. | ||
− | *If the "uses unit" flag is not set, the unit will not be compiled. Nor in win32 (where is needed) neither in the other | + | ** If the "uses unit" flag is not set, the unit will not be compiled. Nor in win32 (where is needed) neither in the other OS-es. It will be compiled '''only''' if another unit in the package uses it. So you must add for example {$IFDEF win32}uses oleutils.pas{$ENDIF} somewhere to one of the package units. |
− | |||
*You can put units specific to targets into sub directories as demonstrated in the Lazarus and FPC sources (units/$(TargetOS)). | *You can put units specific to targets into sub directories as demonstrated in the Lazarus and FPC sources (units/$(TargetOS)). | ||
*Conclusion: There is no real need for conditional options for single units, as this is already possible. | *Conclusion: There is no real need for conditional options for single units, as this is already possible. |
Revision as of 21:10, 12 December 2007
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:
- in the release remove the dependency from the package, and then add again to reenable debugging.
- enclose the units of the package with {$IFNDEF MYRELEASE} and add -dMYRELEASE to the project and all package compiler options (or fpc.cfg).
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.
- Disadvantage: Other packages will use the same Debug/Release differences. In big projects normally only a small part should be set verbose (into debugging mode).
Target specific units
Make units packages/projects optional according to OS. 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:
- All units should be added to the package, independent if they are used. If a unit should not always be compiled in (not added to the uses section of the package), just unset the 'uses unit' checkbox.
- If the "uses unit" flag is not set, the unit will not be compiled. Nor in win32 (where is needed) neither in the other OS-es. It will be compiled only if another unit in the package uses it. So you must add for example {$IFDEF win32}uses oleutils.pas{$ENDIF} somewhere to one of the package units.
- You can put units specific to targets into sub directories as demonstrated in the Lazarus and FPC sources (units/$(TargetOS)).
- Conclusion: There is no real need for conditional options for single units, as this is already possible.