if (CMAKE_VERSION VERSION_LESS "3.9")
  message(FATAL_ERROR "Diy requires CMake 3.9+")
endif()

@PACKAGE_INIT@

set(threads "@threads@")
set(log "@log@")
set(caliper "@caliper@")
set(mpi "@mpi@")

include("${CMAKE_CURRENT_LIST_DIR}/diy-targets.cmake")

set(_diy_find_quietly)
if (${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
  set(_diy_find_quietly QUIET)
endif()

if (threads)
  find_package(Threads ${_diy_find_quietly})
  if (NOT Threads_FOUND)
    list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE" "Threads not found")
    set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0)
  endif()
endif()

if (log)
  find_path(SPDLOG_INCLUDE_DIR "spdlog/spdlog.h")
  if (SPDLOG_INCLUDE_DIR STREQUAL "SPDLOG_INCLUDE_DIR-NOTFOUND")
    list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE" "SPDLOG not found")
    set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0)
  else()
    target_include_directories(DIY::@diy_prefix@ INTERFACE $<INSTALL_INTERFACE:${SPDLOG_INCLUDE_DIR}>)
  endif()
endif()

if (caliper)
  find_package(caliper ${_diy_find_quietly})
  if (NOT caliper_FOUND)
    list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE" "Caliper not found")
    set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0)
  else()
    target_include_directories(DIY::@diy_prefix@ INTERFACE $<INSTALL_INTERFACE:${caliper_INCLUDE_DIR}>)
  endif()
endif()

if (mpi)
  find_package(MPI ${_diy_find_quietly})
  if (NOT MPI_FOUND)
    list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE" "MPI not found")
    set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0)
  endif()
endif()

if (NOT DEFINED "${CMAKE_FIND_PACKAGE_NAME}_FOUND")
  set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 1)
endif ()
