Previous: Syntax of aggregate projects, Up: Aggregate Projects


5.7.6 package Builder in aggregate projects

As mentioned above, only the package Builder can be specified in an aggregate project. In this package, only the following attributes are valid:

`Switches':

This attribute gives the list of switches to use for `gprbuild'. Because no mains can be specified for aggregate projects, the only possible index for attribute Switches is others. All other indexes will be ignored.

Example:

    for Switches (others) use ("-v", "-k", "-j8");

These switches are only read from the main aggregate project (the one passed on the command line), and ignored in all other aggregate projects or projects.

It can only contain builder switches, not compiler switches.

`Global_Compilation_Switches'

This attribute gives the list of compiler switches for the various languages. For instance,

    for Global_Compilation_Switches ("Ada") use ("O1", "-g");
    for Global_Compilation_Switches ("C")   use ("-O2");

This attribute is only taken into account in the aggregate project specified on the command line, not in other aggregate projects.

In the projects grouped by that aggregate, the attribute Builder.Global_Compilation_Switches is also ignored. However, the attribute Compiler.Default_Switches will be taken into account (but that of the aggregate have higher priority). The attribute Compiler.Switches is also taken into account and can be used to override the switches for a specific file. As a result, it always has priority.

The rules are meant to avoid ambiguities when compiling. For instance, aggregate project Agg groups the projects A and B, that both depend on C. Here is an extra for all of these projects:

    aggregate project Agg is
        for Project_Files use ("a.gpr", "b.gpr");
        package Builder is
           for Global_Compilation_Switches ("Ada") use ("-O2");
        end Builder;
    end Agg;
    
    with "c.gpr";
    project A is
        package Builder is
           for Global_Compilation_Switches ("Ada") use ("-O1");
           --  ignored
        end Builder;
    
        package Compiler is
           for Default_Switches ("Ada")
               use ("-O1", "-g");
           for Switches ("a_file1.adb")
               use ("-O0");
        end Compiler;
    end A;
    
    with "c.gpr";
    project B is
        package Compiler is
           for Default_Switches ("Ada") use ("-O0");
        end Compiler;
    end B;
    
    project C is
        package Compiler is
           for Default_Switches ("Ada")
               use ("-O3",
                    "-gnatn");
           for Switches ("c_file1.adb")
               use ("-O0", "-g");
        end Compiler;
    end C;

then the following switches are used:

Even though C is seen through two paths (through A and through B), the switches used by the compiler are unambiguous.

`Global_Configuration_Pragmas'

This attribute can be used to specify a file containing configuration pragmas, to be passed to the Ada compiler. Since we ignore the package Builder in other aggregate projects and projects, only those pragmas defined in the main aggregate project will be taken into account.

Projects can locally add to those by using the Compiler.Local_Configuration_Pragmas attribute if they need.

`Global_Config_File'

This attribute, indexed with a language name, can be used to specify a config when compiling sources of the language. For Ada, these files are configuration pragmas files.

For projects that are built through the aggregate, the package Builder is ignored, except for the Executable attribute which specifies the name of the executables resulting from the link of the main programs, and for the Executable_Suffix.