# A custom module for finding tinyxml2
# - Find TinyXML2
# Find the native TinyXML2 includes and library
#
#   TINYXML2_FOUND       - True if TinyXML2 found.
#   TINYXML2_INCLUDE_DIR - where to find tinyxml2.h, etc.
#   TINYXML2_LIBRARIES   - List of libraries when using TinyXML2.
#

IF( TINYXML2_INCLUDE_DIR )
    # Already in cache, be silent
    SET( TINYXML2_FIND_QUIETLY TRUE )
ENDIF( TINYXML2_INCLUDE_DIR )

SET(_TINYXML2_SEARCHES)

# Search TINYXML2_ROOT first if it is set.
IF(TINYXML2_ROOT)
  SET(_TINYXML2_SEARCH_ROOT PATHS ${TINYXML2_ROOT} NO_DEFAULT_PATH)
  LIST(APPEND _TINYXML2_SEARCHES _TINYXML2_SEARCH_ROOT)
ENDIF()

# Normal search.
SET(_TINYXML2_SEARCH_NORMAL
		"$ENV{PROGRAMFILES}/tinyxml2")
LIST(APPEND _TINYXML2_SEARCHES _TINYXML2_SEARCH_NORMAL)

FOREACH(search ${_TINYXML2_SEARCHES})
	FIND_PATH(TINYXML2_INCLUDE_DIR 		NAMES tinyxml2.h 		PATHS  ${${search}} PATH_SUFFIXES include )
	FIND_LIBRARY(TINYXML2_LIBRARIES 	NAMES tinyxml2 			PATHS ${${search}} PATH_SUFFIXES lib )
ENDFOREACH()
			  
# handle the QUIETLY and REQUIRED arguments and set TINYXML2_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE( FindPackageHandleStandardArgs )
FIND_PACKAGE_HANDLE_STANDARD_ARGS(TINYXML2 DEFAULT_MSG TINYXML2_INCLUDE_DIR TINYXML2_LIBRARIES )

MARK_AS_ADVANCED( TINYXML2_INCLUDE_DIR TINYXML2_LIBRARIES )