Extras library usage with CMake
Guide how to find and use Magnum Extras with CMake build system.
Using Magnum Extras that were externally built and installed
The main logic is in the FindMagnumExtras.cmake module distributed in the modules/
directory of the integration repository, you are encouraged to copy it into your project and add path to the files to CMAKE_MODULE_PATH
:
# Path where FindMagnumExtras.cmake can be found, adapt as needed set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/modules/" ${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 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.
Using Magnum Extras as a CMake subproject
Continuing from Using Magnum as a CMake subproject, adding Magnum Extras is very similar. Again, the Extras build-time options have to be specified before the subdirectory gets added:
... set(MAGNUM_WITH_UI ON CACHE BOOL "" FORCE) # enable what you need add_subdirectory(magnum-extras EXCLUDE_FROM_ALL) find_package(MagnumExtras REQUIRED ...) # see below
Each namespace provides further information about additional steps needed for a CMake subproject setup.
Finding the package and its components
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:
Ui
— Ui library
Besides libraries, the following apps are available:
player
— magnum-player executableui-gallery
— magnum-ui-gallery executable
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 foundMagnumExtras::*
— 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.