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