# Find glTF2-loader
#
# Below are the output variables:
#  - GLTF2-LOADER_INCLUDE_DIR
#  - GLTF2-LOADER_LIBRARY
#  - GLTF2-LOADER_FOUND


find_path(GLTF2-LOADER_INCLUDE_DIR
    NAMES gltf2/glTF2.hpp
    PATHS $ENV{GLTF2-LOADER_ROOT} ${GLTF2-LOADER_ROOT}
    PATH_SUFFIXES include
    CMAKE_FIND_ROOT_PATH_BOTH
)

find_library(GLTF2-LOADER_LIBRARY_DEBUG
    NAMES gltf2-loader-d
    PATHS $ENV{GLTF2-LOADER_ROOT} ${GLTF2-LOADER_ROOT}
    PATH_SUFFIXES lib lib64 lib/${ANDROID_ABI}
    CMAKE_FIND_ROOT_PATH_BOTH
)

find_library(GLTF2-LOADER_LIBRARY_RELEASE
    NAMES gltf2-loader
    PATHS $ENV{GLTF2-LOADER_ROOT} ${GLTF2-LOADER_ROOT}
    PATH_SUFFIXES lib lib64 lib/${ANDROID_ABI}
    CMAKE_FIND_ROOT_PATH_BOTH
)

# if both are found, set GLTF2-LOADER_LIBRARY to contain both
if (GLTF2-LOADER_LIBRARY_DEBUG AND GLTF2-LOADER_LIBRARY_RELEASE)
    set(GLTF2-LOADER_LIBRARY debug ${GLTF2-LOADER_LIBRARY_DEBUG}
                             optimized ${GLTF2-LOADER_LIBRARY_RELEASE})
endif()

# if only one debug/release variant is found, set the other to be equal to the found one
if (GLTF2-LOADER_LIBRARY_DEBUG AND NOT GLTF2-LOADER_LIBRARY_RELEASE)
    set(GLTF2-LOADER_LIBRARY_RELEASE ${GLTF2-LOADER_LIBRARY_DEBUG})
    set(GLTF2-LOADER_LIBRARY ${GLTF2-LOADER_LIBRARY_DEBUG})
endif()

if (NOT GLTF2-LOADER_LIBRARY_DEBUG AND GLTF2-LOADER_LIBRARY_RELEASE)
    set(GLTF2-LOADER_LIBRARY_DEBUG ${GLTF2-LOADER_LIBRARY_RELEASE})
    set(GLTF2-LOADER_LIBRARY ${GLTF2-LOADER_LIBRARY_RELEASE})
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GLTF2-Loader FOUND_VAR GLTF2-LOADER_FOUND REQUIRED_VARS GLTF2-LOADER_LIBRARY GLTF2-LOADER_INCLUDE_DIR)

mark_as_advanced(GLTF2-LOADER_INCLUDE_DIR GLTF2-LOADER_LIBRARY)
