# Find WiringPi
#
# This module defines
#  WiringPi_FOUND
#  WiringPi_INCLUDE_DIRS
#  WiringPi_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 WiringPi
# Once done, this will define
#
#  WiringPi_FOUND - system has WiringPi
#  WiringPi_INCLUDE_DIRS - the WiringPi include directories 
#  WiringPi_LIBRARIES - link these to use WiringPi

include(FindPkgMacros)
findpkg_begin(WiringPi)

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

# construct search paths
set(WiringPi_PREFIX_PATH ${WiringPi_HOME} ${ENV_WiringPi_HOME} )
create_search_paths(WiringPi)
# redo search if prefix path changed
clear_if_changed(WiringPi_PREFIX_PATH
  WiringPi_LIBRARY_FWK
  WiringPi_LIBRARY_REL
  WiringPi_LIBRARY_DBG
  WiringPi_INCLUDE_DIR
)

set(WiringPi_LIBRARY_NAMES wiringPi)
get_debug_names(WiringPi_LIBRARY_NAMES)

use_pkgconfig(WiringPi_PKGC WiringPi-config)

findpkg_framework(WiringPi)

find_path(WiringPi_INCLUDE_DIR NAMES wiringPi.h HINTS ${WiringPi_INC_SEARCH_PATH} ${WiringPi_PKGC_INCLUDE_DIRS} PATH_SUFFIXES wiringPi NO_CMAKE_SYSTEM_PATH)
find_library(WiringPi_LIBRARY_REL NAMES ${WiringPi_LIBRARY_NAMES} HINTS ${WiringPi_LIB_SEARCH_PATH} ${WiringPi_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" Release RelWithDebInfo MinSizeRel ${ANDROID_ABI})
find_library(WiringPi_LIBRARY_DBG NAMES ${WiringPi_LIBRARY_NAMES_DBG} HINTS ${WiringPi_LIB_SEARCH_PATH} ${WiringPi_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" Debug ${ANDROID_ABI})
make_library_set(WiringPi_LIBRARY)

findpkg_finish(WiringPi)