# Find script for the ANGLE OpenGL ES implementation.
# Sets:
# - ANGLE_FOUND if found
# - ANGLE_INCLUDE_DIRECTORIES to ANGLE's include directories
# - ANGLE_LIBRARIES to ANGLE's libraries (ANGLE_EGL_LIBRARY -> libEGL, ANGLE_GLESv2_LIBRARY -> libGLESv2)
include(FindPackageHandleStandardArgs)

set(ANGLE_ROOT ANGLE_ROOT-NOTFOUND CACHE PATH "ANGLE's [source] root directory")

find_path(ANGLE_INCLUDE_DIRECTORIES include/angle_gl.h
    PATHS ${ANGLE_ROOT} $ENV{ANGLE_ROOT}
    PATH_SUFFIXES "" include ANGLE
    DOC "ANGLE's include directory"
)
find_library(ANGLE_EGL_LIBRARY
    NAMES EGL libEGL
    HINTS ${ANGLE_ROOT} $ENV{ANGLE_ROOT}
    PATH_SUFFIXES out out/${CMAKE_BUILD_TYPE}
    DOC "ANGLE's libEGL"
)
find_library(ANGLE_GLESv2_LIBRARY
    NAMES GLESv2 libGLESv2
    HINTS ${ANGLE_ROOT} $ENV{ANGLE_ROOT}
    PATH_SUFFIXES out out/${CMAKE_BUILD_TYPE}
    DOC "ANGLE's libGLESv2"
)
set(ANGLE_LIBRARIES ${ANGLE_EGL_LIBRARY} ${ANGLE_GLESv2_LIBRARY})
if(ANGLE_INCLUDE_DIRECTORIES AND ANGLE_LIBRARIES)
    set(ANGLE_FOUND YES)
else()
    set(ANGLE_FOUND NO)
endif()

find_package_handle_standard_args(ANGLE
  FOUND_VAR ANGLE_FOUND
  REQUIRED_VARS ANGLE_INCLUDE_DIRECTORIES ANGLE_EGL_LIBRARY ANGLE_GLESv2_LIBRARY
)
mark_as_advanced(ANGLE_FOUND ANGLE_INCLUDE_DIRECTORIES ANGLE_EGL_LIBRARY ANGLE_GLESv2_LIBRARY ANGLE_LIBRARIES)
