# We set:
# - SKIA_INCLUDE_DIRS
# - SKIA_LIBRARIES
# - SKIA_DEFINITIONS
# - SKIA_FOUND
# Taking into account:
# - SKIA_PREFIX

SET(SKIA_FOUND FALSE)

FIND_PATH(SKIA_BASE_INCLUDE_DIR
    core/SkBitmap.h
  PATHS
    ${SKIA_PREFIX}/include
)

IF(SKIA_BASE_INCLUDE_DIR)
  SET(SKIA_INCLUDE_DIRS
    ${SKIA_BASE_INCLUDE_DIR}/core
    ${SKIA_BASE_INCLUDE_DIR}/config
    ${SKIA_BASE_INCLUDE_DIR}/images
    ${SKIA_BASE_INCLUDE_DIR}/effects
    ${SKIA_BASE_INCLUDE_DIR}/lazy
  )
ENDIF(SKIA_BASE_INCLUDE_DIR)

SET(SKIA_DEBUG ${SKIA_PREFIX}/out/gyp/Debug)
SET(SKIA_RELEASE ${SKIA_PREFIX}/out/gyp/Release)
FIND_LIBRARY(SKIA_CORE_LIB_D NAMES skia_core PATHS ${SKIA_DEBUG})
FIND_LIBRARY(SKIA_PORTS_LIB_D NAMES skia_ports PATHS ${SKIA_DEBUG})
FIND_LIBRARY(SKIA_OPTS_LIB_D NAMES skia_opts PATHS ${SKIA_DEBUG})
FIND_LIBRARY(SKIA_IMAGES_LIB_D NAMES skia_images PATHS ${SKIA_DEBUG})
FIND_LIBRARY(SKIA_UTILS_LIB_D NAMES skia_utils PATHS ${SKIA_DEBUG})
FIND_LIBRARY(SKIA_OPTS_SSSE3_LIB_D NAMES skia_opts_ssse3 PATHS ${SKIA_DEBUG})
FIND_LIBRARY(SKIA_EFFECTS_LIB_D NAMES skia_effects PATHS ${SKIA_DEBUG})
FIND_LIBRARY(SKIA_SFNT_LIB_D NAMES skia_sfnt PATHS ${SKIA_DEBUG})
FIND_LIBRARY(SKIA_SKGPU_LIB_D NAMES skia_skgpu PATHS ${SKIA_DEBUG})

FIND_LIBRARY(SKIA_CORE_LIB_R NAMES skia_core PATHS ${SKIA_RELEASE})
FIND_LIBRARY(SKIA_PORTS_LIB_R NAMES skia_ports PATHS ${SKIA_RELEASE})
FIND_LIBRARY(SKIA_OPTS_LIB_R NAMES skia_opts PATHS ${SKIA_RELEASE})
FIND_LIBRARY(SKIA_IMAGES_LIB_R NAMES skia_images PATHS ${SKIA_RELEASE})
FIND_LIBRARY(SKIA_UTILS_LIB_R NAMES skia_utils PATHS ${SKIA_RELEASE})
FIND_LIBRARY(SKIA_OPTS_SSSE3_LIB_R NAMES skia_opts_ssse3 PATHS ${SKIA_RELEASE})
FIND_LIBRARY(SKIA_EFFECTS_LIB_R NAMES skia_effects PATHS ${SKIA_RELEASE})
FIND_LIBRARY(SKIA_SFNT_LIB_R NAMES skia_sfnt PATHS ${SKIA_RELEASE})
FIND_LIBRARY(SKIA_SKGPU_LIB_R NAMES skia_skgpu PATHS ${SKIA_RELEASE})

IF(WIN32)

  # Assume that if we find core, we find the rest too
  IF(SKIA_BASE_INCLUDE_DIR AND SKIA_CORE_LIB_R AND SKIA_CORE_LIB_D)
    SET(SKIA_FOUND TRUE)
    SET(SKIA_LIBRARIES
      optimized ${SKIA_CORE_LIB_R}
      debug ${SKIA_CORE_LIB_D}
      optimized ${SKIA_PORTS_LIB_R}
      debug ${SKIA_PORTS_LIB_D}
      optimized ${SKIA_OPTS_LIB_R}
      debug ${SKIA_OPTS_LIB_D}
      optimized ${SKIA_IMAGES_LIB_R}
      debug ${SKIA_IMAGES_LIB_D}
      optimized ${SKIA_UTILS_LIB_R}
      debug ${SKIA_UTILS_LIB_D}
      optimized ${SKIA_OPTS_SSSE3_LIB_R}
      debug ${SKIA_OPTS_SSSE3_LIB_D}
      optimized ${SKIA_EFFECTS_LIB_R}
      debug ${SKIA_EFFECTS_LIB_D}
      optimized ${SKIA_SFNT_LIB_R}
      debug ${SKIA_SFNT_LIB_D}
      optimized ${SKIA_SKGPU_LIB_R}
      debug ${SKIA_SKGPU_LIB_D}
      Usp10.lib
      Opengl32.lib
    )
  ENDIF(SKIA_BASE_INCLUDE_DIR AND SKIA_CORE_LIB_R AND SKIA_CORE_LIB_D)
ELSEIF(APPLE)
  IF(SKIA_BASE_INCLUDE_DIR AND SKIA_CORE_LIB_R)
    SET(SKIA_FOUND TRUE)
    # lines below don't work
    #FIND_LIBRARY(COREFOUNDATION_LIBRARY CoreFoundatation)
    #FIND_LIBRARY(MOBILECORESERVICES_LIBRARY ApplicationServices)
    SET(SKIA_LIBRARIES
      ${SKIA_CORE_LIB_R}
      ${SKIA_PORTS_LIB_R}
      ${SKIA_OPTS_LIB_R}
      ${SKIA_IMAGES_LIB_R}
      ${SKIA_UTILS_LIB_R}
      ${SKIA_OPTS_SSSE3_LIB_R}
      ${SKIA_EFFECTS_LIB_R}
      ${SKIA_SFNT_LIB_R}
      ${SKIA_SKGPU_LIB_R}
      "-framework CoreFoundation"
      "-framework ApplicationServices"
    )
    # avoid undefined SkTOU8 etc (skia checks NDEBUG if SK_RELEASE and
    # SK_DEBUG are undefined)
    SET(SKIA_DEFINES "-DSK_RELEASE")
  ENDIF(SKIA_BASE_INCLUDE_DIR AND SKIA_CORE_LIB_R)
ENDIF(WIN32)


