Next: Extending a Project, Previous: Using External Variables, Up: Examples of Project Files
A compilation unit in a source file in one project may depend on compilation
units in source files in other projects. To obtain this behavior, the
dependent project must import the projects containing the needed source
files. This effect is embodied in syntax similar to an Ada with
clause,
but the "with"ed entities are strings denoting project files.
As an example, suppose that the two projects GUI_Proj
and
Comm_Proj
are defined in the project files gui_proj.gpr and
comm_proj.gpr in directories /gui and /comm,
respectively. Assume that the source files for GUI_Proj
are
gui.ads and gui.adb, and that the source files for
Comm_Proj
are comm.ads and comm.adb, with each set of
files located in its respective project file directory. Diagrammatically:
/gui gui_proj.gpr gui.ads gui.adb /comm comm_proj.gpr comm.ads comm.adb
We want to develop an application in directory /app that "with"s the
packages GUI
and Comm
, using the properties of the
corresponding project files (e.g. the switch settings and object directory).
Skeletal code for a main procedure might be something like the following:
with GUI, Comm; procedure App_Main is ... begin ... end App_Main;
Here is a project file, app_proj.gpr, that achieves the desired effect:
with "/gui/gui_proj", "/comm/comm_proj"; project App_Proj is for Main use ("app_main"); end App_Proj;
Building an executable is achieved through the command:
gnatmake -P/app/app_proj
which will generate the app_main
executable in the directory where
app_proj.gpr resides.
If an imported project file uses the standard extension (gpr
) then
(as illustrated above) the with
clause can omit the extension.
Our example specified an absolute path for each imported project file. Alternatively, you can omit the directory if either
ADA_PROJECT_PATH
that
includes the directory containing the needed project file.
Thus, if we define ADA_PROJECT_PATH
to include /gui and
/comm, then our project file app_proj.gpr could be written as
follows:
with "gui_proj", "comm_proj"; project App_Proj is for Main use ("app_main"); end App_Proj;
Importing other projects raises the possibility of ambiguities. For example, the same unit might be present in different imported projects, or it might be present in both the importing project and an imported project. Both of these conditions are errors. Note that in the current version of the Project Manager, it is illegal to have an ambiguous unit even if the unit is never referenced by the importing project. This restriction may be relaxed in a future release.