]> git.mxchange.org Git - flightgear.git/blob - CMakeModules/FindPLIB.cmake
fgviewer: Update to current initialization structure.
[flightgear.git] / CMakeModules / FindPLIB.cmake
1 # Locate PLIB
2 # This module defines
3 # PLIB_LIBRARIES
4 # PLIB_FOUND, if false, do not try to link to PLIB 
5 # PLIB_INCLUDE_DIR, where to find the headers
6 #
7 # $PLIBDIR is an environment variable that would
8 # correspond to the ./configure --prefix=$PLIBDIR
9 # used in building PLIB.
10 #
11 # Created by James Turner. This was influenced by the FindOpenAL.cmake module.
12
13 #=============================================================================
14 # Copyright 2005-2009 Kitware, Inc.
15 #
16 # Distributed under the OSI-approved BSD License (the "License");
17 # see accompanying file Copyright.txt for details.
18 #
19 # This software is distributed WITHOUT ANY WARRANTY; without even the
20 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 # See the License for more information.
22 #=============================================================================
23 # (To distributed this file outside of CMake, substitute the full
24 #  License text for the above reference.)
25
26 # Per my request, CMake should search for frameworks first in
27 # the following order:
28 # ~/Library/Frameworks/OpenAL.framework/Headers
29 # /Library/Frameworks/OpenAL.framework/Headers
30 # /System/Library/Frameworks/OpenAL.framework/Headers
31 #
32 # On OS X, this will prefer the Framework version (if found) over others.
33 # People will have to manually change the cache values of 
34 # OPENAL_LIBRARY to override this selection or set the CMake environment
35 # CMAKE_INCLUDE_PATH to modify the search paths.
36
37 include(SelectLibraryConfigurations)
38
39 set(save_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
40 set(CMAKE_FIND_FRAMEWORK ONLY)
41 FIND_PATH(PLIB_INCLUDE_DIR ul.h
42   PATH_SUFFIXES include/plib include 
43   PATHS
44   ~/Library/Frameworks
45   /Library/Frameworks
46 )
47 set(CMAKE_FIND_FRAMEWORK ${save_FIND_FRAMEWORK})
48
49 if(NOT PLIB_INCLUDE_DIR)
50     FIND_PATH(PLIB_INCLUDE_DIR plib/ul.h
51       PATH_SUFFIXES include 
52       HINTS $ENV{PLIBDIR}
53       PATHS
54       /usr/local
55       /opt/local
56       /usr
57     )
58 endif()
59
60 message(STATUS ${PLIB_INCLUDE_DIR})
61
62 # check for dynamic framework on Mac ()
63 FIND_LIBRARY(PLIB_LIBRARIES
64   NAMES plib PLIB
65   HINTS
66   $ENV{PLIBDIR}
67   PATHS
68   ~/Library/Frameworks
69   /Library/Frameworks
70 )
71
72 if (MSVC) 
73    set (PUNAME "pui")
74 else (MSVC)
75    set (PUNAME "pu")
76 endif (MSVC)
77
78
79 macro(find_static_component comp libs)
80     # account for alternative Windows PLIB distribution naming
81     if(MSVC)
82       set(compLib "${comp}")
83     else(MSVC)
84       set(compLib "plib${comp}")
85     endif(MSVC)
86     
87     string(TOUPPER "PLIB_${comp}" compLibBase)
88     set( compLibName ${compLibBase}_LIBRARY )
89
90     FIND_LIBRARY(${compLibName}_DEBUG
91       NAMES ${compLib}_d
92       HINTS $ENV{PLIBDIR}
93       PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64
94       PATHS
95       /usr/local
96       /usr
97       /opt
98     )
99     FIND_LIBRARY(${compLibName}_RELEASE
100       NAMES ${compLib}
101       HINTS $ENV{PLIBDIR}
102       PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64
103       PATHS
104       /usr/local
105       /usr
106       /opt
107     )
108     select_library_configurations( ${compLibBase} )
109
110     set(componentLibRelease ${${compLibName}_RELEASE})
111     #message(STATUS "Simgear ${compLibName}_RELEASE ${componentLibRelease}")
112     set(componentLibDebug ${${compLibName}_DEBUG})
113     #message(STATUS "Simgear ${compLibName}_DEBUG ${componentLibDebug}")
114     if (NOT ${compLibName}_DEBUG)
115         if (NOT ${compLibName}_RELEASE)
116             #message(STATUS "found ${componentLib}")
117             list(APPEND ${libs} ${componentLibRelease})
118         endif()
119     else()
120         list(APPEND ${libs} optimized ${componentLibRelease} debug ${componentLibDebug})
121     endif()
122 endmacro()
123
124 if(${PLIB_LIBRARIES} STREQUAL "PLIB_LIBRARIES-NOTFOUND")    
125     set(PLIB_LIBRARIES "") # clear value
126     
127 # based on the contents of deps, add other required PLIB
128 # static library dependencies. Eg PUI requires SSG and FNT
129     set(outDeps ${PLIB_FIND_COMPONENTS})
130     
131     foreach(c ${PLIB_FIND_COMPONENTS})
132         if (${c} STREQUAL "pu")
133             # handle MSVC confusion over pu/pui naming, by removing
134             # 'pu' and then adding it back
135             list(REMOVE_ITEM outDeps "pu")
136             list(APPEND outDeps ${PUNAME} "fnt" "ssg" "sg")
137         elseif (${c} STREQUAL "puaux")
138             list(APPEND outDeps ${PUNAME} "fnt" "ssg" "sg")
139         elseif (${c} STREQUAL "ssg")
140             list(APPEND outDeps "sg")
141         endif()
142     endforeach()
143         
144     list(APPEND outDeps "ul") # everything needs ul
145     list(REMOVE_DUPLICATES outDeps) # clean up
146
147     
148
149     # look for traditional static libraries
150     foreach(component ${outDeps})
151         find_static_component(${component} PLIB_LIBRARIES)
152     endforeach()
153 endif()
154
155 list(FIND outDeps "js" haveJs)
156 if(${haveJs} GREATER -1)
157     message(STATUS "adding runtime JS dependencies")
158     if(APPLE)
159     # resolve frameworks to full paths
160         find_library(IOKIT_LIBRARY IOKit)
161         find_library(CF_LIBRARY CoreFoundation)
162         set(JS_LIBS ${IOKIT_LIBRARY} ${CF_LIBRARY})
163     elseif(WIN32)
164         set(WINMM_LIBRARY winmm)
165         set(JS_LIBS ${WINMM_LIBRARY})
166     elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
167         # anything needed here?
168     elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
169         find_library(USBHID_LIBRARY usbhid)
170         # check_function_exists(hidinit)
171         set(JS_LIBS ${USBHID_LIBRARY})
172     else()
173         message(WARNING "Unsupported platform for PLIB JS libs")
174     endif()
175     
176     list(APPEND PLIB_LIBRARIES ${JS_LIBS})
177 endif()
178
179 include(FindPackageHandleStandardArgs)
180 FIND_PACKAGE_HANDLE_STANDARD_ARGS(PLIB DEFAULT_MSG PLIB_LIBRARIES PLIB_INCLUDE_DIR)
181