# Find SAPI
#
# This module defines
#  SAPI_FOUND
#  SAPI_INCLUDE_DIRS
#  SAPI_LIBRARIES
#
# Copyright (c) 2012 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
#

if(WIN32)
include(FindPkgMacros)
findpkg_begin(SAPI)
  
# On a new cmake run, we do not need to be verbose
IF(SAPI_INCLUDE_DIR AND SAPI_LIBRARY)
 	SET(SAPI_FIND_QUIETLY TRUE)
ENDIF()

# Windows 10 Universal SDK
if(WINDOWS_PHONE AND MSVC12)
  set(SAPI_PREFIX_PATH "C:/Program Files (x86)/Windows Phone Kits/8.1" "C:/Program Files/Windows Phone Kits/8.1" "$ENV{ProgramFiles}/Windows Phone Kits/8.1")
  set(SAPI_INCPATH_SUFFIX "shared")
  set(SAPI_LIBPATH_SUFFIX "${MSVC_CXX_ARCHITECTURE_ID}")
  
# Windows Phone 8.0 SDK
elseif(WINDOWS_PHONE AND MSVC11)
  set(SAPI_PREFIX_PATH "C:/Program Files (x86)/Windows Phone Kits/8.0" "C:/Program Files/Windows Phone Kits/8.0" "$ENV{ProgramFiles}/Windows Phone Kits/8.0")
  set(SAPI_INCPATH_SUFFIX "shared")
  set(SAPI_LIBPATH_SUFFIX "${MSVC_CXX_ARCHITECTURE_ID}")
  
# Windows 8.1 SDK
elseif(MSVC12 OR MSVC14)
  set(SAPI_PREFIX_PATH "C:/Program Files (x86)/Windows Kits/8.1" "C:/Program Files/Windows Kits/8.1" "$ENV{ProgramFiles}/Windows Kits/8.1")
  set(SAPI_INCPATH_SUFFIX "um" "shared")
  set(SAPI_LIBPATH_SUFFIX "winv6.3/um/${MSVC_CXX_ARCHITECTURE_ID}")
  
# Windows 8.0 SDK
else(MSVC11)
  set(SAPI_PREFIX_PATH "C:/Program Files (x86)/Windows Kits/8.0" "C:/Program Files/Windows Kits/8.0" "$ENV{ProgramFiles}/Windows Kits/8.0")
  set(SAPI_INCPATH_SUFFIX "um" "shared")
  set(SAPI_LIBPATH_SUFFIX "win8/um/${MSVC_CXX_ARCHITECTURE_ID}")
endif()

# log message
IF (NOT SAPI_FIND_QUIETLY)
	MESSAGE(STATUS "Checking for SAPI library")
ENDIF()

create_search_paths(SAPI)
# redo search if prefix path changed
clear_if_changed(SAPI_INC_SEARCH_PATH
  SAPI_LIBRARY
  SAPI_INCLUDE_DIR
)

# Search for header files
FIND_PATH(SAPI_INCLUDE_DIR sapi.h PATHS ${SAPI_INC_SEARCH_PATH} PATH_SUFFIXES ${SAPI_INCPATH_SUFFIX})

# Search for libraries files
FIND_LIBRARY(SAPI_LIBRARY sapi PATHS ${SAPI_LIB_SEARCH_PATH} PATH_SUFFIXES ${SAPI_LIBPATH_SUFFIX})

# Configure libraries
SET(SAPI_INCLUDE_DIRS ${SAPI_INCLUDE_DIR} CACHE STRING "Directory containing SAPI header files" FORCE)
SET(SAPI_LIBRARIES ${SAPI_LIBRARY} CACHE STRING "SAPI libraries files" FORCE)

findpkg_finish(SAPI)
endif(WIN32)