Multiple project configurations make it possible to use the same code base with different sets of project properties. For example, many projects are targeted at multiple platforms where a single code base may be compiled for different target microcontrollers. This is often accomplished with a series of #ifdef directives to select specific blocks of code only when a particular microcontroller is chosen as the target. MPLAB® X IDE's project configurations can help make working with multiple target platforms very easy.
For this example, assume we have two versions of the target hardware that are very similar and use the same code base. One version has more features and might even use a PIC® microcontroller with more memory and a couple of extra peripherals. Let's call them the Cheap Version and the Expensive Version.
1
First create a project with multiple configurations. Name one configuration "Cheap_Version" and the other "Expensive_Version" (or whatever describes them best for your situation).
2
For each configuration, select the C compiler node in the tree along the left side (the compiler itself, not the suite heading). Under the General category (combo box at top center of window) click on the "…" to the right of Preprocessor Macros and create a macro label to identify the configuration. For example, in the "Cheap_Version" configuration create a macro label "CHEAP_VERSION" and in the "Expensive_Version" configuration create a macro label "EXPENSIVE_VERSION".
Other options may be changed between the two configurations such as which PIC microcontroller will be the target, compiler settings, and so on. The two configurations can be completely different except that they share the same source files.
3
In your code, you can now use the macro labels you just defined to identify which blocks of code should be used for each configuration. For example:
4
The combo box on the toolbar may be used to switch between the two configurations. When you build the project, it will use the options for the selected configuration and will correctly select conditional code blocks inside #ifdef directives based on the macro label provided.
Although the editor generally colors unused #ifdef blocks the same as comments, you might need to save the project after changing configurations for the colors to change properly.