Chord wrote:Does pascal has something can automatically choose its line to compile by project's target controller, like C's preprocessor?
Not yet, we borrowed the target controller functionality from the embedded target of FPC and something it didn't implement was adding a define to identify the selected target (whereas there is one for the target CPU and OS).
We hope to add that as an option when we upgrade to the latest FPC in the next release but in the meantime there are a couple of easy ways to deal with this.
For many small projects, tests and examples we compile from the command line and just maintain a set of batch files with the correct parameters for each Pi model we want to compile for, when compiling from the command line it is a simple matter to just add an extra define using the -d
option (eg -dRPI3
) to allow testing for it in the code.
If you prefer to use Lazarus you can do something equally as simple by just creating multiple .lpr files for your project. The basic idea is to put only the bare minimum amount of code in the project lpr file and instead put all of your project code into units that are included from the project file.
For example you might have MyProject.lpr (and the corresponding MyProject.lpi) which includes the necessary driver units so that your project has all the needed services available but simply does some very basic setup before calling your main project code in another unit. Instead of having just MyProject.lpr you could have MyProject-RPI.lpr, MyProject-RPI3.lpr and MyProject-QEUM.lpr with each one including the correct driver units for that target, then you can add a define to each project under Project, Project Options..., Compiler Options, Custom options, Defines...
and also set the correct target CPU, processor and controller so the project lpr and lpi files contain everything needed to correctly compile for that target.