INFORMATION NOTICE ON COOKIES : This website uses only browsing/session cookies. Users can choose whether or not to accept the use of cookies and access the website. By clicking on "Further Information", the full information notice on the types of cookies will be displayed and you will be able to choose whether or not to accept them whilst browsing on the website.Further information

CMake and FIND PACKAGE

One of the most important features of CMake is that it allows to configure your project to include/link additional packages (libraries). To do this you have to tell CMake you want to use an additional package, you do this with the FIND_PACKAGE macro. I found FIND_PACKAGE a bit confusing so I try to explain here how it works and how we have been using it on YARP.

Note: I here explain the functionalities of FIND_PACKAGE that are used in YARP, go to http://www.cmake.org for a more complete explanation.

FIND_PACKAGE(<name>) asks CMake to find and load settings from the external projects/packages called <name>. This works as follows:

CMake searches the directories listed in CMAKE_MODULE_PATH for a file called Find<name>.cmake. If found, this macro is executed and it is responsible for finding the package (examples of similar macro are: FindACE.cmake, FindBoost.cmake, FindOpenCV.cmake that are located in your $YARP_ROOT/conf directory). "Find" macros define variables which allow you to check if the package has been found and use it in your project. Unfortunately different macros behave differently so you have to check the code to find out the exact names of those variables (usually this is explained in the comments at the beginning of the file). For example, a Find macro might define:

<name>_FOUND // true iff the package was found
<name>_INCLUDE_DIR // a list of directories containing the package's include files
<name>_LIBRARIES // a list of directories containing the package's libraries
<name>_LINK_DIRECTORIES // the list of the package's libraries

If CMake does not find any Find<name>.cmake file in the directories listed in MAKE_MODULE_PATH, it assumes the package was built with CMake and has a "<name>Config.cmake" file associated. CMake expects the user to specify the location of this file by filling a cache entry called <name>_DIR (this entry is created by CMake automatically). If the file is found, it is processed to load the settings of the package (an error or a warning is displayed otherwise).

For example, when YARP is built CMake creates a file called YARPConfig.cmake in the "build" directory selected by the user. When users want to create a project which uses YARP they do something like:

The macro FIND_PACKAGE automatically searches YARP_DIR for the file YARPConfig.CMake and executes it. YARPConfig.cmake creates the entries YARP_LIBRARIES, YARP_INCLUDES and YARP_DEFINES which are already processed so that projects added later will use them: