if(TARGET EasyAR::Sense)
  return()
endif()

if(WIN32)
  if(CMAKE_SIZEOF_VOID_P EQUAL 4)
    set(_package_root ${CMAKE_CURRENT_LIST_DIR}/Windows/x86)
  else()
    set(_package_root ${CMAKE_CURRENT_LIST_DIR}/Windows/x64)
  endif()

  add_library(EasyAR::Sense SHARED IMPORTED)
  set_target_properties(EasyAR::Sense PROPERTIES
    INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/include
    IMPORTED_IMPLIB ${_package_root}/EasyAR.lib
    IMPORTED_LOCATION ${_package_root}/EasyAR.dll
  )
elseif(ANDROID)
  set(_package_root ${CMAKE_CURRENT_LIST_DIR}/Android)

  add_library(EasyAR::Sense SHARED IMPORTED)
  set_target_properties(EasyAR::Sense PROPERTIES
    INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/include
    IMPORTED_LOCATION ${_package_root}/${ANDROID_ABI}/libEasyAR.so
  )

  add_library(EasyAR::Sense::JAR UNKNOWN IMPORTED)
  set_target_properties(EasyAR::Sense::JAR PROPERTIES
    IMPORTED_LOCATION ${_package_root}/EasyAR.jar
  )
elseif(IOS)
  set(_package_root ${CMAKE_CURRENT_LIST_DIR}/iOS)

  file(GLOB dirs RELATIVE ${_package_root} ${_package_root}/*/*.framework)
  foreach(dir ${dirs})
    get_filename_component(framework_type "${dir}" DIRECTORY)
    add_library(EasyARSense_${framework_type} INTERFACE)
    target_link_libraries(EasyARSense_${framework_type} INTERFACE ${_package_root}/${framework_type}/easyar.framework)
    add_library(EasyAR::Sense::${framework_type} ALIAS EasyARSense_${framework_type})

    if(framework_type MATCHES static)
      target_link_libraries(EasyARSense_${framework_type} INTERFACE
        "-framework AVFoundation"
        "-framework CoreGraphics"
        "-framework CoreImage"
        "-framework CoreMedia"
        "-framework CoreVideo"
        "-framework OpenGLES"
        "-framework UIKit"
        "-framework CoreMotion"
      )
      add_library(EasyAR::Sense::STATIC ALIAS EasyARSense_${framework_type})
    endif()
    if(framework_type MATCHES dynamic)
      add_library(EasyAR::Sense::SHARED ALIAS EasyARSense_${framework_type})
    endif()
  endforeach()

  add_library(EasyARSense_headers INTERFACE)
  target_include_directories(EasyARSense_headers INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
  add_library(EasyAR::Sense::Headers ALIAS EasyARSense_headers)

  if(TARGET EasyARSense_static)
    add_library(EasyAR::Sense ALIAS EasyARSense_static)
  elseif(TARGET EasyARSense_dynamic)
    add_library(EasyAR::Sense ALIAS EasyARSense_dynamic)
  else()
    add_library(EasyAR::Sense ALIAS EasyARSense_headers)
  endif()
else(CMAKE_SYSTEM_NAME STREQUAL Darwin)
  set(_package_root ${CMAKE_CURRENT_LIST_DIR}/MacOS)

  add_library(EasyAR::Sense SHARED IMPORTED)
  if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL arm64)
    set_target_properties(EasyAR::Sense PROPERTIES
      INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/include
      IMPORTED_LOCATION ${_package_root}/arm64/libEasyAR.dylib
    )
  else()
    set_target_properties(EasyAR::Sense PROPERTIES
      INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/include
      IMPORTED_LOCATION ${_package_root}/x64/libEasyAR.dylib
    )
  endif()
endif()
