Download GPRbuild User's Guide

Transcript
Chapter 1: GNAT Project Manager
For Exec_Dir use A’Exec_Dir; -- not ok
end B;
with "d.gpr";
project C is
end C;
limited with "a.gpr"; -- Cyclic dependency: A -> C -> D -> A
project D is
For Exec_Dir use A’Exec_Dir; -- not ok
end D;
1.3.3 Sharing Between Projects
When building an application, it is common to have similar needs in severa of
the projects corresponding to the subsystems under construction. For instance,
they will all have the same compilation switches.
As seen before (see Section 1.2.4 [Tools Options in Project Files], page 9),
setting compilation switches for all sources of a subsystem is simple: it is just a
matter of adding a Compiler.Default_Switches attribute to each project files
with the same value. Of course, that means duplication of data, and both places
need to be changed in order to recompile the whole application with different
switches. It can become a real problem if there are many subsystems and thus
many project files to edit.
There are two main approaches to avoiding this duplication:
• Since ‘build.gpr’ imports ‘logging.gpr’, we could change it to reference the
attribute in Logging, either through a package renaming, or by referencing
the attribute. The following example shows both cases:
project Logging is
package Compiler is
for Switches ("Ada") use ("-O2");
end Compiler;
package Binder is
for Switches ("Ada") use ("-E");
end Binder;
end Logging;
with "logging.gpr";
project Build is
package Compiler renames Logging.Compiler;
package Binder is
for Switches ("Ada") use Logging.Binder’Switches ("Ada");
end Binder;
end Build;
19