File: FindOpenSceneGraph.cmake

package info (click to toggle)
cmake 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 147,284 kB
  • sloc: ansic: 403,915; cpp: 290,772; sh: 4,102; python: 3,357; yacc: 3,106; lex: 1,189; f90: 532; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 230; perl: 217; objc: 215; xml: 198; makefile: 97; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (383 lines) | stat: -rw-r--r-- 13,754 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file LICENSE.rst or https://cmake.org/licensing for details.

#[=======================================================================[.rst:
FindOpenSceneGraph
------------------

Finds `OpenSceneGraph`_ (OSG), a 3D graphics application programming interface.

.. 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:

.. code-block:: c++
  :caption: ``example.cxx``

  #include <osg/PositionAttitudeTransform>

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

.. code-block:: c++
  :caption: ``example.cxx``

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

.. _`OpenSceneGraph`: https://openscenegraph.github.io/openscenegraph.io/

Components
^^^^^^^^^^

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

.. code-block:: cmake

  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
  :module:`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``
  Boolean indicating whether the (requested version of) OpenSceneGraph with all
  specified components is found.  For backward compatibility, the
  ``OPENSCENEGRAPH_FOUND`` variable is also set to the same value.

``OPENSCENEGRAPH_VERSION``
  The version of the OSG which was 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, :variable:`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``.

Examples
^^^^^^^^

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

.. code-block:: cmake

  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 :module:`Findosg` module to find the core osg library.
* The :module:`FindosgAnimation` module to find osgAnimation.
* The :module:`FindosgDB` module to find osgDB.
* The :module:`FindosgFX` module to find osgDB.
* The :module:`FindosgGA` module to find osgGA.
* The :module:`FindosgIntrospection` module to find osgIntrospection.
* The :module:`FindosgManipulator` module to find osgManipulator.
* The :module:`FindosgParticle` module to find osgParticle.
* The :module:`FindosgPresentation` module to find osgPresentation.
* The :module:`FindosgProducer` module to find osgProducer.
* The :module:`FindosgQt` module to find osgQt.
* The :module:`FindosgShadow` module to find osgShadow.
* The :module:`FindosgSim` module to find osgSim.
* The :module:`FindosgTerrain` module to find osgTerrain.
* The :module:`FindosgText` module to find osgText.
* The :module:`FindosgUtil` module to find osgUtil.
* The :module:`FindosgViewer` module to find osgViewer.
* The :module:`FindosgVolume` module to find osgVolume.
* The :module:`FindosgWidget` module to find osgWidget.
#]=======================================================================]

cmake_policy(PUSH)
cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>

include(${CMAKE_CURRENT_LIST_DIR}/Findosg_functions.cmake)

set(_osg_modules_to_process)
foreach(_osg_component ${OpenSceneGraph_FIND_COMPONENTS})
    list(APPEND _osg_modules_to_process ${_osg_component})
endforeach()
list(APPEND _osg_modules_to_process "osg" "OpenThreads")
list(REMOVE_DUPLICATES _osg_modules_to_process)

if(OpenSceneGraph_DEBUG)
    message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
        "Components = ${_osg_modules_to_process}")
endif()

#
# First we need to find and parse osg/Version
#
OSG_FIND_PATH(OSG osg/Version)
if(OpenSceneGraph_MARK_AS_ADVANCED)
    OSG_MARK_AS_ADVANCED(OSG)
endif()

# Try to ascertain the version...
if(OSG_INCLUDE_DIR)
    if(OpenSceneGraph_DEBUG)
        message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
            "Detected OSG_INCLUDE_DIR = ${OSG_INCLUDE_DIR}")
    endif()

    set(_osg_Version_file "${OSG_INCLUDE_DIR}/osg/Version")
    if("${OSG_INCLUDE_DIR}" MATCHES "\\.framework$" AND NOT EXISTS "${_osg_Version_file}")
        set(_osg_Version_file "${OSG_INCLUDE_DIR}/Headers/Version")
    endif()

    if(EXISTS "${_osg_Version_file}")
      file(STRINGS "${_osg_Version_file}" _osg_Version_contents
           REGEX "#define (OSG_VERSION_[A-Z]+|OPENSCENEGRAPH_[A-Z]+_VERSION)[ \t]+[0-9]+")
    else()
      set(_osg_Version_contents "unknown")
    endif()

    string(REGEX MATCH ".*#define OSG_VERSION_MAJOR[ \t]+[0-9]+.*"
        _osg_old_defines "${_osg_Version_contents}")
    string(REGEX MATCH ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+[0-9]+.*"
        _osg_new_defines "${_osg_Version_contents}")
    if(_osg_old_defines)
        string(REGEX REPLACE ".*#define OSG_VERSION_MAJOR[ \t]+([0-9]+).*"
            "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
        string(REGEX REPLACE ".*#define OSG_VERSION_MINOR[ \t]+([0-9]+).*"
            "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
        string(REGEX REPLACE ".*#define OSG_VERSION_PATCH[ \t]+([0-9]+).*"
            "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
    elseif(_osg_new_defines)
        string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MAJOR_VERSION[ \t]+([0-9]+).*"
            "\\1" _osg_VERSION_MAJOR ${_osg_Version_contents})
        string(REGEX REPLACE ".*#define OPENSCENEGRAPH_MINOR_VERSION[ \t]+([0-9]+).*"
            "\\1" _osg_VERSION_MINOR ${_osg_Version_contents})
        string(REGEX REPLACE ".*#define OPENSCENEGRAPH_PATCH_VERSION[ \t]+([0-9]+).*"
            "\\1" _osg_VERSION_PATCH ${_osg_Version_contents})
    else()
        message(WARNING "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
            "Failed to parse version number, please report this as a bug")
    endif()
    unset(_osg_Version_contents)

    set(OPENSCENEGRAPH_VERSION "${_osg_VERSION_MAJOR}.${_osg_VERSION_MINOR}.${_osg_VERSION_PATCH}"
                                CACHE INTERNAL "The version of OSG which was detected")
    if(OpenSceneGraph_DEBUG)
        message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
            "Detected version ${OPENSCENEGRAPH_VERSION}")
    endif()
endif()

set(_osg_quiet)
if(OpenSceneGraph_FIND_QUIETLY)
    set(_osg_quiet "QUIET")
endif()
#
# Here we call find_package() on all of the components
#
foreach(_osg_module ${_osg_modules_to_process})
    if(OpenSceneGraph_DEBUG)
        message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] "
            "Calling find_package(${_osg_module} ${_osg_required} ${_osg_quiet})")
    endif()
    find_package(${_osg_module} ${_osg_quiet})

    string(TOUPPER ${_osg_module} _osg_module_UC)
    # append to list if module was found OR is required
    if( ${_osg_module_UC}_FOUND OR OpenSceneGraph_FIND_REQUIRED )
      list(APPEND OPENSCENEGRAPH_INCLUDE_DIR ${${_osg_module_UC}_INCLUDE_DIR})
      list(APPEND OPENSCENEGRAPH_LIBRARIES ${${_osg_module_UC}_LIBRARIES})
    endif()

    if(OpenSceneGraph_MARK_AS_ADVANCED)
        OSG_MARK_AS_ADVANCED(${_osg_module})
    endif()
endforeach()

if(OPENSCENEGRAPH_INCLUDE_DIR)
    list(REMOVE_DUPLICATES OPENSCENEGRAPH_INCLUDE_DIR)
endif()

#
# Check each module to see if it's found
#
set(_osg_component_founds)
if(OpenSceneGraph_FIND_REQUIRED)
    foreach(_osg_module ${_osg_modules_to_process})
        string(TOUPPER ${_osg_module} _osg_module_UC)
        list(APPEND _osg_component_founds ${_osg_module_UC}_FOUND)
    endforeach()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenSceneGraph
                                  REQUIRED_VARS OPENSCENEGRAPH_LIBRARIES OPENSCENEGRAPH_INCLUDE_DIR ${_osg_component_founds}
                                  VERSION_VAR OPENSCENEGRAPH_VERSION)

unset(_osg_component_founds)

set(OPENSCENEGRAPH_INCLUDE_DIRS ${OPENSCENEGRAPH_INCLUDE_DIR})

cmake_policy(POP)