duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

FindWebP.cmake (5702B)


      1 # Copyright (C) 2020 Sony Interactive Entertainment Inc.
      2 # Copyright (C) 2012 Raphael Kubo da Costa <rakuco@webkit.org>
      3 # Copyright (C) 2013 Igalia S.L.
      4 #
      5 # Redistribution and use in source and binary forms, with or without
      6 # modification, are permitted provided that the following conditions
      7 # are met:
      8 # 1.  Redistributions of source code must retain the above copyright
      9 #     notice, this list of conditions and the following disclaimer.
     10 # 2.  Redistributions in binary form must reproduce the above copyright
     11 #     notice, this list of conditions and the following disclaimer in the
     12 #     documentation and/or other materials provided with the distribution.
     13 #
     14 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS
     15 # IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     16 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     17 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS
     18 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     19 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     20 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     21 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     22 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     23 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     24 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25 
     26 #[=======================================================================[.rst:
     27 FindWebP
     28 --------------
     29 
     30 Find WebP headers and libraries.
     31 
     32 Imported Targets
     33 ^^^^^^^^^^^^^^^^
     34 
     35 ``WebP::libwebp``
     36   The WebP library, if found.
     37 
     38 ``WebP::demux``
     39   The WebP demux library, if found.
     40 
     41 Result Variables
     42 ^^^^^^^^^^^^^^^^
     43 
     44 This will define the following variables in your project:
     45 
     46 ``WebP_FOUND``
     47   true if (the requested version of) WebP is available.
     48 ``WebP_VERSION``
     49   the version of WebP.
     50 ``WebP_LIBRARIES``
     51   the libraries to link against to use WebP.
     52 ``WebP_INCLUDE_DIRS``
     53   where to find the WebP headers.
     54 ``WebP_COMPILE_OPTIONS``
     55   this should be passed to target_compile_options(), if the
     56   target is not used for linking
     57 
     58 #]=======================================================================]
     59 
     60 find_package(PkgConfig QUIET)
     61 pkg_check_modules(PC_WEBP QUIET libwebp)
     62 set(WebP_COMPILE_OPTIONS ${PC_WEBP_CFLAGS_OTHER})
     63 set(WebP_VERSION ${PC_WEBP_CFLAGS_VERSION})
     64 
     65 find_path(WebP_INCLUDE_DIR
     66     NAMES webp/decode.h
     67     HINTS ${PC_WEBP_INCLUDEDIR} ${PC_WEBP_INCLUDE_DIRS}
     68 )
     69 
     70 find_library(WebP_LIBRARY
     71     NAMES ${WebP_NAMES} webp libwebp
     72     HINTS ${PC_WEBP_LIBDIR} ${PC_WEBP_LIBRARY_DIRS}
     73 )
     74 
     75 # There's nothing in the WebP headers that could be used to detect the exact
     76 # WebP version being used so don't attempt to do so. A version can only be found
     77 # through pkg-config
     78 if ("${WebP_FIND_VERSION}" VERSION_GREATER "${WebP_VERSION}")
     79     if (WebP_VERSION)
     80         message(FATAL_ERROR "Required version (" ${WebP_FIND_VERSION} ") is higher than found version (" ${WebP_VERSION} ")")
     81     else ()
     82         message(WARNING "Cannot determine WebP version without pkg-config")
     83     endif ()
     84 endif ()
     85 
     86 # Find components
     87 if (WebP_INCLUDE_DIR AND WebP_LIBRARY)
     88     set(_WebP_REQUIRED_LIBS_FOUND ON)
     89     set(WebP_LIBS_FOUND "WebP (required): ${WebP_LIBRARY}")
     90 else ()
     91     set(_WebP_REQUIRED_LIBS_FOUND OFF)
     92     set(WebP_LIBS_NOT_FOUND "WebP (required)")
     93 endif ()
     94 
     95 if ("demux" IN_LIST WebP_FIND_COMPONENTS)
     96     find_library(WebP_DEMUX_LIBRARY
     97         NAMES ${WebP_DEMUX_NAMES} webpdemux libwebpdemux
     98         HINTS ${PC_WEBP_LIBDIR} ${PC_WEBP_LIBRARY_DIRS}
     99     )
    100 
    101     if (WebP_DEMUX_LIBRARY)
    102         if (WebP_FIND_REQUIRED_demux)
    103             list(APPEND WebP_LIBS_FOUND "demux (required): ${WebP_DEMUX_LIBRARY}")
    104         else ()
    105            list(APPEND WebP_LIBS_FOUND "demux (optional): ${WebP_DEMUX_LIBRARY}")
    106         endif ()
    107     else ()
    108         if (WebP_FIND_REQUIRED_demux)
    109            set(_WebP_REQUIRED_LIBS_FOUND OFF)
    110            list(APPEND WebP_LIBS_NOT_FOUND "demux (required)")
    111         else ()
    112            list(APPEND WebP_LIBS_NOT_FOUND "demux (optional)")
    113         endif ()
    114     endif ()
    115 endif ()
    116 
    117 if (NOT WebP_FIND_QUIETLY)
    118     if (WebP_LIBS_FOUND)
    119         message(STATUS "Found the following WebP libraries:")
    120         foreach (found ${WebP_LIBS_FOUND})
    121             message(STATUS " ${found}")
    122         endforeach ()
    123     endif ()
    124     if (WebP_LIBS_NOT_FOUND)
    125         message(STATUS "The following WebP libraries were not found:")
    126         foreach (found ${WebP_LIBS_NOT_FOUND})
    127             message(STATUS " ${found}")
    128         endforeach ()
    129     endif ()
    130 endif ()
    131 
    132 include(FindPackageHandleStandardArgs)
    133 find_package_handle_standard_args(WebP
    134     FOUND_VAR WebP_FOUND
    135     REQUIRED_VARS WebP_INCLUDE_DIR WebP_LIBRARY _WebP_REQUIRED_LIBS_FOUND
    136     VERSION_VAR WebP_VERSION
    137 )
    138 
    139 if (WebP_LIBRARY AND NOT TARGET WebP::libwebp)
    140     add_library(WebP::libwebp UNKNOWN IMPORTED GLOBAL)
    141     set_target_properties(WebP::libwebp PROPERTIES
    142         IMPORTED_LOCATION "${WebP_LIBRARY}"
    143         INTERFACE_COMPILE_OPTIONS "${WebP_COMPILE_OPTIONS}"
    144         INTERFACE_INCLUDE_DIRECTORIES "${WebP_INCLUDE_DIR}"
    145     )
    146 endif ()
    147 
    148 if (WebP_DEMUX_LIBRARY AND NOT TARGET WebP::demux)
    149     add_library(WebP::demux UNKNOWN IMPORTED GLOBAL)
    150     set_target_properties(WebP::demux PROPERTIES
    151         IMPORTED_LOCATION "${WebP_DEMUX_LIBRARY}"
    152         INTERFACE_COMPILE_OPTIONS "${WebP_COMPILE_OPTIONS}"
    153         INTERFACE_INCLUDE_DIRECTORIES "${WebP_INCLUDE_DIR}"
    154     )
    155 endif ()
    156 
    157 mark_as_advanced(
    158     WebP_INCLUDE_DIR
    159     WebP_LIBRARY
    160     WebP_DEMUX_LIBRARY
    161 )
    162 
    163 if (WebP_FOUND)
    164     set(WebP_LIBRARIES ${WebP_LIBRARY} ${WebP_DEMUX_LIBRARY})
    165     set(WebP_INCLUDE_DIRS ${WebP_INCLUDE_DIR})
    166 endif ()