Getting started » Extras library usage with CMake

Guide how to find and use Magnum Extras with CMake build system.

The logic is in module FindMagnumExtras.cmake distributed in extras repository in modules/ directory, you are encouraged to copy it into your project and add path to the files to CMAKE_MODULE_PATH. Otherwise, if CMake won't be able to find this file in predefined locations, it will error out even if Magnum Extras libraries might be installed on the system.

Note that the module file is updated as the library evolves, you are encouraged to update your copy from time to time to avoid strange building issues.

If you installed the library or its dependencies to non-standard location (other than /usr, e.g. /home/xyz/projects), set CMAKE_PREFIX_PATH to that directory to help CMake find it. You can enter more different dirs if you separate them with semicolons.

Basic usage is:

find_package(MagnumExtras REQUIRED)

This command tries to find Magnum extras and then defines:

  • MagnumExtras_FOUND — Whether Magnum extras were found

This command alone is useless without specifying the components:

  • UiUi library

Besides libraries, the following apps are available:

Note that each namespace contains more detailed information about dependencies, availability on particular platform and also guide how to enable given library in build and use it with CMake.

Example usage with specifying additional components is:

find_package(MagnumExtras REQUIRED Ui)

For each component is then defined:

  • MagnumExtras_*_FOUND — Whether the component was found
  • MagnumExtras::* — Component imported target

The package is found if either debug or release version of each requested library is found. If both debug and release libraries are found, proper version is chosen based on actual build configuration of the project (i.e. Debug build is linked to debug libraries, Release build to release libraries).

See also Magnum usage with CMake for more information.

Other CMake modules

See relevant section for the main Magnum project.