Yet Another Robot Platform
How to install files for the ResourceFinder
Lorenzo Natale and Elena Ceseracciu


In previous tutorials (The ResourceFinder Class (basic) and The ResourceFinder Class (advanced)) we showed how you can employ the yarp::os::ResourceFinder to locate files on your machine. In those tutorials, the files were manually created inside the user's "local" directory; here, we show how to install those files within a project, so that you can provide default configuration files for modules or even complete applications.

Files to be installed

The module from The ResourceFinder Class (basic) required the "robot","part", and "joint" initialization parameters. Default values were provided in a file:


robot icub
part head
joint 0

We saved this file into a subdirectory of our source tree; we chose the "randomMotion" subdirectory, in our <YARP_SOURCE_CODE>/examples/resourceFinder directory.

We defined a default initialization context, i.e., "randomMotion", for the module to locate files; this means that in the source code, the ResourceFinder was configured like this:

ResourceFinder rf;
rf.configure(argc, argv);

We'll see now how to setup installation rules so that after compilation the configuration files for the module will be available without manual copies.

CMake to the rescue

The minimal CMake file that allows to build our tutorial modules is this (this CMake file actually builds the two Resource Finder tutorials):

cmake_minimum_required(VERSION 3.5)

find_package(YARP REQUIRED)

add_executable(rf_basic tutorial_rf_basic.cpp)
target_link_libraries(rf_basic ${YARP_LIBRARIES})

add_executable(rf_advanced tutorial_rf_advanced.cpp)
target_link_libraries(rf_advanced ${YARP_LIBRARIES})

The yarp_install macro is loaded automatically with find_package(YARP):

Now, we add:

set(conf randomMotion/config.ini)

to tell CMake which files to install, and

yarp_install(FILES ${conf} DESTINATION ${YARP_CONTEXTS_INSTALL_DIR}/randomMotion)

to tell CMake where to install those files.

Instead of creating the conf variable by listing all configuration files explicitly as in set(conf randomMotion/configure.ini), one can have CMake figure out the list or all configuration files like this:
file(GLOB conf randomMotion/*.ini)
but GLOBBING is EVIL, so we do not recommend it.


Keep in mind that the ${YARP_CONTEXTS_INSTALL_DIR} variable expands to a relative path that will be appended to the installation prefix chosen by the user; the user should be warned to use the same installation directory as YARP, or to configure their system as explained 3rd party packages (for developers) here.

Remember that you can always inspect the state of contexts on your machine, and customize installed configuration files, using the yarp-config: the yarp-config tool utility.


See code in: example/resourceFinder/CMakeLists.txt