In previous tutorial you learned how to develop native packages that depends on other native packages. In this tutorial we will see how a native package can use external packages.
First of all just a precision on terminology:
- native packages are those implemented using the PID package API. In previous tutorial you defined and used only native packages.
- external packages are implemented using the PID wrapper API. External packages have not been defined using the PID API but with their own specific build system. They are provided with a description of their content in such a way that they can be used within PID nearly “as if” they were native packages.
Step 1: Define a dependency to an external package
Let’s suppose we want to add an external dependency to the package
my-first-package defined in previous tutorials. For instance, we want to use the well known
boost filesystem library.
boost is a very popular C++ project that provides many facilities to software developpers and it has been “wrapped” into PID.
The first thing to do is to declare
boost external project as a dependency of
my-first-package. To do this edit the CMakeLists.txt of
As you may see dependencies to external packages are expressed the same way as for native packages, using the
PID_Dependency command. We defined no version to the
boost dependency because all recent versions of
filesystem library and it has a very stable API so the code is supposed to be buildable with any version of boost wrapped into PID.
Step 2: Define a dependency to an external component
Now we will modify a bit the behavior of the
hello-app application defined in
my-first-package in order to make it use boost filesystem library.
2.1 Write the code
First edit the file named
apps/hello folder and paste the following code:
The code now checks if the string passed as argument is a valid path in filesystem and then prints it. To do this, it uses boost filesystem API that is found thanks to
#include <boost/filesystem.hpp> procedure.
2.2 Modify the description
So the source code of the application now also depends on
boost filesystem library and we need to configure the application adequately. Open the CMakeLists.txt file of the app folder and replace existing description with the following one:
Compared to previous version of the code we simply added the dependency
boost/boost-filesystem. So the description of dependencies to external components is the same as for native components.
Step 3: Configure, build and run
Now that the source code is ready, let’s build it.
- configure the package:
This command should deploy the boost package into your workspace (except if already installed). This deployment can lead to an automatic build of the
boost project which can take a long time.
- build the package:
The output of the command should print something like:
Step 4: Change dependency version
By default PID should have installed the last available version of
boost because there is not version constraint in specification of package dependency. To know which version is used launch the
The output gives you the exact version of
boost used by
my-first-package. Let’s suppose
my-first-package use version 1.64.0 of
boost and you want now to change this version to a previous one, let’s say 1.55.0:
In available user cache entries you should see one called
boost_ALTERNATIVE_VERSION_USED whose value should be
ANY. Now to change to the version 1.55.0 simply enter this version number instead of
ANY and reconfigure (type
g). This is equivalent to do:
This should again deploy
boost but this time the version 1.55.0. Then rebuild and run, you shoud see no difference ! Do:
The version for dependency
boost should have changed and is now 1.55.0.