Project Configurations are a feature of MPLAB® X IDE that effectively enables "projects within projects". Project Configurations address many different scenarios that often come up in the world of embedded development.
Conditionally Compiled Code
There are numerous instances when conditionally compiled code can make our lives easier:
- Single code base to support multiple related products, differing only in which features are available:
- Incremental feature sets (e.g. low-end version and high-end version of a product)
- Different interface (e.g. same product using a different sensor, display module, etc.)
- Single code base with "tweaks" for different end customers
- Different parameters (e.g. alarm/siren patterns, lighting level, speed, calibration, etc.)
- Language differences (e.g. European vs. Brazilian Portuguese, English vs. Chinese, etc.)
- Blocks of code that are only used for debugging or testing
The traditional way this is handled is to use #ifdef directives to test for the presence or absence of a #define. While this works reasonably well, Project Configurations can greatly enhance this mechanism by tying it into the IDE itself and making it even easier to switch between the different variations of the code.
Target Device, Tools, Tool Settings
Sometimes, the difference between a low-end and high-end version of an end product include a different target microcontroller (to accommodate additional memory, I/O, etc.). Project Configurations make this easy because you can change every characteristic of your project inside of each configuration.
- Different Target Devices
- Different Compiler Settings
- Different Compilers
- Different Debug Tools
In some development environments, you might frequently switch between a tool like the MPLAB® REAL ICE™ In Circuit Emulator and the simulator built into MPLAB X IDE. You could setup two configurations within your project that are identical in every way except for the selected debug tool. Then you can use project configurations to quickly swap tools without having to open the project properties window.
Per File Configuration
In some instances, it might be convenient to operate at the file level. Project Configurations allow you to:
- Include or Exclude entire files from a project configuration
- Set compiler options for individual files (e.g. override the project's memory model or optimization level for an individual file)
Including or excluding entire files just takes the conditional compilation concept to a higher level. While this could be done with #ifdef directives, the project configuration method is cleaner and more elegant.