find_package(PkgConfig)
pkg_check_modules(LIBDRM libdrm)
if(LIBDRM_FOUND)
  if(NOT TARGET LIBDRM::LIBDRM)
    add_library(LIBDRM::LIBDRM UNKNOWN IMPORTED)

    set_target_properties(LIBDRM::LIBDRM PROPERTIES
      INTERFACE_INCLUDE_DIRECTORIES "${LIBDRM_INCLUDE_DIRS}"
      IMPORTED_LOCATION "${LIBDRM_LINK_LIBRARIES}")
  endif()
endif()

find_path(LIBVA_INCLUDE_DIR NAMES va/va.h PATHS "${LIBVA_ROOT_DIR}/include" NO_DEFAULT_PATH)
find_library(LIBVA_LIBRARY NAMES va PATHS "${LIBVA_ROOT_DIR}/lib" NO_DEFAULT_PATH)
find_library(LIBVA_DRM_LIBRARY NAMES va-drm PATHS "${LIBVA_ROOT_DIR}/lib" NO_DEFAULT_PATH)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LIBVA DEFAULT_MSG LIBVA_LIBRARY LIBVA_DRM_LIBRARY LIBVA_INCLUDE_DIR)

mark_as_advanced(LIBVA_INCLUDE_DIR LIBVA_LIBRARY LIBVA_DRM_LIBRARY)

if(LIBVA_FOUND)
  if(NOT TARGET LIBVA::LIBVA)
    add_library(LIBVA::LIBVA UNKNOWN IMPORTED)

    set_target_properties(LIBVA::LIBVA PROPERTIES
      INTERFACE_INCLUDE_DIRECTORIES "${LIBVA_INCLUDE_DIR}"
      IMPORTED_LOCATION "${LIBVA_LIBRARY}")
  endif()
  if(NOT TARGET LIBVA::LIBVA_DRM)
    add_library(LIBVA::LIBVA_DRM UNKNOWN IMPORTED)

    target_link_libraries(LIBVA::LIBVA_DRM INTERFACE LIBDRM::LIBDRM)
    set_target_properties(LIBVA::LIBVA_DRM PROPERTIES
      INTERFACE_INCLUDE_DIRECTORIES "${LIBVA_INCLUDE_DIR}"
      IMPORTED_LOCATION "${LIBVA_DRM_LIBRARY}")
  endif()
endif()