1# - try to find VR Juggler-related packages (combined finder)
2#  VRJUGGLER_INCLUDE_DIRS, include search paths
3#  VRJUGGLER_LIBRARIES, the libraries to link against
4#  VRJUGGLER_ENVIRONMENT
5#  VRJUGGLER_RUNTIME_LIBRARY_DIRS
6#  VRJUGGLER_CXX_FLAGS
7#  VRJUGGLER_DEFINITIONS
8#  VRJUGGLER_FOUND, If false, do not try to use VR Juggler.
9#
10# Components available to search for (uses "VRJOGL" by default):
11#  VRJOGL
12#  VRJ
13#  Gadgeteer
14#  JCCL
15#  VPR
16#  Sonix
17#  Tweek
18#
19# Additionally, a full setup requires these packages and their Find_.cmake scripts
20#  CPPDOM
21#  GMTL
22#
23# Optionally uses Flagpoll (and FindFlagpoll.cmake)
24#
25# Notes on components:
26#  - All components automatically include their dependencies.
27#  - If you do not specify a component, VRJOGL (the OpenGL view manager)
28#    will be used by default.
29#  - Capitalization of component names does not matter, but it's best to
30#    pretend it does and use the above capitalization.
31#  - Since this script calls find_package for your requested components and
32#    their dependencies, you can use any of the variables specified in those
33#    files in addition to the "summary" ones listed here, for more finely
34#    controlled building and linking.
35#
36# This CMake script requires all of the Find*.cmake scripts for the
37# components listed above, as it is only a "meta-script" designed to make
38# using those scripts more developer-friendly.
39#
40# Useful configuration variables you might want to add to your cache:
41#  (CAPS COMPONENT NAME)_ROOT_DIR - A directory prefix to search
42#                         (a path that contains include/ as a subdirectory)
43#
44# The VJ_BASE_DIR environment variable is also searched (preferentially)
45# when seeking any of the above components, as well as Flagpoll, CPPDOM,
46# and Boost (from within VPR), so most sane build environments should
47# "just work."
48#
49# IMPORTANT: Note that you need to manually re-run CMake if you change
50# this environment variable, because it cannot auto-detect this change
51# and trigger an automatic re-run.
52#
53# Original Author:
54# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
55# http://academic.cleardefinition.com
56# Iowa State University HCI Graduate Program/VRAC
57# Updated for VR Juggler 3.0 by:
58# Brandon Newendorp <brandon@newendorp.com>
59#
60# Copyright Iowa State University 2009-2010.
61# Distributed under the Boost Software License, Version 1.0.
62# (See accompanying file LICENSE_1_0.txt or copy at
63# http://www.boost.org/LICENSE_1_0.txt)
64
65include(CleanLibraryList)
66include(CleanDirectoryList)
67include(FindPackageMessage)
68
69if(NOT VRJUGGLER_ROOT_DIR)
70	file(TO_CMAKE_PATH "$ENV{VJ_BASE_DIR}" VRJUGGLER_ROOT_DIR)
71endif()
72
73set(VRJUGGLER_ROOT_DIR
74	"${VRJUGGLER_ROOT_DIR}"
75	CACHE
76	PATH
77	"Additional root directory to search for VR Juggler and its dependencies.")
78if(NOT VRJUGGLER_ROOT_DIR)
79	file(TO_CMAKE_PATH "$ENV{VJ_BASE_DIR}" VRJUGGLER30_ROOT_DIR)
80endif()
81
82# Default required components
83if(NOT VRJuggler_FIND_COMPONENTS)
84	set(VRJuggler_FIND_COMPONENTS vrjogl)
85endif()
86
87if(VRJuggler30_FIND_QUIETLY)
88	set(_FIND_FLAGS "QUIET")
89else()
90	set(_FIND_FLAGS "")
91endif()
92
93set(VRJUGGLER_FIND_22 TRUE)
94set(VRJUGGLER_FIND_30 TRUE)
95if(VRJuggler_FIND_VERSION)
96	if(VRJuggler_FIND_VERSION_EXACT)
97		if(VRJuggler_FIND_VERSION MATCHES "2.2" OR VRJuggler_FIND_VERSION MATCHES "22")
98			set(VRJUGGLER_FIND_30 FALSE)
99		elseif(VRJuggler_FIND_VERSION MATCHES "3.0" OR VRJuggler_FIND_VERSION MATCHES "30")
100			set(VRJUGGLER_FIND_22 FALSE)
101		endif()
102	else()
103		if(VRJuggler_FIND_VERSION MATCHES "3.0" OR VRJuggler_FIND_VERSION MATCHES "30")
104			set(VRJUGGLER_FIND_22 FALSE)
105		endif()
106	endif()
107endif()
108
109if(VRJUGGLER_FIND_30)
110	if(NOT VRJUGGLER30_ROOT_DIR)
111		set(VRJUGGLER30_ROOT_DIR ${VRJUGGLER_ROOT_DIR})
112	endif()
113	find_package(VRJuggler30 COMPONENTS ${VRJuggler_FIND_COMPONENTS})
114	if(VRJUGGLER30_FOUND)
115		set(VRJUGGLER_FOUND TRUE)
116
117		set(VRJUGGLER_LIBRARIES ${VRJUGGLER30_LIBRARIES})
118		set(VRJUGGLER_INCLUDE_DIRS ${VRJUGGLER30_INCLUDE_DIRS})
119		set(VRJUGGLER_LIBRARY_DIRS ${VRJUGGLER30_LIBRARY_DIRS})
120
121		set(VRJUGGLER_ENVIRONMENT ${VRJUGGLER30_ENVIRONMENT})
122		set(VRJUGGLER_RUNTIME_LIBRARY_DIRS ${VRJUGGLER30_RUNTIME_LIBRARY_DIRS})
123
124		set(VRJUGGLER_CXX_FLAGS ${VRJUGGLER30_CXX_FLAGS})
125		set(VRJUGGLER_DEFINITIONS ${VRJUGGLER30_DEFINITIONS})
126		set(VRJUGGLER_BUNDLE_PLUGINS ${VRJUGGLER30_BUNDLE_PLUGINS})
127		set(VRJUGGLER_VJ_BASE_DIR ${VRJUGGLER30_VJ_BASE_DIR})
128		set(VRJUGGLER_VERSION 3.0)
129
130		macro(install_vrjuggler_data_files prefix)
131			install_vrjuggler30_data_files("${prefix}" ${ARGN})
132		endmacro()
133
134		macro(install_vrjuggler_plugins prefix varForFilenames)
135			install_vrjuggler30_plugins("${prefix}" ${varForFilenames} ${ARGN})
136		endmacro()
137	endif()
138endif()
139
140if(VRJUGGLER_FIND_22 AND (NOT VRJUGGLER_FOUND))
141
142	if(NOT VRJUGGLER22_ROOT_DIR)
143		set(VRJUGGLER22_ROOT_DIR ${VRJUGGLER_ROOT_DIR})
144	endif()
145	find_package(VRJuggler22 COMPONENTS ${VRJuggler_FIND_COMPONENTS})
146	if(VRJUGGLER22_FOUND)
147		set(VRJUGGLER_FOUND TRUE)
148
149		set(VRJUGGLER_LIBRARIES ${VRJUGGLER22_LIBRARIES})
150		set(VRJUGGLER_INCLUDE_DIRS ${VRJUGGLER22_INCLUDE_DIRS})
151		set(VRJUGGLER_LIBRARY_DIRS ${VRJUGGLER22_LIBRARY_DIRS})
152
153		set(VRJUGGLER_ENVIRONMENT ${VRJUGGLER22_ENVIRONMENT})
154		set(VRJUGGLER_RUNTIME_LIBRARY_DIRS ${VRJUGGLER22_RUNTIME_LIBRARY_DIRS})
155
156		set(VRJUGGLER_CXX_FLAGS ${VRJUGGLER22_CXX_FLAGS})
157		set(VRJUGGLER_DEFINITIONS ${VRJUGGLER22_DEFINITIONS})
158		set(VRJUGGLER_BUNDLE_PLUGINS ${VRJUGGLER22_BUNDLE_PLUGINS})
159		set(VRJUGGLER_VJ_BASE_DIR ${VRJUGGLER22_VJ_BASE_DIR})
160		set(VRJUGGLER_VERSION 2.2)
161
162		macro(install_vrjuggler_data_files prefix)
163			install_vrjuggler22_data_files("${prefix}" ${ARGN})
164		endmacro()
165
166		macro(install_vrjuggler_plugins prefix varForFilenames)
167			install_vrjuggler22_plugins("${prefix}" ${varForFilenames} ${ARGN})
168		endmacro()
169	endif()
170endif()
171
172include(FindPackageHandleStandardArgs)
173find_package_handle_standard_args(VRJuggler
174	REQUIRED_VARS
175	VRJUGGLER_LIBRARIES
176	VERSION_VAR
177	VRJUGGLER_VERSION)
178
179if(VRJUGGLER_FOUND)
180	mark_as_advanced(VRJUGGLER_ROOT_DIR)
181
182	# Set generic component variables, like VPR_LIBRARIES
183	if(VRJUGGLER_VERSION VERSION_EQUAL 2.2)
184		set(_components VRJ22 VRJOGL22 VPR20 TWEEK12 SONIX12 JCCL12)
185	else()
186		set(_components VRJ30 VRJOGL30 VPR22 TWEEK14 SONIX14 JCCL14)
187	endif()
188
189	foreach(comp ${_components})
190		string(LENGTH "${comp}" len)
191		math(EXPR complen "${len} - 2")
192		string(SUBSTRING "${comp}" 0 ${complen} compshort)
193		set(${compshort}_LIBRARIES ${${comp}_LIBRARIES})
194		set(${compshort}_INCLUDE_DIRS ${${comp}_INCLUDE_DIRS})
195		set(${compshort}_LIBRARY_DIRS ${${comp}_LIBRARY_DIRS})
196		set(${compshort}_CXX_FLAGS ${${comp}_CXX_FLAGS})
197	endforeach()
198endif()
199