Project Configurations are a feature of MPLAB® X IDE that effectively enables "projects within projects." This feature addresses 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., the 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 to handle this 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 includes 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 within 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 set up two configurations within your project that are identical in every way except for the selected debug tool. Then you can use the project configuration feature 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.
Configuration Name Restrictions
Some special characters cannot be used in configuration names. This is because we are able to use the configuration name within the source code as a define macro, i.e., MPLAB XC C compiler preprocessor macros.
Special characters like a hyphen (-), ampersand (&), etc., will be automatically replaced with an underscore (_).