Building Projects with Scenarios

GNAT project files have the concept of scenario variables that allow considerable flexibility in controlling how the tools build an executable, among other possible uses. (See Scenario Variables for details on scenario variables, and GNAT Projects for the details of GNAT project files.) You can define, for example, different scenarios for debugging and releases, in which optimization and symbolic information are either present or not, respectively.

GNATbench provides the Scenario View for managing scenario variables. The idea is that you can view and control the build by changing the values of the scenario variables within this view. (See Scenario Variables View for details.)

Note that scenario variable settings persist across Workbench sessions so there is no need to set them again whenever Workbench is started or a closed project is re-opened.

The wizard that created our new project also created the corresponding GNAT project file for us. It is shown below. Note the scenario variable named "Mode".

project file created by wizard with scenarios

The variable Mode has two possible values because of its type: "Release" and "Debug". (These values are case-sensitive because they are strings.) As you have guessed, these two values represent two different build scenarios. "Release" corresponds to the scenario in which you build for actual delivery. The "Debug" scenario is for development and testing. Therefore, these scenarios require different switches to be applied and this fact is reflected in the content of the project file. Note in particular the switches set in the package Compiler depending on the value of Mode. You will see these switches applied in the build console.

The initial value of Mode is "Debug" because that is the default:

scenario view showing Debug selection

If we build the project with that value for Mode we will see the corresponding debugging switches set:

content of build console after successful build

If we change the value of "BUILD" to "Release"

scenario view showing Release selection

and then rebuild we will see the different switches applied:

content of build console after changing BUILD to Release