6.1. Description of the Projects
6.1.2. Contents of project files
Project files contain all the information describing the organization of
your source files, object files, and executables.
A project file can contain comments, which have the same format as in Ada:
they start with “–” and extend to the end of the line. You can add
comments when you edit the project file manually. GPS attempts to preserve
them when you save the project through the menu, but this is not always
possible. GPS is more likely to preserve them if the comments are put at
the end of the line:
project Default is
for Source_Dirs use (); -- No source in this project
end Default;
Often, one project file is not enough to describe a complex system. If so,
you will create and use a project hierarchy, with a root project importing
subprojects. Each project and subproject is responsible for its own set of
sources (including compiling them with the appropriate switches and putting
the resulting files in the correct directories).
Each project file contains the following information (see the GNAT Pro
User’s Guide for the full list):
List of imported projects
When compiling sources from this project, the builder first makes sure it
correctly recompiled all the imported projects and that they are up to
date. This properly handles dependencies between source files.
If one source file of project A depends on some source files from project
B, B must be marked as imported by A. If this is not done, the compiler
will complain that those source files cannot be found.
Each source file name must be unique in the project hierarchy (i.e., a
file cannot be under control of two different projects), ensuring that
the file will be found no matter what project is managing it.
List of source directories
All sources managed by a project are located in one or more source
directories. Each project can have multiple source directories and a
given source directory may be shared by multiple projects.
Object directory
When sources of the project are compiled, the resulting object files are
put in this directory. There must be exactly one object directory for
each project. If you need to split the object files across multiple
directories, you must create multiple projects importing each other.
When sources from imported subprojects are recompiled, the resulting
object files are put in the subproject’s own object directory and not the
parent’s object directory.
Exec directory
When the object files are linked into an executable, this executable is
put in the exec directory specified by this attribute. If it is omitted,
the builder puts the executable into the object directory.
List of source files
Each project is responsible for managing its set of source files. These
files can be written in any programming language, but the graphical
interface supports only Ada, C, and C++.
By default, these source files are found by taking all the files in the
source directories that follow the naming scheme (see below) for each
language. You can also edit the project file manually to provide an
explicit list of source files.
This attribute cannot be modified graphically.
List of main units
The main units of a project (or main files in some languages) are the
units containing the main subprogram of the application. The name of the
file is generally related to the name of the executable.
A project file hierarchy can be used to compile and link several
executables. GPS automatically updates the Compile,
Run and Debug menu with the list of executables
based on this list.
Naming schemes
The naming scheme refers to the way files are named for each language
used by your project. GPS uses this to choose the language to use when
you open a source file and what tools to use to compile or otherwise
manipulate a source file.
Embedded targets and cross environments
GPS supports cross environment software development: GPS itself can run
on one host, such as GNU/Linux, while compilation, execution, and
debugging occur on a different remote host, such as Sun/Solaris.
GPS also supports embedded targets such as VxWorks by specifying
alternate names for the build and debug tools.
The project file contains the information required to log on to the
remote host.
Tools
Project files provide a simple way of specifying the compiler and
debugger commands to use.
Switches
Each tool used by GPS (such as the compiler, pretty-printer, and
debugger) has its own set of switches. Moreover, these switches may
depend on the file being processed and the programming language it is
written in.
6.2. Supported Languages
Other information stored in the project file is the list of languages used
by the project. GPS supports any language, each with a name you choose, but
advanced support is only provided by default for some languages (Ada, C, and
C++). You can specify other properties of the languages through
customization files (see Adding support for new languages).
The graphical interface only allows you to choose languages currently known
to GPS, either through built-in support or your customization files.
Supporting a languages means syntax highlighting in the editor, and
possibly the Outline view. Other languages have advanced
cross-references facilities available. You can edit the project files by
hand to add support for any language.
Languages are a very important part of the project definition. For each
language, you should specify a naming scheme to allow GPS to associate files
with that language. For example, you could specify that all .adb
files are Ada, all .txt files are standard text files, etc.
Only files that have an associated known language are displayed in the
Project view and available for selection through the
menu. Similarly, only these
files are shown in the Version Control System interface. It is important to
properly set up your project to make these files conveniently available in
GPS although you can still open any file through the menu.
If your project includes README files, or other text files, you
should add “txt” as a language (the name is arbitrary) and ensure these
files are associated with that language in the .
6.3. Scenarios and Configuration Variables
You can further tailor the behavior of project by using scenarios.
You can specify the value of all attributes of a project except its list of
imported projects based on the value of external variables, each of which
comes from either the host computer environment or is specifically set in
GPS. The interface to manipulate these scenarios is the
Scenario view, which you display by selecting the menu
(The Scenario View). You may want to drop this window above the
Project view so you can see both at the same time.
The Scenario view allows you to select new values for the
scenario variables defined in your project and thus dynamically change the
view GPS has of your project and its source files.
For example, you can use this facility to compile all the sources either in
debug mode (so the executables can be run in the debugger) or in optimized
mode (to reduce the space and increase the speed when delivering the
software). In that scenario, most of the attributes (such as source
directories and tools) remain the same, but compilation switches differ.
You could also maintain a completely separate hierarchy of projects, but
it is much more efficient to create a new configuration variable and edit
the switches for the appropriate scenario (see
The Project Properties Editor).
There is one limitation on what GPS can do with scenario variables:
although gnatmake and gprbuild can use scenario
variables whose default value is something other than static string (for
example, a concatenation or the value of another scenario variable), GPS
cannot edit such a project graphically, though such projects load
correctly.
6.3.1. Creating new scenario variables
Create a new scenario variable through the contextual menu (right-click) in
the Project or Scenario views themselves. Select
the menu, which
opens the following dialog:
There are two main areas in this dialog. You specify the name of the
variable in the top line. This name is used for two purposes:
It is displayed in the Scenario view
It is the name of the environment variable from which the initial value is
read. When GPS starts, all configuration variables are initialized from
the host computer environment, although you can later change their values
inside GPS. Selecting a new value for the scenario variable does not
change the value of the environment variable, which is only used to get
the default initial value of the scenario variable.
When you spawn external tools like gnatmake you can also
specify the value they should use for the scenario variable by using a
command line switch, typically -X.
Click on the arrow on the right of the name area to display the list of all
currently-defined environment variables. However, you can choose any
variable; the environment variable need not exist when you start GPS.
The second area in this dialog is the list of possible values for this
variable. GPS generates an error and will not load the project if you specify
any other value. One of these values is the default (the one whose button
in the Default column is selected). If the environment variable
is not defined when GPS starts, it behaves as if it had this default
value.
You can edit the list of possible values by right-clicking on the name of
the variable and selecting either Edit properties or
Delete variable.
6.3.2. Editing existing scenario variables
If at least one configuration variable is defined in your project, the
Scenario view contains something similar to:
You can change the current value of any of these variables by clicking on
one, which displays a pop-up window with the list of possible values, from
which you select the one you want to use.
As soon as a new value is selected, GPS recomputes the Project
view (in case source directories, object directories or list of source
files have changed). GPS also updates other items such as the list of
executables in the Compile, Run, and
Debug menus.
Because it can be time consuming and costly of system resources, GPS does
not recompute the contents of the various browsers, such as the call graph
and dependencies, for this updated project. You must explicitly request that
they be updated if you want them recomputed.
Change the list of possible values for a configuration variable at any time
by clicking on the edit button in the local toolbar. This pops
up the same dialog used to create new variables, and also allows you to
change the name of the scenario variable (the same name as the
environment variable used to set the initial value of the scenario
variable).
To remove a variable, select it and click the remove button in
the local toolbar. GPS displays a confirmation dialog. When the variable
is removed, GPS acts as if the variable always had the value it had when it
was removed.
6.4. Extending Projects
6.4.1. Description of project extensions
Project files are designed to support large projects, with several hundred
or even several thousand source files. In such contexts, one developer will
generally work on a subset of the sources. Such a project may often take
several hours to be fully compiled. Most developers do not need to have the
full copy of the project compiled on their own machine.
However, it can still be useful to access other source files from the
application. For example, a developer may need to find out whether a
a subprogram can be changed, and where it is currently called.
Such a setup can be achieved through project extensions. These are special
types of projects that inherit most of their attributes and source files
from another project and can have, in their source directories, some source
files that hide those inherited from the original project.
When compiling such projects, the compiler puts the newly created project
files in the extension project’s directory and leaves the original
directory untouched. As a result, the original project can be shared
read-only among several developers (for example, the original project is
often the result of a nightly build of the application).
6.4.2. Creating project extensions
The project wizard allows you to create extension projects. Select an
empty directory (which is created if it does not exist), as well as a list of
initial source files (new files can be added later). GPS copies the
selected source files to the directory and creates a number of project
files there. It then loads a new project, with the same properties as the
previous one, except that some files are found in the new directory and
object files resulting from the compilation are put into that directory
instead of the object directory of the original project.
6.4.3. Adding files to project extensions
Once you load a project extension in GPS, most things are transparent to
the extension. If you open a file through the dialog, the files found in the local directory of the
extension project are picked up first. Build actions create object files
in the project extensions’s directory, leaving the original project
untouched.
You may want to work on a source file you did not put in the project
extension when you created it. You could edit the file in the original
project (provided, of course, you have write access to it). However, it is
generally better to edit it in the context of the project extension, so the
original project can be shared among developers. Do this by clicking the
file in the Project view and selecting the menu. You will see a dialog asking whether you want
GPS to copy the file to the project extension’s directory. GPS may also
create some new project files in that directory, if necessary, and
automatically reload the project as needed. From that point on, if you use
the menu , GPS uses the file
from the project extension. Open editors will still edit the same files
they previously contained, so you should open the new file in them if
needed.
6.6. Disabling Editing of the Project File
You should generally consider project files part of the sources and put
them under the control of a version control system. This will prevent
accidental editing of the project files, either by you or someone else
using the same GPS installation.
One way to prevent such accidents is to change the write permissions of the
project files themselves. On Unix systems, you could also change the owner
of the file. When GPS cannot write a project file, it reports an error to
the user. However, the above does not prevent a user from trying to make
changes at the GUI level, since the error message only occurs when trying
to save the project (this is by design, so that temporary modification can
be done in memory).
You can disable all the project editing related menus in GPS by adding a
special startup switch, typically by creating a short script that spawns
GPS with these switches. Use the following command line:
gps --traceoff=MODULE.PROJECT_VIEWER --traceoff=MODULE.PROJECT_PROPERTIES
This prevents the loading of the two GPS modules responsible for editing
project files. However, this also has an impact on the Python functions
that are exported by GPS and thus could break some plug-ins. Another
possible solution is to hide the corresponding project editing menus and
contextual menus. You could do this by creating a simple Python plug-in for
GPS (see Customizing through XML and Python files), which contains
the following code:
import GPS
GPS.Menu.get('/Project/Edit Project Properties').hide()
GPS.Contextual('Edit project properties').hide()
GPS.Contextual('Save project').hide()
GPS.Contextual('Add configuration variable').hide()
6.8. The Project Wizard
The project wizard allows you to create a new project file in a few steps.
It contains a number of pages, each dedicated to editing a specific set of
attributes of the project.
You normally access this wizard through the menu. The project wizard is also launched when you create a new
dependency between two projects using the contextual menu in the project
view.
The wizard has the following pages:
6.8.1. Project Type
Several types of project wizards are provided in GPS:
Single Project
This is the wizard you will probably use most often. It creates a project
file from scratch and asks you for the location of source directories and
the object directory. The rest of this chapter describes this wizard in
more detail.
Single Project with complex naming scheme
Use this wizard to create a project for existing Ada units stored in
files with irregular or arbitrary naming conventions. To do this, specify
file name patterns on page File patterns. GPS uses these
patterns to search for Ada units in each source directory specified in
the Source Directory Selection page using the gnatname
tool and generates the required pragmas for the set of files.
Project Tree
This wizard attempts to create a set of one or more project files to
represent your current build environment. It analyzes the location of
your sources and corresponding object files and tries to find a possible
configuration for the project files (a given .gpr project file
can only be associated with a single object directory).
This wizard may not succeed in all cases but is worth trying if you
already have an existing set of sources
Library Project
This specialized wizard is similar to the Single Project
wizard, except it adds one extra page, the Library page. The
output of the compilation of this project is a library (shared or
static), as opposed to an executable in the case of Single
Project.
Project Extention
This specialized wizard allows you to easily create project extentions.
(See Extending Projects).
6.8.2. Project Naming
This is the first page displayed by all the wizards and is where you enter
the name and location of the project to create. The name must be a valid
Ada identifier (starting with a letter, optionally followed by a series of
digits, letters or underscores). Spaces and reserved Ada keywords are not
allowed. If the name is invalid, GPS displays an error message when you
press the Forward button.
You can create child projects from this dialog. These are projects
whose name is of the form Parent.Child. GPS automatically generates
the dependency on the parent project.
The last part of this page indicates how the path should be stored in the
generated project file. Most of the time, this setting has no impact on
your work. However, if you plan to edit the project files by hand or be
able to duplicate a project hierarchy to another location on your disk, it
might be useful to indicate that paths should be stored as relative paths
(relative to the location of the project file).
6.8.3. Language Selection
Use this page to select the programming languages used for the sources of
the project. By default, only Ada is selected. You can add new languages
to this list by using XML files (see the section on customizing GPS:
Adding support for new languages).
This page allows you to select the toolchain used when working on your
project. You can select one of the pre-defined toolchains or scan your
system for installed toolchains. You can also manually define some of the
tools in the toolchain such as which debugger, GNAT driver, or
gnatls tool to use. If you need to select a toolchain for a
cross environment, see Working in a Cross Environment for more
information.
6.8.4. VCS Selection
The second page in the project wizard allows you to select which Version
Control System you want to use for the source files of this project. GPS
does not attempt to automatically guess what it should use, so you must
specify it if you want VCS operations to be available.
The two fields Log checker and File checker are the
name and location of programs to be run just prior an actual commit of the
files in the Version Control System. These should be used if you wish to
enforce style checks before a file is actually made available to other
developers in your team. If left blank, nothing is run.
6.8.5. Source Directory Selection
This page displays and allows you to edit the list of source directories
for the project. You can use an arbitrary number of source directories (the
default is the directory containing the project file, specified in the
first page of the wizard). If you do not specify any source directories, no
source files are associated with the project.
Use the top frame to select a directory to add. The bottom frame displays
the current list of directories. You can change the sizes of the frames by
dragging the separation line between them.
To add source directories to the project, select a directory in the top
frame and click on the down arrow. This adds the directory to the bottom
frame, which contains the current list of source directories. You can also
add a directory and all its subdirectories recursively by using the
contextual menu in the top frame. This contextual menu also provides an
entry to create new directories, if needed.
To remove source directories from the project, select the directory in the
bottom frame and click on the up arrow or use the contextual menu.
All files in these directories that match one of the languages supported by
the project are automatically associated with that project.
6.8.6. Build Directory
The object directory is the location where the files resulting from the
compilation of sources (usually, .o files) are placed. One object
directory is associated with each project.
The exec directory is the location where the executables are put. By
default, this is the same as the object directory.
6.8.7. Main Units
The main units of a project are the files to be compiled and linked to
obtain executables.
Typically, for C applications, these are the files that contain the
main function. For Ada applications, these are the files that
contain the main subprogram for each partition in the project.
These files are treated specially by GPS. Some submenus of
and have predefined entries
for the main units, making it more convenient to compile and link your
executables.
To add main units, click the Add button, which opens a file
selection dialog. No check is done at that point to ensure that the
selected file belongs to the project, but GPS complains later if it
does not.
When compiled, each main unit generates an executable, whose name is
visible in the second column of this page. If you are using a recent enough
version of GNAT (3.16 or more recent), you can change the name of this
executable by clicking in the second column.
6.8.8. Library
This page allows you to configure your project so the output of its
compilation is a library (shared or static), as opposed to an executable or
a set of objet files. You can then link this library with other
executables (it will automatically be linked if the project is imported by
another project).
Define the attributes in the top box to transform your project into a
library project. See the tooltips that appear to the left of each field.
If you define any of the attributes in the Standalone Library
box, your project will create a standalone library, which is a library that
does its own elaboration instead of relying on its caller to elaborate it,
as is standard in Ada. You also have more control over which files make up
the public interface to the library and which files are private to the
library and invisible from the outside.
6.8.9. Naming Scheme
A naming scheme indicates the file naming conventions used by each of the
different languages used in a project. For example, all .adb files
are Ada files, all .c files are C files.
GPS is very flexible with naming schemes and allows you to specify the
default extension for the files in each language. GPS makes a distinction
between spec (or header) files, which generally contain only declarations
and no executable code, and body files, which contain the actual code. For
languages other than Ada, this header file is used as the “body” file when
you select in the contextual menu of
editors. In a language like Ada, the distinction between spec and body is
part of the language itself.
The default naming scheme for Ada is GNAT’s naming scheme (.ads for
specs and .adb for bodies). In addition, a number of predefined
naming schemes for other compilers are available in the first combo box on
the page. Create your own customized scheme by entering text in the text
entries.
For all languages, GPS accepts exceptions to this standard naming
scheme. For instance, you can specify that, in addition to using
.adb for Ada body files, the file foo.ada should also be
considered as an Ada file.
GPS displays the list of exceptions in the bottom list of the naming scheme
editor. To remove entries from this list, select the line you want to
remove and press the Del key. You can edit the contents of any line
by double-clicking on the line and column you want to edit.
To add new entries to this list, use the fields at the bottom of the window
and press the update button.
GNAT and GPS both support Ada sources containing multiple Ada units
(typically a single file would contain both the spec and the body of a
unit, for example). This is not recommended since that might trigger
unnecessary recompilation of your source files, but you can handle such
source files as naming scheme exceptions. Specify those in the editor by
adding at 1, at 2 (and so on) after the file name for
either the spec, the body, or both. The digit after at is the index
(starting at 1) of the unit in the source file.
For example, specifying file.ada at 1 for the spec and
file.ada at 2 for the body of the unit unit indicates
that the two components of the unit are in the same file, with the spec
first, followed by the body.
6.8.10. Switches
Use the last page of the project wizard to specify the default switches to
be used by the various tools that GPS calls such as the compiler, linker,
binder, and pretty printer.
This page appears as a notebook, where each page is associated with a
specific tool. All pages have the same structure:
Graphical selection of switches
The top of each page contains a set of buttons, combo boxes, and entry
fields, giving quick and intuitive access to the most commonly used
switches for that tool.
Textual selection of switches
The bottom is an editable entry field, where you can directly enter the
switches you need. This makes it easier to move from an older setup
(e.g. Makefile, script) to GPS by copying and pasting switches.
You can add any switch to the entry field, even if there is no
corresponding button. In this case, GPS forwards it to the tool when
called, without trying to represent it graphically on the page.
GPS keeps the two parts of the pages synchronized at all times: clicking on
a button modifies the entry field to show the new switch and adding a new
switch by hand in the entry field activates the corresponding button, if
such button exists.
6.9. The Project Dependencies Editor
Edit the dependencies between projects through the contextual
menu in the
Project view.
This view makes it easy to indicate that your project depends on external
libraries or other modules in your source code. For example, you can get
access to the GtkAda graphical library in your project by adding a project
dependency to gtkada.gpr (assuming GtkAda has been installed in
your system).
The dependencies also determine in what order your application is built.
When you compile a project, the builder first makes sure the projects it
depends on are up-to-date. If not, it recompiles them.
When you select that contextual menu, GPS opens a dialog allowing you to
add or remove dependencies from your project. You add a new dependency
by selecting a project file name from one of the following sources:
One of the loaded projects from the current project tree
One of the predefined projects
These are the projects are found in one of the directories referenced by
the ADA_PROJECT_PATH environment variable. Typically, these
include third party libraries, such as GtkAda or win32ada.
A new project created through the project wizard
Any project file located on the disk
In all cases, you can choose whether this should be a simple dependency or
a limited dependency. The latter allows you to have mutually dependent
projects (A depends on B, which in turns depends on
A even indirectly), although you cannot reference the attributes of
such a project in the current project (for example, to indicate that the
compiler switches to use for A are the same as for B you
need to duplicate that information). In some cases, GPS forces a limited
dependency to avoid loops in the dependencies that would make the project
tree illegal.
6.10. The Project Properties Editor
Use the Project Properties editor at any time to access the
properties of your project through the menu or the contextual menu on any project item, e.g. from the Project
views or the Project browser.
If there was an error loading the project (such as invalid syntax or
non-existing directories), GPS displays a warning dialog when you select
the menu. This reminds you that the project might be only partially loaded,
and editing it might result in the loss of data. In such cases, you should
edit the project file manually, which you can do directly from the pop-up
dialog.
Correct the errors in the project file by editing it as you would any text
file and reload it manually (through the or menus).
The Project Properties editor is divided into three parts:
The attributes editor
The contents of this editor are very similar to that of the project
wizard (see The Project Wizard). In fact, all pages but the
General page are exactly the same; read their description in
the project wizard section.
See also Working in a Cross Environment for more info on the
Cross environment attributes.
The project selector
This area, the top-right corner of the properties editor, displays a list
of all projects in the hierarchy. The value in the attributes editor is
applied to all the selected projects in this selector. You cannot unselect
the project for which you activated the contextual menu.
Clicking on the right title bar (Project) of this selector
sorts the projects in ascending or descending order. Clicking on the
left title bar (untitled) selects or deselect all the projects.
This selector has two different possible presentations, chosen by the
toggle button on top: either a sorted list of all the projects, each
appearing only once, or the same project hierarchy displayed in the
Project view.
The scenario selector
This area, the bottom-right corner of the properties editor, displays all
scenario variables declared in the project hierarchy. By selecting some
or all of their values, you can chose to which scenario the modifications
in the attributes editor apply.
Clicking on the left title bar (untitled, on the left of the
Scenario label) selects or deselects all values of all
variables.
To select all values of a given variable, click on the corresponding
check button.
6.11. The Switches Editor
The switches editor, available through the menu, displays all source files associated with the selected
project.
For each file, it lists the compiler switches for that file. These switches
are displayed in gray if they are the default switches defined at the
project level (see The Project Properties Editor) and in black if
they are specific to that file.
Edit the switches for the file by double-clicking in the switches column.
You can edit the switches for multiple files at the same time by selecting
them before displaying the contextual menu .
When you double-click in one of the columns containing switches, GPS opens
a new dialog allowing you to edit the switches specific to the selected
files. This dialog has a button titled Revert, which cancels
any file-specific switch and reverts to the default switches defined at the
project level.