#-----------------------------------------------------------------------------
# H4H5 Config file for compiling against H4H5 build directory
#-----------------------------------------------------------------------------
@PACKAGE_INIT@

string(TOUPPER @H4H5_PACKAGE@ H4H5_PACKAGE_NAME)

set (${H4H5_PACKAGE_NAME}_VALID_COMPONENTS
    static
    shared
    C
)

#-----------------------------------------------------------------------------
# User Options
#-----------------------------------------------------------------------------
set (${H4H5_PACKAGE_NAME}_ENABLE_PARALLEL @HDF_ENABLE_PARALLEL@)
set (${H4H5_PACKAGE_NAME}_BUILD_TOOLS     @HDF_BUILD_TOOLS@)
set (${H4H5_PACKAGE_NAME}_PACKAGE_EXTLIBS      @HDF_PACKAGE_EXTLIBS@)
set (${H4H5_PACKAGE_NAME}_EXPORT_LIBRARIES @HDF_LIBRARIES_TO_EXPORT@)
set (${H4H5_PACKAGE_NAME}_BUILD_SHARED_LIBS       @BUILD_SHARED_LIBS@)
set (${H4H5_PACKAGE_NAME}_ENABLE_JPEG_LIB_SUPPORT @HDF_ENABLE_JPEG_LIB_SUPPORT@)
set (${H4H5_PACKAGE_NAME}_ENABLE_Z_LIB_SUPPORT @HDF_ENABLE_Z_LIB_SUPPORT@)
set (${H4H5_PACKAGE_NAME}_ENABLE_SZIP_SUPPORT  @HDF_ENABLE_SZIP_SUPPORT@)
set (${H4H5_PACKAGE_NAME}_ENABLE_SZIP_ENCODING @HDF_ENABLE_SZIP_ENCODING@)
set (${H4H5_PACKAGE_NAME}_EXPORT_LIBRARIES @H4H5_LIBRARIES_TO_EXPORT@)
set (${H4H5_PACKAGE_NAME}_TOOLSET "@CMAKE_GENERATOR_TOOLSET@")

#-----------------------------------------------------------------------------
# Directories
#-----------------------------------------------------------------------------
set (${H4H5_PACKAGE_NAME}_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")

set (${H4H5_PACKAGE_NAME}_SHARE_DIR "@PACKAGE_SHARE_INSTALL_DIR@")
set_and_check (${H4H5_PACKAGE_NAME}_BUILD_DIR "@PACKAGE_CURRENT_BUILD_DIR@")

if (${H4H5_PACKAGE_NAME}_BUILD_TOOLS)
  set (${H4H5_PACKAGE_NAME}_INCLUDE_DIR_TOOLS "@PACKAGE_INCLUDE_INSTALL_DIR@")
  set_and_check (${H4H5_PACKAGE_NAME}_TOOLS_DIR "@PACKAGE_CURRENT_BUILD_DIR@/bin")
endif ()

#-----------------------------------------------------------------------------
# Version Strings
#-----------------------------------------------------------------------------
set (H4H5_VERSION_STRING @H4H5_VERSION_STRING@)
set (H4H5_VERSION_MAJOR  @H4H5_VERSION_MAJOR@)
set (H4H5_VERSION_MINOR  @H4H5_VERSION_MINOR@)

#-----------------------------------------------------------------------------
# Don't include targets if this file is being picked up by another
# project which has already built h4h5 as a subproject
#-----------------------------------------------------------------------------
if (NOT TARGET "@H4H5_PACKAGE@")
  if (${H4H5_PACKAGE_NAME}_ENABLE_JPEG_LIB_SUPPORT AND ${H4H5_PACKAGE_NAME}_PACKAGE_EXTLIBS AND NOT TARGET "jpeg")
    include (@PACKAGE_SHARE_INSTALL_DIR@/@JPEG_PACKAGE_NAME@@HDF_PACKAGE_EXT@-targets.cmake)
  endif ()
  if (${H4H5_PACKAGE_NAME}_ENABLE_Z_LIB_SUPPORT AND ${H4H5_PACKAGE_NAME}_PACKAGE_EXTLIBS AND NOT TARGET "zlib")
    include (@PACKAGE_SHARE_INSTALL_DIR@/@ZLIB_PACKAGE_NAME@@HDF_PACKAGE_EXT@-targets.cmake)
  endif ()
  if (${H4H5_PACKAGE_NAME}_ENABLE_SZIP_SUPPORT AND ${H4H5_PACKAGE_NAME}_PACKAGE_EXTLIBS AND NOT TARGET "szip")
    include (@PACKAGE_SHARE_INSTALL_DIR@/@SZIP_PACKAGE_NAME@@HDF_PACKAGE_EXT@-targets.cmake)
  endif ()
  if (${H4H5_PACKAGE_NAME}_ENABLE_HDF4_LIB_SUPPORT AND ${H4H5_PACKAGE_NAME}_PACKAGE_EXTLIBS AND NOT TARGET "hdf4")
    include (@PACKAGE_SHARE_INSTALL_DIR@/@HDF4_PACKAGE_NAME@@HDF_PACKAGE_EXT@-targets.cmake)
  endif ()
  if (${H4H5_PACKAGE_NAME}_ENABLE_HDF5_LIB_SUPPORT AND ${H4H5_PACKAGE_NAME}_PACKAGE_EXTLIBS AND NOT TARGET "hdf5")
    include (@PACKAGE_SHARE_INSTALL_DIR@/@HDF5_PACKAGE_NAME@@HDF_PACKAGE_EXT@-targets.cmake)
  endif ()
  include (@PACKAGE_SHARE_INSTALL_DIR@/@H4H5_PACKAGE@@HDF_PACKAGE_EXT@-targets.cmake)
endif ()

# Handle default component :
if (NOT ${H4H5_PACKAGE_NAME}_FIND_COMPONENTS)
    set (${H4H5_PACKAGE_NAME}_LIB_TYPE)
    set (${H4H5_PACKAGE_NAME}_FIND_COMPONENTS C static)
    set (${H4H5_PACKAGE_NAME}_FIND_REQUIRED_static_C true)
endif ()

# Handle requested components:
list (REMOVE_DUPLICATES ${H4H5_PACKAGE_NAME}_FIND_COMPONENTS)
foreach (comp IN LISTS ${H4H5_PACKAGE_NAME}_FIND_COMPONENTS)
  if (${comp} STREQUAL "shared")
    list (REMOVE_ITEM ${H4H5_PACKAGE_NAME}_FIND_COMPONENTS ${comp})
    set (${H4H5_PACKAGE_NAME}_LIB_TYPE ${${H4H5_PACKAGE_NAME}_LIB_TYPE} ${comp})
  elseif (${comp} STREQUAL "static")
    list (REMOVE_ITEM ${H4H5_PACKAGE_NAME}_FIND_COMPONENTS ${comp})
    set (${H4H5_PACKAGE_NAME}_LIB_TYPE ${${H4H5_PACKAGE_NAME}_LIB_TYPE} ${comp})
  endif ()
endforeach ()
foreach (libtype IN LISTS ${H4H5_PACKAGE_NAME}_LIB_TYPE)
  foreach (comp IN LISTS ${H4H5_PACKAGE_NAME}_FIND_COMPONENTS)
    if (${comp} STREQUAL "C")
      set (h4h5_comp "h4h5")
    endif ()
    list (FIND ${H4H5_PACKAGE_NAME}_EXPORT_LIBRARIES "${h4h5_comp}-${libtype}" HAVE_COMP)
    if (${HAVE_COMP} LESS 0)
      set (${H4H5_PACKAGE_NAME}_${libtype}_${comp}_FOUND 0)
    else ()
      set (${H4H5_PACKAGE_NAME}_${libtype}_${comp}_FOUND 1)
      string(TOUPPER ${H4H5_PACKAGE_NAME}_${comp}_${libtype}_LIBRARY COMP_LIBRARY)
      set (${COMP_LIBRARY} ${${COMP_LIBRARY}} @H4H5_PACKAGE@::${h4h5_comp}-${libtype})
    endif ()
  endforeach ()
endforeach ()

foreach (libtype IN LISTS ${H4H5_PACKAGE_NAME}_LIB_TYPE)
  check_required_components(${H4H5_PACKAGE_NAME}_${libtype})
endforeach ()
