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
but the "with"ed entities are strings denoting project files.
As an example, suppose that the two projects
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.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
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:
which will generate the
app_main executable in the directory where
If an imported project file uses the standard extension (
(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_PATHthat 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
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.