]> git.mxchange.org Git - flightgear.git/blob - CMakeModules/FindPLIB.cmake
Merge branch 'next' of gitorious.org:fg/flightgear into next
[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 set(save_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
38 set(CMAKE_FIND_FRAMEWORK ONLY)
39 FIND_PATH(PLIB_INCLUDE_DIR ul.h
40   PATH_SUFFIXES include/plib include 
41   PATHS
42   ~/Library/Frameworks
43   /Library/Frameworks
44 )
45 set(CMAKE_FIND_FRAMEWORK ${save_FIND_FRAMEWORK})
46
47 if(NOT PLIB_INCLUDE_DIR)
48     FIND_PATH(PLIB_INCLUDE_DIR plib/ul.h
49       PATH_SUFFIXES include 
50       HINTS $ENV{PLIBDIR}
51       PATHS
52       /usr/local
53       /opt/local
54       /usr
55     )
56 endif()
57
58 message(STATUS ${PLIB_INCLUDE_DIR})
59
60 # check for dynamic framework on Mac ()
61 FIND_LIBRARY(PLIB_LIBRARIES
62   NAMES plib PLIB
63   HINTS
64   $ENV{PLIBDIR}
65   PATHS
66   ~/Library/Frameworks
67   /Library/Frameworks
68 )
69
70 if (MSVC) 
71    set (PUNAME "pui")
72 else (MSVC)
73    set (PUNAME "pu")
74 endif (MSVC)
75
76
77 macro(find_static_component comp libs)
78     # account for alternative Windows PLIB distribution naming
79     if(MSVC)
80       set(compLib "${comp}")
81     else(MSVC)
82       set(compLib "plib${comp}")
83     endif(MSVC)
84     
85     string(TOUPPER "PLIB_${comp}_LIBRARY" compLibName)
86     
87     FIND_LIBRARY(${compLibName}
88       NAMES ${compLib}
89       HINTS $ENV{PLIBDIR}
90       PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64
91       PATHS
92       /usr/local
93       /usr
94       /opt
95     )
96     
97     set(componentLib ${${compLibName}})
98     if (NOT ${componentLib} STREQUAL "componentLib-NOTFOUND")
99         list(APPEND ${libs} ${componentLib})
100     endif()
101 endmacro()
102
103 if(${PLIB_LIBRARIES} STREQUAL "PLIB_LIBRARIES-NOTFOUND")    
104     set(PLIB_LIBRARIES "") # clear value
105     
106 # based on the contents of deps, add other required PLIB
107 # static library dependencies. Eg PUI requires SSG and FNT
108     set(outDeps ${PLIB_FIND_COMPONENTS})
109     
110     foreach(c ${PLIB_FIND_COMPONENTS})
111         if (${c} STREQUAL "pu")
112             # handle MSVC confusion over pu/pui naming, by removing
113             # 'pu' and then adding it back
114             list(REMOVE_ITEM outDeps "pu")
115             list(APPEND outDeps ${PUNAME} "fnt" "ssg" "sg")
116         elseif (${c} STREQUAL "puaux")
117             list(APPEND outDeps ${PUNAME} "fnt" "ssg" "sg")
118         elseif (${c} STREQUAL "ssg")
119             list(APPEND outDeps "sg")
120         endif()
121     endforeach()
122         
123     list(APPEND outDeps "ul") # everything needs ul
124     list(REMOVE_DUPLICATES outDeps) # clean up
125
126     
127
128     # look for traditional static libraries
129     foreach(component ${outDeps})
130         find_static_component(${component} PLIB_LIBRARIES)
131     endforeach()
132 endif()
133
134 list(FIND outDeps "js" haveJs)
135 if(${haveJs} GREATER -1)
136     message(STATUS "adding runtime JS dependencies")
137     if(APPLE)
138     # resolve frameworks to full paths
139         find_library(IOKIT_LIBRARY IOKit)
140         find_library(CF_LIBRARY CoreFoundation)
141         set(JS_LIBS ${IOKIT_LIBRARY} ${CF_LIBRARY})
142     elseif(WIN32)
143         find_library(WINMM_LIBRARY winmm)
144         set(JS_LIBS ${WINMM_LIBRARY})
145     elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
146         # anything needed here?
147     elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
148         find_library(USBHID_LIBRARY usbhid)
149         # check_function_exists(hidinit)
150         set(JS_LIBS ${USBHID_LIBRARY})
151     else()
152         message(WARNING "Unsupported platform for PLIB JS libs")
153     endif()
154     
155     list(APPEND PLIB_LIBRARIES ${JS_LIBS})
156 endif()
157
158 include(FindPackageHandleStandardArgs)
159 FIND_PACKAGE_HANDLE_STANDARD_ARGS(PLIB DEFAULT_MSG PLIB_LIBRARIES PLIB_INCLUDE_DIR)
160