# Find Ogg
#
# This module defines
#  Ogg_FOUND
#  Ogg_INCLUDE_DIRS
#  Ogg_LIBRARIES
#
# Copyright (c) 2014 I-maginer
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA, or go to
# http://www.gnu.org/copyleft/lesser.txt
#
# - Try to find Ogg
# Once done, this will define
#
#  Ogg_FOUND - system has Ogg
#  Ogg_INCLUDE_DIRS - the Ogg include directories
#  Ogg_LIBRARIES - link these to use Ogg

include(FindPkgMacros)
findpkg_begin(Ogg)

message("prefix: ${CMAKE_FIND_LIBRARY_PREFIXES}")
message("suffix: ${CMAKE_FIND_LIBRARY_SUFFIXES}")

# Get path, convert backslashes as ${ENV_${var}}
getenv_path(OGG_HOME)

# construct search paths
set(Ogg_PREFIX_PATH ${Ogg_HOME} ${ENV_Ogg_HOME} )
create_search_paths(Ogg)
# redo search if prefix path changed
clear_if_changed(Ogg_PREFIX_PATH
  Ogg_LIBRARY_FWK
  Ogg_LIBRARY_REL
  Ogg_LIBRARY_DBG
  Ogg_INCLUDE_DIR
)

set(Ogg_LIBRARY_NAMES Ogg ogg)
get_debug_names(Ogg_LIBRARY_NAMES)

use_pkgconfig(Ogg_PKGC Ogg-config)

findpkg_framework(Ogg)

find_path(Ogg_INCLUDE_DIR NAMES ogg/ogg.h HINTS ${Ogg_INC_SEARCH_PATH} ${Ogg_PKGC_INCLUDE_DIRS} NO_CMAKE_FIND_ROOT_PATH)
find_library(Ogg_LIBRARY_REL NAMES ${Ogg_LIBRARY_NAMES} HINTS ${Ogg_LIB_SEARCH_PATH} ${Ogg_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" Release RelWithDebInfo MinSizeRel ${ANDROID_ABI} NO_CMAKE_FIND_ROOT_PATH)
find_library(Ogg_LIBRARY_DBG NAMES ${Ogg_LIBRARY_NAMES_DBG} HINTS ${Ogg_LIB_SEARCH_PATH} ${Ogg_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" Debug ${ANDROID_ABI} NO_CMAKE_FIND_ROOT_PATH)
make_library_set(Ogg_LIBRARY)

findpkg_finish(Ogg)