FindOpenSceneGraph — CMake 4.3.0 Documentation

# FindOpenSceneGraph

Finds OpenSceneGraph (OSG), a 3D graphics application programming interface:

    find_package(OpenSceneGraph [<version>] [COMPONENTS <components>...] [...])

Note

OpenSceneGraph development has largely transitioned to its successor project, VulkanSceneGraph, which should be preferred for new code. Refer to the upstream documentation for guidance on using VulkanSceneGraph with CMake.

This module searches for the OpenSceneGraph core osg library, its dependency OpenThreads, and additional OpenSceneGraph libraries, some of which are also known as NodeKits, if specified.

When working with OpenSceneGraph, its core library headers are intended to be included in C++ project source code as:

`example.cxx`

    #include <osg/PositionAttitudeTransform>

Headers for the OpenSceneGraph libraries and NodeKits follow a similar inclusion structure, for example:

`example.cxx`

    #include <osgAnimation/Animation>
    #include <osgDB/DatabasePager>
    #include <osgFX/BumpMapping>
    // ...

## Components

OpenSceneGraph toolkit consists of the core library osg, and additional libraries, which can be optionally specified as components with the `find_package()` command:

    find_package(OpenSceneGraph [COMPONENTS <components>...])

Supported components include:

`osg`

  Finds the core osg library (`libosg`), required to use OpenSceneGraph. This component is always automatically implied.

`OpenThreads`

  Finds the dependent OpenThreads library (`libOpenThreads`) via the `FindOpenThreads` module. This component is always automatically implied as it is required to use OpenSceneGraph.

`osgAnimation`

  Finds the osgAnimation library, which provides general purpose utility classes for animation.

`osgDB`

  Finds the osgDB library for reading and writing scene graphs support.

`osgFX`

  Finds the osgFX NodeKit, which provides a framework for implementing special effects.

`osgGA`

  Finds the osgGA (GUI Abstraction) library, which provides facilities to work with varying window systems.

`osgIntrospection`

  Finds the osgIntrospection library, which provides a reflection framework for accessing and invoking class properties and methods at runtime without modifying the classes.

  Note

  The osgIntrospection library has been removed from the OpenSceneGraph toolkit as of OpenSceneGraph version 3.0.

`osgManipulator`

  Finds the osgManipulator NodeKit, which provides support for 3D interactive manipulators.

`osgParticle`

  Finds the osgParticle NodeKit, which provides support for particle effects.

`osgPresentation`

  Finds the osgPresentation NodeKit, which provides support for 3D scene graph based presentations.

  Note

  This NodeKit has been added in OpenSceneGraph 3.0.0.

`osgProducer`

  Finds the osgProducer utility library, which provides functionality for window management and event handling.

  Note

  The osgProducer has been removed from early versions of OpenSceneGraph toolkit 1.x, and has been superseded by the osgViewer library.

`osgQt`

  Finds the osgQt utility library, which provides various classes to aid the integration of Qt.

  Note

  As of OpenSceneGraph version 3.6, this library has been moved to its own repository.

`osgShadow`

  Finds the osgShadow NodeKit, which provides support for a range of shadow techniques.

`osgSim`

  Finds the osgSim NodeKit, which adds support for simulation features like navigation lights and OpenFlight-style movement controls.

`osgTerrain`

  Finds the osgTerrain NodeKit, which provides geospecifc terrain rendering support.

`osgText`

  Finds the osgText NodeKit, which provides high quality text support.

`osgUtil`

  Finds the osgUtil library, which provides general-purpose utilities like update, cull, and draw traversals, as well as scene graph tools such as optimization, triangle stripping, and tessellation.

`osgViewer`

  Finds the osgViewer library, which provides high level viewer functionality.

`osgVolume`

  Finds the osgVolume NodeKit, which provides volume rendering support.

`osgWidget`

  Finds the osgWidget NodeKit, which provides support for 2D and 3D GUI widget sets.

If no components are specified, this module searches for the `osg` and `OpenThreads` components by default.

## Result Variables

This module defines the following variables:

`OpenSceneGraph_FOUND`

  Added in version 3.3.

  Boolean indicating whether (the requested version of) OpenSceneGraph with all specified components was found.

`OpenSceneGraph_VERSION`

  Added in version 4.2.

  The version of OpenSceneGraph found.

`OPENSCENEGRAPH_INCLUDE_DIRS`

  Include directories containing headers needed to use OpenSceneGraph.

`OPENSCENEGRAPH_LIBRARIES`

  Libraries needed to link against to use OpenSceneGraph.

## Hints

This module accepts the following variables:

`OpenSceneGraph_DEBUG`

  Set this variable to boolean true to enable debugging output by this module.

`OpenSceneGraph_MARK_AS_ADVANCED`

  Set this variable to boolean true to mark cache variables of this module as advanced automatically.

To help this module find OpenSceneGraph and its various components installed in custom location, `CMAKE_PREFIX_PATH` variable can be used. Additionally, the following variables are also respected:

`<COMPONENT>_DIR`

  Environment or CMake variable that can be set to the root of the OSG common installation, where `<COMPONENT>` is the uppercase form of component listed above. For example, `OSGVOLUME_DIR` to find the `osgVolume` component.

`OSG_DIR`

  Environment or CMake variable that can be set to influence detection of OpenSceneGraph installation root location as a whole.

`OSGDIR`

  Environment variable treated the same as `OSG_DIR`.

`OSG_ROOT`

  Environment variable treated the same as `OSG_DIR`.

## Deprecated Variables

The following variables are provided for backward compatibility:

`OPENSCENEGRAPH_FOUND`

  Deprecated since version 4.2: Use `OpenSceneGraph_FOUND`, which has the same value.

  Boolean indicating whether (the requested version of) OpenSceneGraph with all specified components was found.

`OPENSCENEGRAPH_VERSION`

  Deprecated since version 4.2: Superseded by the `OpenSceneGraph_VERSION`.

  The version of OpenSceneGraph found.

## Examples

Finding the OpenSceneGraph with `osgDB` and `osgUtil` libraries specified as components and creating an interface imported target that encapsulates its usage requirements for linking to a project target:

    find_package(OpenSceneGraph 2.0.0 REQUIRED COMPONENTS osgDB osgUtil)

    if(OpenSceneGraph_FOUND AND NOT TARGET OpenSceneGraph::OpenSceneGraph)
      add_library(OpenSceneGraph::OpenSceneGraph INTERFACE IMPORTED)
      set_target_properties(
        OpenSceneGraph::OpenSceneGraph
        PROPERTIES
          INTERFACE_INCLUDE_DIRECTORIES "${OPENSCENEGRAPH_INCLUDE_DIRS}"
          INTERFACE_LINK_LIBRARIES "${OPENSCENEGRAPH_LIBRARIES}"
      )
    endif()

    add_executable(example example.cxx)

    target_link_libraries(example PRIVATE OpenSceneGraph::OpenSceneGraph)

## See Also

The following OpenSceneGraph-related helper find modules are used internally by this module when finding specific OpenSceneGraph components. These modules are not intended to be included or invoked directly by project code during typical use of `find_package(OpenSceneGraph)`. However, they can be useful for advanced scenarios where finer control over component detection is needed. For example, to find them explicitly and override or bypass detection of specific OpenSceneGraph components:

- The `Findosg` module to find the core osg library.

- The `FindosgAnimation` module to find osgAnimation.

- The `FindosgDB` module to find osgDB.

- The `FindosgFX` module to find osgDB.

- The `FindosgGA` module to find osgGA.

- The `FindosgIntrospection` module to find osgIntrospection.

- The `FindosgManipulator` module to find osgManipulator.

- The `FindosgParticle` module to find osgParticle.

- The `FindosgPresentation` module to find osgPresentation.

- The `FindosgProducer` module to find osgProducer.

- The `FindosgQt` module to find osgQt.

- The `FindosgShadow` module to find osgShadow.

- The `FindosgSim` module to find osgSim.

- The `FindosgTerrain` module to find osgTerrain.

- The `FindosgText` module to find osgText.

- The `FindosgUtil` module to find osgUtil.

- The `FindosgViewer` module to find osgViewer.

- The `FindosgVolume` module to find osgVolume.

- The `FindosgWidget` module to find osgWidget.