Add CMake config-file package generation
[platform/upstream/libvorbis.git] / cmake / FindOgg.cmake
1 #[=======================================================================[.rst:
2
3 FindOgg
4 --------
5
6 Find the native Ogg includes and library.
7
8 IMPORTED Targets
9 ^^^^^^^^^^^^^^^^
10
11 This module defines :prop_tgt:`IMPORTED` target ``Ogg::ogg``, if
12 Ogg has been found.
13
14 Result Variables
15 ^^^^^^^^^^^^^^^^
16
17 This module defines the following variables:
18
19 ::
20
21   OGG_INCLUDE_DIRS    - where to find ogg.h, etc.
22   OGG_LIBRARIES       - List of libraries when using ogg.
23   OGG_FOUND           - True if ogg found.
24
25 ::
26
27   OGG_VERSION_STRING  - The version of ogg found (x.y.z)
28
29 Hints
30 ^^^^^
31
32 A user may set ``OGG_ROOT`` to a ogg installation root to tell this
33 module where to look.
34 #]=======================================================================]
35
36 if(OGG_INCLUDE_DIR)
37   # Already in cache, be silent
38   set(OGG_FIND_QUIETLY TRUE)
39 endif()
40
41 find_package(PkgConfig QUIET)
42 pkg_check_modules(PC_OGG QUIET ogg)
43
44 set(OGG_VERSION_STRING ${PC_OGG_VERSION})
45
46 find_path(OGG_INCLUDE_DIR ogg/ogg.h
47     HINTS
48         ${PC_OGG_INCLUDEDIR}
49         ${PC_OGG_INCLUDE_DIRS}
50         ${OGG_ROOT}
51     PATH_SUFFIXES
52         include
53 )
54 # MSVC built ogg may be named ogg_static.
55 # The provided project files name the library with the lib prefix.
56 find_library(OGG_LIBRARY
57     NAMES
58         ogg
59         ogg_static
60         libogg
61         libogg_static
62     HINTS
63         ${PC_OGG_LIBDIR}
64         ${PC_OGG_LIBRARY_DIRS}
65         ${OGG_ROOT}
66     PATH_SUFFIXES
67         lib
68 )
69
70 # Handle the QUIETLY and REQUIRED arguments and set OGG_FOUND
71 # to TRUE if all listed variables are TRUE.
72 include(FindPackageHandleStandardArgs)
73 find_package_handle_standard_args(Ogg
74     REQUIRED_VARS
75         OGG_LIBRARY
76         OGG_INCLUDE_DIR
77     VERSION_VAR
78         OGG_VERSION_STRING
79 )
80
81 if(OGG_FOUND)
82     set(OGG_LIBRARIES ${OGG_LIBRARY})
83     set(OGG_INCLUDE_DIRS ${OGG_INCLUDE_DIR})
84     
85     if(NOT TARGET Ogg::ogg)
86     add_library(Ogg::ogg UNKNOWN IMPORTED)
87         set_target_properties(Ogg::ogg PROPERTIES
88             INTERFACE_INCLUDE_DIRECTORIES "${OGG_INCLUDE_DIRS}"
89             IMPORTED_LOCATION "${OGG_LIBRARIES}"
90         )
91   endif()
92 endif()
93
94 mark_as_advanced(OGG_INCLUDE_DIR OGG_LIBRARY)