# Module for locating genericSparseArray, based on ICU module.
#
# Cutomizable variables:
#   GENERICSPARSEARRAY_ROOT_DIR
#     This variable points to the genericSparseArray root directory. On Windows the
#     library location typically will have to be provided explicitly using the
#     -D command-line option. Alternatively, an environment variable can be set.
#
# Read-Only variables:
#   GENERICSPARSEARRAY_FOUND
#     Indicates whether the library has been found.
#
#   GENERICSPARSEARRAY_INCLUDE_DIRS
#     Points to the genericSparseArray include directory.
#
INCLUDE (CMakeParseArguments)
INCLUDE (FindPackageHandleStandardArgs)

SET (_PF86 "ProgramFiles(x86)")
SET (_GENERICSPARSEARRAY_POSSIBLE_DIRS
  ${GENERICSPARSEARRAY_ROOT_DIR}
  "$ENV{GENERICSPARSEARRAY_ROOT_DIR}"
  "C:/genericSparseArray"
  "$ENV{PROGRAMFILES}/genericSparseArray"
  "$ENV{${_PF86}}/genericSparseArray")

SET (_GENERICSPARSEARRAY_POSSIBLE_INCLUDE_SUFFIXES include)

IF (CMAKE_SIZEOF_VOID_P EQUAL 8)
  SET (_GENERICSPARSEARRAY_POSSIBLE_LIB_SUFFIXES lib64)
  SET (_GENERICSPARSEARRAY_POSSIBLE_BIN_SUFFIXES bin64)

  IF (NOT WIN32)
    LIST (APPEND _GENERICSPARSEARRAY_POSSIBLE_LIB_SUFFIXES lib)
    LIST (APPEND _GENERICSPARSEARRAY_POSSIBLE_BIN_SUFFIXES bin)
  ENDIF (NOT WIN32)
ELSE (CMAKE_SIZEOF_VOID_P EQUAL 8)
  SET (_GENERICSPARSEARRAY_POSSIBLE_LIB_SUFFIXES lib)
  SET (_GENERICSPARSEARRAY_POSSIBLE_BIN_SUFFIXES bin)
ENDIF (CMAKE_SIZEOF_VOID_P EQUAL 8)

FIND_PATH (GENERICSPARSEARRAY_ROOT_DIR
  NAMES include/genericSparseArray.h
  PATHS ${_GENERICSPARSEARRAY_POSSIBLE_DIRS}
  DOC "genericSparseArray root directory")

IF (GENERICSPARSEARRAY_ROOT_DIR)
  # Re-use the previous path:
  FIND_PATH (GENERICSPARSEARRAY_INCLUDE_DIR
    NAMES genericSparseArray.h
    PATHS ${GENERICSPARSEARRAY_ROOT_DIR}
    PATH_SUFFIXES ${_GENERICSPARSEARRAY_POSSIBLE_INCLUDE_SUFFIXES}
    DOC "genericSparseArray include directory"
    NO_DEFAULT_PATH)
ELSE (GENERICSPARSEARRAY_ROOT_DIR)
  # Use default path search
  FIND_PATH (GENERICSPARSEARRAY_INCLUDE_DIR
    NAMES genericSparseArray.h
    DOC "genericSparseArray include directory"
    )
ENDIF (GENERICSPARSEARRAY_ROOT_DIR)

IF (GENERICSPARSEARRAY_INCLUDE_DIR)
    SET (GENERICSPARSEARRAY_INCLUDE_DIRS "${GENERICSPARSEARRAY_INCLUDE_DIR}")
ENDIF (GENERICSPARSEARRAY_INCLUDE_DIR)

MARK_AS_ADVANCED (GENERICSPARSEARRAY_ROOT_DIR GENERICSPARSEARRAY_INCLUDE_DIR)

FIND_PACKAGE_HANDLE_STANDARD_ARGS (GENERICSPARSEARRAY
  REQUIRED_VARS
  GENERICSPARSEARRAY_INCLUDE_DIR
  )

IF(GENERICSPARSEARRAY_FOUND)
  MESSAGE(STATUS "-----------------------------------------")
  MESSAGE(STATUS "Setup GENERICSPARSEARRAY:")
  MESSAGE(STATUS "")
  MESSAGE(STATUS "           ROOT_DIR: ${GENERICSPARSEARRAY_ROOT_DIR}")
  MESSAGE(STATUS "        INCLUDE_DIR: ${GENERICSPARSEARRAY_INCLUDE_DIR}")
  MESSAGE(STATUS "-----------------------------------------")
ENDIF()

MARK_AS_ADVANCED (GENERICSPARSEARRAY_FOUND)
