Getting started » Integration library usage with CMake

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

The logic is in module FindMagnumIntegration.cmake distributed in integration 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 integration 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(MagnumIntegration REQUIRED)

This command tries to find Magnum integration library and then defines:

  • MagnumIntegration_FOUND — Whether the library was found

This command alone is useless without specifying the components:

Note that each *Integration 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(MagnumIntegration REQUIRED Bullet)

For each component is then defined:

  • MagnumIntegration_*_FOUND — Whether the component was found
  • MagnumIntegration::* — 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).

Workflows without imported targets are deprecated and the following variables are included just for backwards compatibility and only if MAGNUM_BUILD_DEPRECATED is enabled:

  • MAGNUM_*INTEGRATION_LIBRARIES — Expands to MagnumIntegration::* target. Use MagnumIntegration::* target directly instead.

See also Magnum usage with CMake for more information.

Other CMake modules

The modules/ directory contains more useful CMake modules:

  • FindOVR.cmake — CMake module for finding the OVR SDK. Copy this to your module directory if you want to use the OvrIntegration library.

See also relevant section for the main Magnum project.