# Integrating ROOT into CMake projects

You can integrate ROOT into a CMake based project.
The main interface is the CMake command find_package(…), which defines the following standard variables:

Variable Type Description
ROOT_INCLUDE_DIRS PATH Include directories for the ROOT installation.
ROOT_LIBRARIES LIST Libraries to link against. The actual list of libraries is composed using the COMPONENTS listed in the find_package(…) command.
ROOT_DEFINITIONS STRING Compile definitions needed to use ROOT.
ROOT_CXX_FLAGS STRING C++ compiler flags used to build ROOT.
ROOT_CC_FLAGS STRING C compiler flags used to build ROOT.
ROOT_<library>_LIBRARY PATH Full path for each of the ROOT libraries listed in COMPONENTS.
ROOT_<command>_CMD PATH Full path for each ROOT executable (rootcling, root, hadd, etc.).
ROOT_<option>_FOUND BOOL TRUE for each enabled build option (e.g. cocoa, python, xrootd, etc.).
ROOT_FOUND BOOL TRUE if the ROOT package has been found.
ROOT_USE_FILE PATH Path to a CMake module, which makes use of the previous variables and loads modules with useful macros or functions such as ROOT_GENERATE_DICTIONARY.

You can force additional ROOT libraries in the ROOT_LIBRARIES variable using the COMPONENTS option in the find_package(…) command. For example, to add the RooStats library, you can specify it as an extra component (the name of the component is the name of the library without any library prefix or suffix).

## Useful commands

ROOT provides a number of CMake macros/functions that are used internally but can also be used by projects layered on top of ROOT.

### ROOT_GENERATE_DICTIONARY

Generate dictionary for a set of header files (convenient wrapper on top of the rootcling command).

The ${dictionary}.cxx and ${dictionary}.pcm files are created using the header and the linkdef files, calling the rootcling command. Optionally, you can provide OPTIONS and MODULE to customize the way the rootcling command is called and the name for the .pcm files.

### REFLEX_GENERATE_DICTIONARY

Generate dictionary for a set of header files (convenient wrapper on top of the rootcling command).

The ${dictionary}.cxx and ${dictionary}.pcm files are created using the headers and the selection file, calling the genreflex command. Optionally, you can provide OPTIONS to customize the way the genreflex command is called.

## Full example (event project)

The following is an example of a project that creates a library including a dictionary and an executable file.