]> git.mxchange.org Git - flightgear.git/blob - CMakeModules/FindPLIB.cmake
Win32 fix
[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 macro(find_static_component comp libs)
71         set(compLib "plib${comp}")
72         string(TOUPPER "PLIB_${comp}_LIBRARY" compLibName)
73         
74         FIND_LIBRARY(${compLibName}
75           NAMES ${compLib}
76           HINTS $ENV{PLIBDIR}
77           PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64
78           PATHS
79           /usr/local
80           /usr
81           /opt
82         )
83         
84         set(componentLib ${${compLibName}})
85         if (NOT ${componentLib} STREQUAL "componentLib-NOTFOUND")
86                 #message(STATUS "found ${componentLib}")
87                 list(APPEND ${libs} ${componentLib})
88                 #set(PLIB_LIBRARIES "${PLIB_LIBRARIES} ${componentLib}" PARENT_SCOPE)
89         endif()
90 endmacro()
91
92 if(${PLIB_LIBRARIES} STREQUAL "PLIB_LIBRARIES-NOTFOUND")        
93         set(PLIB_LIBRARIES "") # clear value
94         
95 # based on the contents of deps, add other required PLIB
96 # static library dependencies. Eg PUI requires SSG and FNT
97         set(outDeps ${PLIB_FIND_COMPONENTS})
98         
99         foreach(c ${PLIB_FIND_COMPONENTS})
100                 if (${c} STREQUAL "pu")
101                         list(APPEND outDeps "fnt" "ssg" "sg")
102                 elseif (${c} STREQUAL "puaux")
103                         list(APPEND outDeps "pu" "fnt" "ssg" "sg")
104                 elseif (${c} STREQUAL "ssg")
105                         list(APPEND outDeps "sg")
106                 endif()
107         endforeach()
108                 
109         list(APPEND outDeps "ul") # everything needs ul
110         list(REMOVE_DUPLICATES outDeps) # clean up
111                 
112         # look for traditional static libraries
113         foreach(component ${outDeps})
114                 find_static_component(${component} PLIB_LIBRARIES)
115         endforeach()
116 endif()
117
118 list(FIND outDeps "js" haveJs)
119 if(${haveJs} GREATER -1)
120         message(STATUS "adding runtime JS dependencies")
121         if(APPLE)
122         # resolve frameworks to full paths
123                 find_library(IOKIT_LIBRARY IOKit)
124                 find_library(CF_LIBRARY CoreFoundation)
125                 set(JS_LIBS ${IOKIT_LIBRARY} ${CF_LIBRARY})
126         elseif(WIN32)
127                 find_library(WINMM_LIBRARY winmm)
128                 set(JS_LIBS ${WINMM_LIBRARY})
129         elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
130                 # anything needed here?
131         elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
132                 find_library(USBHID_LIBRARY usbhid)
133                 # check_function_exists(hidinit)
134                 set(JS_LIBS ${USBHID_LIBRARY})
135         else()
136                 message(WARNING "Unsupported platform for PLIB JS libs")
137         endif()
138         
139         list(APPEND PLIB_LIBRARIES ${JS_LIBS})
140 endif()
141
142 include(FindPackageHandleStandardArgs)
143 FIND_PACKAGE_HANDLE_STANDARD_ARGS(PLIB DEFAULT_MSG PLIB_LIBRARIES PLIB_INCLUDE_DIR)
144