1 # - Find OpenSG 2 libraries
2 # Find the specified OpenSG 2 libraries and header files.
4 # Since OpenSG consists of a number of libraries you need to specify which
5 # of those you want to use. To do so, pass a list of their names after
6 # the COMPONENTS argument to FIND_PACKAGE. A typical call looks like this:
7 # FIND_PACKAGE(OpenSG REQUIRED COMPONENTS OSGBase OSGSystem OSGDrawable)
8 # OSG_OPTIONAL_COMPONENTS can be used to exclude optional components from
9 # the computation of OpenSG_FOUND
11 # This module specifies the following variables:
16 # For each component COMP the capitalized name (e.g. OSGBASE, OSGSYSTEM):
17 # OpenSG_${COMP}_LIBRARY
18 # OpenSG_${COMP}_LIBRARY_RELEASE
19 # OpenSG_${COMP}_LIBRARY_DEBUG
21 # You can control where this module attempts to locate libraries and headers:
22 # you can use the following input variables:
23 # OPENSG_ROOT root of an installed OpenSG with include/OpenSG and lib below it
24 # OPENSG_INCLUDE_DIR header directory
25 # OPENSG_LIBRARY_DIR library directory
27 # OpenSG_DIR is what is automaticall added by cmake
28 IF(NOT OPENSG_ROOT AND OpenSG_DIR)
29 SET(OPENSG_ROOT ${OpenSG_DIR})
30 ENDIF(NOT OPENSG_ROOT AND OpenSG_DIR)
32 IF(NOT OSG_FORCE_CACHE_UPDATE)
33 SET(__OpenSG_IN_CACHE TRUE)
34 IF(OpenSG_INCLUDE_DIR)
35 FOREACH(COMPONENT ${OpenSG_FIND_COMPONENTS})
36 STRING(TOUPPER ${COMPONENT} COMPONENT)
37 IF(NOT OpenSG_${COMPONENT}_FOUND)
38 SET(__OpenSG_IN_CACHE FALSE)
39 ENDIF(NOT OpenSG_${COMPONENT}_FOUND)
41 ELSE(OpenSG_INCLUDE_DIR)
42 SET(__OpenSG_IN_CACHE FALSE)
43 ENDIF(OpenSG_INCLUDE_DIR)
44 ENDIF(NOT OSG_FORCE_CACHE_UPDATE)
46 # The reason that we failed to find OpenSG. This will be set to a
47 # user-friendly message when we fail to find some necessary piece of
49 set(OpenSG_ERROR_REASON)
51 SET(__OSG_LIBDIR_SUFFIX "")
53 IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
54 SET(__OSG_LIBDIR_SUFFIX "64")
57 ############################################
59 # Check the existence of the libraries.
61 ############################################
62 # This macro is directly taken from FindBoost.cmake that comes with the cmake
63 # distribution. It is NOT my work, only minor modifications have been made to
64 # remove references to boost.
65 #########################################################################
67 MACRO(__OpenSG_ADJUST_LIB_VARS basename component)
68 IF(OpenSG_INCLUDE_DIR)
70 IF(OpenSG_${basename}_LIBRARY_DEBUG AND OpenSG_${basename}_LIBRARY_RELEASE)
71 # if the generator supports configuration types then set
72 # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
73 IF (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
74 SET(OpenSG_${basename}_LIBRARY optimized ${OpenSG_${basename}_LIBRARY_RELEASE} debug ${OpenSG_${basename}_LIBRARY_DEBUG})
75 ELSE(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
76 # if there are no configuration types and CMAKE_BUILD_TYPE has no value
77 # then just use the release libraries
78 SET(OpenSG_${basename}_LIBRARY ${OpenSG_${basename}_LIBRARY_RELEASE} )
79 ENDIF(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
81 SET(OpenSG_${basename}_LIBRARIES optimized ${OpenSG_${basename}_LIBRARY_RELEASE} debug ${OpenSG_${basename}_LIBRARY_DEBUG})
82 ENDIF(OpenSG_${basename}_LIBRARY_DEBUG AND OpenSG_${basename}_LIBRARY_RELEASE)
84 # if only the release version was found, set the debug variable also to the release version
85 IF(OpenSG_${basename}_LIBRARY_RELEASE AND NOT OpenSG_${basename}_LIBRARY_DEBUG)
86 SET(OpenSG_${basename}_LIBRARY ${OpenSG_${basename}_LIBRARY_RELEASE})
87 SET(OpenSG_${basename}_LIBRARIES ${OpenSG_${basename}_LIBRARY_RELEASE})
88 ENDIF(OpenSG_${basename}_LIBRARY_RELEASE AND NOT OpenSG_${basename}_LIBRARY_DEBUG)
90 # if only the debug version was found, set the release variable also to the debug version
91 IF(OpenSG_${basename}_LIBRARY_DEBUG AND NOT OpenSG_${basename}_LIBRARY_RELEASE)
92 SET(OpenSG_${basename}_LIBRARY ${OpenSG_${basename}_LIBRARY_DEBUG})
93 SET(OpenSG_${basename}_LIBRARIES ${OpenSG_${basename}_LIBRARY_DEBUG})
94 ENDIF(OpenSG_${basename}_LIBRARY_DEBUG AND NOT OpenSG_${basename}_LIBRARY_RELEASE)
96 IF(OpenSG_${basename}_LIBRARY)
97 SET(OpenSG_${basename}_LIBRARY ${OpenSG_${basename}_LIBRARY} CACHE FILEPATH "The OpenSG ${basename} library")
98 GET_FILENAME_COMPONENT(OpenSG_LIBRARY_DIRS "${OpenSG_${basename}_LIBRARY}" PATH)
99 SET(OpenSG_LIBRARY_DIRS ${OpenSG_LIBRARY_DIRS} CACHE FILEPATH "OpenSG library directory")
100 SET(OpenSG_${basename}_FOUND ON CACHE INTERNAL "Whether the OpenSG ${basename} library found")
101 ENDIF(OpenSG_${basename}_LIBRARY)
103 IF(OpenSG_${basename}_LIBRARY_DEBUG OR OpenSG_${basename}_LIBRARY_DEBUGOPT OR
104 OpenSG_${basename}_LIBRARY_RELEASE OR OpenSG_${basename}_LIBRARY_RELEASENOOPT)
106 SET(OpenSG_${basename}_FOUND ON CACHE INTERNAL "Whether the OpenSG ${basename} library found")
108 SET(OpenSG_${basename}_LIBRARY ${component})
111 ENDIF(OpenSG_INCLUDE_DIR)
113 # Make variables changeble to the advanced user
115 OpenSG_${basename}_LIBRARY
116 OpenSG_${basename}_LIBRARY_RELEASE
117 OpenSG_${basename}_LIBRARY_DEBUG
119 ENDMACRO(__OpenSG_ADJUST_LIB_VARS)
122 FUNCTION(SETUP_OSG_LIB_TARGETS COMPONENT UPPERCOMPONENT)
124 ADD_LIBRARY(${COMPONENT} SHARED IMPORTED)
126 IF(OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASE)
128 GET_FILENAME_COMPONENT(OSG_TMP_LIB_DIR_OPT ${OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASE}
132 SET(OSG_IMP_RELEASE IMPORTED_LOCATION_RELEASE ${OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASE})
134 SET(OSG_IMP_RELEASE IMPORTED_IMPLIB_RELEASE ${OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASE}
135 IMPORTED_LOCATION_RELEASE ${OSG_TMP_LIB_DIR_OPT})
138 ENDIF(OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASE)
141 IF(OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASENOOPT)
143 GET_FILENAME_COMPONENT(OSG_TMP_LIB_DIR_OPT ${OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASENOOPT}
147 SET(OSG_IMP_RELEASENOOPT IMPORTED_LOCATION_RELEASENOOPT ${OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASENOOPT})
149 SET(OSG_IMP_RELEASENOOPT IMPORTED_IMPLIB_RELEASENOOPT ${OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASENOOPT}
150 IMPORTED_LOCATION_RELEASENOOPT ${OSG_TMP_LIB_DIR_OPT})
153 ENDIF(OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASENOOPT)
156 IF(OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUG)
158 GET_FILENAME_COMPONENT(OSG_TMP_LIB_DIR_DBG ${OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUG}
162 SET(OSG_IMP_DEBUG IMPORTED_LOCATION_DEBUG ${OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUG})
163 SET(OSG_IMP_DEBUG ${OSG_IMP_DEBUG} IMPORTED_LOCATION_DEBUGGV ${OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUG})
165 SET(OSG_IMP_DEBUG IMPORTED_IMPLIB_DEBUG ${OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUG}
166 IMPORTED_LOCATION_DEBUG ${OSG_TMP_LIB_DIR_DBG})
169 ENDIF(OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUG)
172 IF(OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUGOPT)
174 GET_FILENAME_COMPONENT(OSG_TMP_LIB_DIR_DBG ${OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUGOPT}
178 SET(OSG_IMP_DEBUGOPT IMPORTED_LOCATION_DEBUGOPT ${OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUGOPT})
179 SET(OSG_IMP_DEBUGOPT ${OSG_IMP_DEBUGOPT} IMPORTED_LOCATION_DEBUGOPTGV ${OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUGOPT})
181 SET(OSG_IMP_DEBUGOPT IMPORTED_IMPLIB_DEBUGOPT ${OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUGOPT}
182 IMPORTED_LOCATION_DEBUGOPT ${OSG_TMP_LIB_DIR_DBG})
185 ENDIF(OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUGOPT)
187 IF(OSG_IMP_RELEASE OR OSG_IMP_RELEASENOOPT OR OSG_IMP_DEBUG OR OSG_IMP_DEBUGOPT)
188 SET_TARGET_PROPERTIES(${COMPONENT} PROPERTIES
190 ${OSG_IMP_RELEASENOOPT}
192 ${OSG_IMP_DEBUGOPT} )
193 ENDIF(OSG_IMP_RELEASE OR OSG_IMP_RELEASENOOPT OR OSG_IMP_DEBUG OR OSG_IMP_DEBUGOPT)
195 ENDFUNCTION(SETUP_OSG_LIB_TARGETS)
197 #-------------------------------------------------------------------------------
200 IF(__OpenSG_IN_CACHE)
201 # values are already in the cache
203 SET(OpenSG_FOUND TRUE)
204 FOREACH(COMPONENT ${OpenSG_FIND_COMPONENTS})
205 STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
207 # avoid setting up componentes more than once - which is not
208 # allowed for import libraries
209 IF(NOT TARGET ${COMPONENT})
210 __OpenSG_ADJUST_LIB_VARS(${UPPERCOMPONENT} ${COMPONENT})
212 SET(OpenSG_LIBRARIES ${OpenSG_LIBRARIES} ${OpenSG_${UPPERCOMPONENT}_LIBRARY})
213 SETUP_OSG_LIB_TARGETS(${COMPONENT} ${UPPERCOMPONENT})
214 ENDIF(NOT TARGET ${COMPONENT})
215 ENDFOREACH(COMPONENT)
217 SET(OpenSG_INCLUDE_DIRS "${OpenSG_INCLUDE_DIR}" "${OpenSG_INCLUDE_DIR}/OpenSG")
219 ELSE(__OpenSG_IN_CACHE)
220 # need to search for libs
222 SET(__OpenSG_INCLUDE_SEARCH_DIRS
225 "$ENV{ProgramFiles}/OpenSG"
229 SET(__OpenSG_LIBRARIES_SEARCH_DIRS
232 "$ENV{ProgramFiles}/OpenSG"
236 # handle input variable OPENSG_ROOT
238 FILE(TO_CMAKE_PATH ${OPENSG_ROOT} OPENSG_ROOT)
239 SET(__OpenSG_INCLUDE_SEARCH_DIRS
240 ${OPENSG_ROOT}/include
242 ${__OpenSG_INCLUDE_SEARCH_DIRS})
244 SET(__OpenSG_LIBRARIES_SEARCH_DIRS
246 ${OPENSG_ROOT}/stage/lib
247 ${__OpenSG_LIBRARIES_SEARCH_DIRS})
249 IF(__OSG_LIBDIR_SUFFIX)
250 SET(__OpenSG_LIBRARIES_SEARCH_DIRS
251 ${OPENSG_ROOT}/lib${__OSG_LIBDIR_SUFFIX}
252 ${OPENSG_ROOT}/stage/lib${__OSG_LIBDIR_SUFFIX}
253 ${__OpenSG_LIBRARIES_SEARCH_DIRS})
257 # handle input variable OPENSG_INCLUDE_DIR
258 IF(OPENSG_INCLUDE_DIR)
259 FILE(TO_CMAKE_PATH ${OPENSG_INCLUDE_DIR} OPENSG_INCLUDE_DIR)
260 SET(__OpenSG_INCLUDE_SEARCH_DIRS
261 ${OPENSG_INCLUDE_DIR} ${__OpenSG_INCLUDE_SEARCH_DIRS})
262 ENDIF(OPENSG_INCLUDE_DIR)
264 # handle input variable OPENSG_LIBRARY_DIR
265 IF(OPENSG_LIBRARY_DIR)
266 FILE(TO_CMAKE_PATH ${OPENSG_LIBRARY_DIR} OPENSG_LIBRARY_DIR)
267 SET(__OpenSG_LIBRARIES_SEARCH_DIRS
268 ${OPENSG_LIBRARY_DIR} ${__OpenSG_LIBRARIES_SEARCH_DIRS})
269 ENDIF(OPENSG_LIBRARY_DIR)
272 IF(NOT OpenSG_INCLUDE_DIR)
273 # try to find include dirrectory by searching for OSGConfigured.h
275 FIND_PATH(OpenSG_INCLUDE_DIR
276 NAMES OpenSG/OSGConfigured.h
277 HINTS ${__OpenSG_INCLUDE_SEARCH_DIRS})
278 ENDIF(NOT OpenSG_INCLUDE_DIR)
280 # ------------------------------------------------------------------------
281 # Begin finding OpenSG libraries
282 # ------------------------------------------------------------------------
283 FOREACH(COMPONENT ${OpenSG_FIND_COMPONENTS})
284 STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
285 SET(OpenSG_${UPPERCOMPONENT}_LIBRARY "OpenSG_${UPPERCOMPONENT}_LIBRARY-NOTFOUND" )
286 SET(OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASE "OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASE-NOTFOUND" )
287 SET(OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUG "OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUG-NOTFOUND")
290 SET(OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASENOOPT "OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASENOOPT-NOTFOUND" )
291 SET(OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUGOPT "OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUGOPT-NOTFOUND")
294 FIND_LIBRARY(OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASE
296 HINTS ${__OpenSG_LIBRARIES_SEARCH_DIRS}
297 PATH_SUFFIXES "release" "rel" "opt" "relwithdbg"
301 FIND_LIBRARY(OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUG
302 NAMES "${COMPONENT}D"
303 HINTS ${__OpenSG_LIBRARIES_SEARCH_DIRS}
304 PATH_SUFFIXES "debug" "dbg" "debugopt"
307 FIND_LIBRARY(OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASENOOPT
308 NAMES "${COMPONENT}RN"
309 HINTS ${__OpenSG_LIBRARIES_SEARCH_DIRS}
310 PATH_SUFFIXES "relnoopt"
313 FIND_LIBRARY(OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUGOPT
314 NAMES "${COMPONENT}DO"
315 HINTS ${__OpenSG_LIBRARIES_SEARCH_DIRS}
316 PATH_SUFFIXES "debugopt"
319 FIND_LIBRARY(OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUG
321 HINTS ${__OpenSG_LIBRARIES_SEARCH_DIRS}
322 PATH_SUFFIXES "debug" "dbg"
326 __OpenSG_ADJUST_LIB_VARS(${UPPERCOMPONENT} ${COMPONENT})
328 ENDFOREACH(COMPONENT)
329 # ------------------------------------------------------------------------
330 # End finding OpenSG libraries
331 # ------------------------------------------------------------------------
333 SET(OpenSG_INCLUDE_DIRS "${OpenSG_INCLUDE_DIR}" "${OpenSG_INCLUDE_DIR}/OpenSG")
335 SET(OpenSG_FOUND FALSE)
337 IF(OpenSG_INCLUDE_DIR)
338 SET(OpenSG_FOUND TRUE)
340 # check if all requested components were found
341 SET(__OpenSG_CHECKED_COMPONENT FALSE)
342 SET(__OpenSG_MISSING_COMPONENTS)
344 FOREACH(_COMPONENT ${OpenSG_FIND_COMPONENTS})
345 STRING(TOUPPER ${_COMPONENT} COMPONENT)
346 SET(__OpenSG_CHECKED_COMPONENT TRUE)
348 IF(NOT OpenSG_${COMPONENT}_FOUND)
349 STRING(TOLOWER ${COMPONENT} COMPONENT)
350 LIST(APPEND __OpenSG_MISSING_COMPONENTS ${COMPONENT})
352 LIST(FIND OSG_OPTIONAL_COMPONENTS ${_COMPONENT} _CMP_OPTIONAL)
354 IF(_CMP_OPTIONAL EQUAL -1)
355 SET(OpenSG_FOUND FALSE)
357 ENDIF(NOT OpenSG_${COMPONENT}_FOUND)
358 ENDFOREACH(_COMPONENT)
360 IF(__OpenSG_MISSING_COMPONENTS)
361 # We were unable to find some libraries, so generate a sensible
362 # error message that lists the libraries we were unable to find.
363 SET(OpenSG_ERROR_REASON
364 "${OpenSG_ERROR_REASON}\nThe following OpenSG libraries could not be found:\n")
365 FOREACH(COMPONENT ${__OpenSG_MISSING_COMPONENTS})
366 SET(OpenSG_ERROR_REASON
367 "${OpenSG_ERROR_REASON} ${COMPONENT}\n")
368 ENDFOREACH(COMPONENT)
370 LIST(LENGTH OpenSG_FIND_COMPONENTS __OpenSG_NUM_COMPONENTS_WANTED)
371 LIST(LENGTH __OpenSG_MISSING_COMPONENTS __OpenSG_NUM_MISSING_COMPONENTS)
372 IF(${__OpenSG_NUM_COMPONENTS_WANTED} EQUAL ${__OpenSG_NUM_MISSING_COMPONENTS})
373 SET(OpenSG_ERROR_REASON
374 "${OpenSG_ERROR_REASON}No OpenSG libraries were found. You may need to set OPENSG_LIBRARY_DIR to the directory containing OpenSG libraries or OPENSG_ROOT to the location of OpenSG.")
375 ELSE(${__OpenSG_NUM_COMPONENTS_WANTED} EQUAL ${__OpenSG_NUM_MISSING_COMPONENTS})
376 SET(OpenSG_ERROR_REASON
377 "${OpenSG_ERROR_REASON}Some (but not all) of the required OpenSG libraries were found. You may need to install these additional OpenSG libraries. Alternatively, set OPENSG_LIBRARY_DIR to the directory containing OpenSG libraries or OPENSG_ROOT to the location of OpenSG.")
378 ENDIF(${__OpenSG_NUM_COMPONENTS_WANTED} EQUAL ${__OpenSG_NUM_MISSING_COMPONENTS})
379 ENDIF(__OpenSG_MISSING_COMPONENTS)
381 ENDIF(OpenSG_INCLUDE_DIR)
384 IF(NOT OpenSG_FIND_QUIETLY)
385 MESSAGE(STATUS "OpenSG found.")
386 ENDIF(NOT OpenSG_FIND_QUIETLY)
388 IF (NOT OpenSG_FIND_QUIETLY)
389 MESSAGE(STATUS "Found the following OpenSG libraries:")
390 ENDIF(NOT OpenSG_FIND_QUIETLY)
392 FOREACH(COMPONENT ${OpenSG_FIND_COMPONENTS})
393 STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
394 IF(OpenSG_${UPPERCOMPONENT}_FOUND)
395 IF(NOT OpenSG_FIND_QUIETLY)
396 MESSAGE(STATUS " ${COMPONENT}")
397 ENDIF(NOT OpenSG_FIND_QUIETLY)
399 SETUP_OSG_LIB_TARGETS(${COMPONENT} ${UPPERCOMPONENT})
401 SET(OpenSG_LIBRARIES ${OpenSG_LIBRARIES} ${OpenSG_${UPPERCOMPONENT}_LIBRARY})
402 ENDIF(OpenSG_${UPPERCOMPONENT}_FOUND)
403 ENDFOREACH(COMPONENT)
406 IF(OpenSG_FIND_REQUIRED)
407 MESSAGE(SEND_ERROR "Unable to find the requested OpenSG libraries.\n${OpenSG_ERROR_REASON}")
408 ENDIF(OpenSG_FIND_REQUIRED)
411 ENDIF(__OpenSG_IN_CACHE)