# Find LibHaru
#
# This module defines
#  LibHaru_FOUND
#  LibHaru_INCLUDE_DIRS
#  LibHaru_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
#

include(FindPkgMacros)
findpkg_begin(LibHaru)

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

# construct search paths
set(LibHaru_PREFIX_PATH ${LIBHARU_HOME} ${ENV_LIBHARU_HOME})
create_search_paths(LibHaru)
# redo search if prefix path changed
clear_if_changed(LibHaru_PREFIX_PATH
  LibHaru_LIBRARY_FWK
  LibHaru_LIBRARY_REL
  LibHaru_LIBRARY_DBG
  LibHaru_INCLUDE_DIR
)

set(LibHaru_LIBRARY_NAMES libhpdfs libhpdfsd hpdfs)
get_debug_names(LibHaru_LIBRARY_NAMES)

use_pkgconfig(LibHaru_PKGC zzip-LibHaru-config)

findpkg_framework(LibHaru)

find_path(LibHaru_INCLUDE_DIR NAMES hpdf.h HINTS ${LibHaru_INC_SEARCH_PATH} ${LibHaru_PKGC_INCLUDE_DIRS})
find_library(LibHaru_LIBRARY_REL NAMES ${LibHaru_LIBRARY_NAMES} HINTS ${LibHaru_LIB_SEARCH_PATH} ${LibHaru_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" Release RelWithDebInfo MinSizeRel ${ANDROID_ABI})
find_library(LibHaru_LIBRARY_DBG NAMES ${LibHaru_LIBRARY_NAMES_DBG} HINTS ${LibHaru_LIB_SEARCH_PATH} ${LibHaru_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" Debug ${ANDROID_ABI})
make_library_set(LibHaru_LIBRARY)

findpkg_finish(LibHaru)