1# - Include the OpenSceneGraph runtime files in an installation or built package.
2#
3#  OSGRUNTIME_BUNDLE - Set to "yes" to enable this behavior
4#  OSGRUNTIME_zlib1dll - Must be set to the location of zlib1.dll on Windows
5#  OSGRUNTIME_zlib1ddll - Can be set to the location of zlib1d.dll (debug) on Windows.
6#                         If set, will be installed.
7#
8# Requires these CMake modules:
9#  no additional modules required
10#
11# Original Author:
12# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
13# http://academic.cleardefinition.com
14# Iowa State University HCI Graduate Program/VRAC
15#
16# Copyright Iowa State University 2009-2010.
17# Distributed under the Boost Software License, Version 1.0.
18# (See accompanying file LICENSE_1_0.txt or copy at
19# http://www.boost.org/LICENSE_1_0.txt)
20
21function(_osgbundle_split_debug_versions releasevar debugvar)
22	set(release)
23	set(debug)
24	foreach(fn ${ARGN})
25		get_filename_component(name "${fn}" NAME_WE)
26		if(${name} MATCHES "d$")
27			list(APPEND debug "${fn}")
28		else()
29			list(APPEND release "${fn}")
30		endif()
31	endforeach()
32	set(${releasevar} ${release} PARENT_SCOPE)
33	set(${debugvar} ${debug} PARENT_SCOPE)
34endfunction()
35
36function(_osgbundle_find_plugins varprefix filenameprefix)
37	file(GLOB
38		all
39		"${OSG_RUNTIME_LIBRARY_DIR}/osgPlugins-${OPENSCENEGRAPH_VERSION}/${filenameprefix}*${CMAKE_SHARED_LIBRARY_SUFFIX}")
40	_osgbundle_split_debug_versions(${varprefix}_PLUGINS_RELEASE
41		${varprefix}_PLUGINS_DEBUG
42		${all})
43endfunction()
44
45if(OPENSCENEGRAPH_FOUND)
46	if(WIN32)
47		get_filename_component(_osglibdir "${OSG_LIBRARY}" PATH)
48		get_filename_component(_osgroot "${_osglibdir}/.." ABSOLUTE)
49		set(OSG_RUNTIME_LIBRARY_DIR "${_osgroot}/bin")
50		find_file(OSGBUNDLE_zlib1dll
51			zlib1.dll
52			PATHS
53			"${_osgroot}/bin"
54			"${_osgroot}/lib")
55		find_file(OSGBUNDLE_zlib1ddll
56			zlib1d.dll
57			PATHS
58			"${_osgroot}/bin"
59			"${_osgroot}/lib")
60		mark_as_advanced(OSGBUNDLE_zlib1dll OSGBUNDLE_zlib1ddll)
61		set(_osgbundle_required OSGBUNDLE_zlib1dll)
62		set(_osgbundle_platformOK on)
63	else()
64		get_filename_component(_osglibdir "${OSG_LIBRARY}" PATH)
65		set(OSG_RUNTIME_LIBRARY_DIR "${_osglibdir}")
66		set(_osgbundle_platformOK on)
67	endif()
68
69	# Find the osgDB plugins
70
71	_osgbundle_find_plugins(OSGDB osgdb)
72	_osgbundle_find_plugins(OSGWRAPPER osgwrapper)
73endif()
74
75
76
77if(_osgbundle_platformOK)
78	set(_osgbundle_caninstall on)
79	foreach(_var ${_osgbundle_required})
80		if(NOT ${_var})
81			# If we are missing a single required file, cut out now.
82			set(_osgbundle_caninstall off)
83			option(OSGRUNTIME_BUNDLE
84				"Install a local copy of the OpenSceneGraph runtime files with the project."
85				off)
86		endif()
87	endforeach()
88	if(_osgbundle_caninstall)
89		option(OSGRUNTIME_BUNDLE
90			"Install a local copy of the OpenSceneGraph runtime files with the project."
91			on)
92	endif()
93endif()
94
95mark_as_advanced(OSGRUNTIME_BUNDLE)
96
97if(OSGRUNTIME_BUNDLE AND OPENSCENEGRAPH_FOUND AND _osgbundle_caninstall)
98	if(WIN32)
99		set(DESTINATION bin)
100		install(FILES "${OSGBUNDLE_zlib1dll}"
101			DESTINATION ${DESTINATION})
102
103		if(OSGBUNDLE_zlib1ddll)
104			install(FILES "${OSGBUNDLE_zlib1ddll}"
105				DESTINATION ${DESTINATION})
106		endif()
107
108	else()
109		set(DESTINATION lib)
110	endif()
111
112	install(DIRECTORY "${_osgroot}/bin/" "${_osgroot}/lib/"
113		DESTINATION ${DESTINATION}
114		FILES_MATCHING
115
116		# Runtime files
117		PATTERN "*${CMAKE_SHARED_LIBRARY_SUFFIX}")
118endif()
119