7.4. 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. (See Scenario Variables for an the details of 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.

In the GNAT project file shown in the following figure, note the scenario variable named “Mode” declared on line 5. On that same line, note the use of the “external” function that references the name “BUILD” as the external name by which we can get values for Mode. That external name is used on the command line and in the Scenario Variables View as you will see shortly.

project file showing scenario var

The scenario variable Mode has two possible values because of its type: “Production” and “Debug”. (These values are case-sensitive because they are strings.) As you have guessed, these two values represent two different build scenarios. “Production” 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 packages in the project file.

The value of the variable Mode, then, controls how the executable is built so we must control the value of the variable. This control is accomplished using the Scenario Variables View. In the following figure we see the use of the external reference name “BUILD” and the corresponding value “Debug” in the view.

tutorial scenario var debug setting

When “BUILD” has the value “Debug”, the builder will apply the switches corresponding to that scenario. We can see them in the Build Console below. Look for the use of the switches (e.g., “-g”, “-gnato”) on the command line.

content of Build Console after successful build

We can change the value of “BUILD” to “Production” by double-clicking on the value to get a list of all possible values in a pull-down list, as shown below:

tutorial scenario var production setting

Changing the value of “BUILD” to “Production” and then rebuilding will apply the different switches:

content of Build Console after changing BUILD to Production