4 # PLIB_FOUND, if false, do not try to link to PLIB
5 # PLIB_INCLUDE_DIR, where to find the headers
7 # $PLIBDIR is an environment variable that would
8 # correspond to the ./configure --prefix=$PLIBDIR
9 # used in building PLIB.
11 # Created by James Turner. This was influenced by the FindOpenAL.cmake module.
13 #=============================================================================
14 # Copyright 2005-2009 Kitware, Inc.
16 # Distributed under the OSI-approved BSD License (the "License");
17 # see accompanying file Copyright.txt for details.
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.)
26 include(SelectLibraryConfigurations)
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}
34 set(CMAKE_FIND_FRAMEWORK ${save_FIND_FRAMEWORK})
36 if(NOT PLIB_INCLUDE_DIR)
37 FIND_PATH(PLIB_INCLUDE_DIR plib/ul.h
40 PATHS ${ADDITIONAL_LIBRARY_PATHS}
44 message(STATUS ${PLIB_INCLUDE_DIR})
46 # check for dynamic framework on Mac ()
47 FIND_LIBRARY(PLIB_LIBRARIES
51 PATHS ${ADDITIONAL_LIBRARY_PATHS}
61 macro(find_static_component comp libs)
62 # account for alternative Windows PLIB distribution naming
64 set(compLib "${comp}")
66 set(compLib "plib${comp}")
69 string(TOUPPER "PLIB_${comp}" compLibBase)
70 set( compLibName ${compLibBase}_LIBRARY )
72 FIND_LIBRARY(${compLibName}_DEBUG
75 PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64
76 PATHS ${ADDITIONAL_LIBRARY_PATHS}
78 FIND_LIBRARY(${compLibName}_RELEASE
81 PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64
82 PATHS ${ADDITIONAL_LIBRARY_PATHS}
84 select_library_configurations( ${compLibBase} )
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})
96 list(APPEND ${libs} optimized ${componentLibRelease} debug ${componentLibDebug})
100 if(${PLIB_LIBRARIES} STREQUAL "PLIB_LIBRARIES-NOTFOUND")
101 set(PLIB_LIBRARIES "") # clear value
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})
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")
120 list(APPEND outDeps "ul") # everything needs ul
121 list(REMOVE_DUPLICATES outDeps) # clean up
124 # look for traditional static libraries
125 foreach(component ${outDeps})
126 find_static_component(${component} PLIB_LIBRARIES)
130 list(FIND outDeps "js" haveJs)
131 if(${haveJs} GREATER -1)
132 message(STATUS "adding runtime JS dependencies")
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})
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})
148 message(WARNING "Unsupported platform for PLIB JS libs")
151 list(APPEND PLIB_LIBRARIES ${JS_LIBS})
154 include(FindPackageHandleStandardArgs)
155 FIND_PACKAGE_HANDLE_STANDARD_ARGS(PLIB DEFAULT_MSG PLIB_LIBRARIES PLIB_INCLUDE_DIR)