#-----------------------------------------------------------------------------
# HDF4 Config file for compiling against hdf4 build/install directory
#-----------------------------------------------------------------------------
@PACKAGE_INIT@

string(TOUPPER @HDF4_PACKAGE@ HDF4_PACKAGE_NAME)

set (${HDF4_PACKAGE_NAME}_VALID_COMPONENTS
    static
    shared
    C
    Fortran
    Java
)

set (${HDF4_PACKAGE_NAME}_BUILD_MODE       @HDF_CFG_NAME@)

#-----------------------------------------------------------------------------
# User Options
#-----------------------------------------------------------------------------
# Languages:
#-----------------------------------------------------------------------------
set (${HDF4_PACKAGE_NAME}_BUILD_FORTRAN           @HDF4_BUILD_FORTRAN@)
set (${HDF4_PACKAGE_NAME}_BUILD_JAVA              @HDF4_BUILD_JAVA@)
#-----------------------------------------------------------------------------
# Features:
#-----------------------------------------------------------------------------
set (${HDF4_PACKAGE_NAME}_BUILD_SHARED_LIBS       @H4_ENABLE_SHARED_LIB@)
set (${HDF4_PACKAGE_NAME}_BUILD_STATIC_LIBS       @H4_ENABLE_STATIC_LIB@)
#-----------------------------------------------------------------------------
set (${HDF4_PACKAGE_NAME}_BUILD_TOOLS             @HDF4_BUILD_TOOLS@)
set (${HDF4_PACKAGE_NAME}_BUILD_UTILS             @HDF4_BUILD_UTILS@)
set (${HDF4_PACKAGE_NAME}_BUILD_STATIC_TOOLS      @HDF4_BUILD_STATIC_TOOLS@)
#-----------------------------------------------------------------------------
set (${HDF4_PACKAGE_NAME}_ENABLE_JPEG_LIB_SUPPORT @HDF4_ENABLE_JPEG_LIB_SUPPORT@)
set (${HDF4_PACKAGE_NAME}_ENABLE_Z_LIB_SUPPORT    @HDF4_ENABLE_Z_LIB_SUPPORT@)
set (${HDF4_PACKAGE_NAME}_ENABLE_SZIP_SUPPORT     @HDF4_ENABLE_SZIP_SUPPORT@)
set (${HDF4_PACKAGE_NAME}_ENABLE_SZIP_ENCODING    @HDF4_ENABLE_SZIP_ENCODING@)
#-----------------------------------------------------------------------------
set (${HDF4_PACKAGE_NAME}_PACKAGE_EXTLIBS         @HDF4_PACKAGE_EXTLIBS@)
set (${HDF4_PACKAGE_NAME}_EXPORT_LIBRARIES        @HDF4_LIBRARIES_TO_EXPORT@)
set (${HDF4_PACKAGE_NAME}_ARCHITECTURE            "@CMAKE_GENERATOR_ARCHITECTURE@")
set (${HDF4_PACKAGE_NAME}_TOOLSET                 "@CMAKE_GENERATOR_TOOLSET@")

#-----------------------------------------------------------------------------
# Dependencies
#-----------------------------------------------------------------------------
if (${HDF4_PACKAGE_NAME}_BUILD_JAVA)
  set (${HDF4_PACKAGE_NAME}_JAVA_INCLUDE_DIRS
      @PACKAGE_CURRENT_BUILD_DIR@/lib/jarhdf-@HDF4_VERSION_STRING@.jar
      @PACKAGE_CURRENT_BUILD_DIR@/lib/slf4j-api-2.0.16.jar
      @PACKAGE_CURRENT_BUILD_DIR@/lib/slf4j-nop-2.0.16.jar
  )
endif ()

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

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

if (${HDF4_PACKAGE_NAME}_BUILD_FORTRAN)
  set (${HDF4_PACKAGE_NAME}_INCLUDE_DIR_FORTRAN "@PACKAGE_INCLUDE_INSTALL_DIR@" )
endif ()

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


if (${HDF4_PACKAGE_NAME}_BUILD_UTILS)
  set (${HDF4_PACKAGE_NAME}_INCLUDE_DIR_UTILS "@PACKAGE_INCLUDE_INSTALL_DIR@" )
  set_and_check (${HDF4_PACKAGE_NAME}_UTILS_DIR "@PACKAGE_CURRENT_BUILD_DIR@/bin" )
endif ()

#-----------------------------------------------------------------------------
# Version Strings
#-----------------------------------------------------------------------------
set (${HDF4_PACKAGE_NAME}_VERSION_STRING @HDF4_VERSION_STRING@)
set (${HDF4_PACKAGE_NAME}_VERSION_MAJOR  @HDF4_VERSION_MAJOR@)
set (${HDF4_PACKAGE_NAME}_VERSION_MINOR  @HDF4_VERSION_MINOR@)

#-----------------------------------------------------------------------------
# Don't include targets if this file is being picked up by another
# project which has already built hdf4 as a subproject
#-----------------------------------------------------------------------------
if (NOT TARGET "@HDF4_PACKAGE@")
  if (${HDF4_PACKAGE_NAME}_ENABLE_JPEG_LIB_SUPPORT AND ${HDF4_PACKAGE_NAME}_PACKAGE_EXTLIBS)
    include (@PACKAGE_SHARE_INSTALL_DIR@/@JPEG_PACKAGE_NAME@@HDF_PACKAGE_EXT@-targets.cmake)
  endif ()
  if (${HDF4_PACKAGE_NAME}_ENABLE_Z_LIB_SUPPORT AND ${HDF4_PACKAGE_NAME}_PACKAGE_EXTLIBS)
    include (@PACKAGE_SHARE_INSTALL_DIR@/@ZLIB_PACKAGE_NAME@@HDF_PACKAGE_EXT@-targets.cmake)
  endif ()
  if (${HDF4_PACKAGE_NAME}_ENABLE_SZIP_SUPPORT AND ${HDF4_PACKAGE_NAME}_PACKAGE_EXTLIBS)
    include (@PACKAGE_SHARE_INSTALL_DIR@/@LIBAEC_PACKAGE_NAME@@HDF_PACKAGE_EXT@-targets.cmake)
  endif ()
  include (@PACKAGE_SHARE_INSTALL_DIR@/@HDF4_PACKAGE@@HDF_PACKAGE_EXT@-targets.cmake)
endif ()

# Handle default component(static) :
if (NOT ${HDF4_PACKAGE_NAME}_FIND_COMPONENTS)
  if (${HDF4_PACKAGE_NAME}_BUILD_STATIC_LIBS)
    set (${HDF4_PACKAGE_NAME}_LIB_TYPE)
    set (${HDF4_PACKAGE_NAME}_FIND_COMPONENTS C static)
    set (${HDF4_PACKAGE_NAME}_FIND_REQUIRED_static_C true)
  else ()
    set (${HDF4_PACKAGE_NAME}_LIB_TYPE)
    set (${HDF4_PACKAGE_NAME}_FIND_COMPONENTS C shared)
    set (${HDF4_PACKAGE_NAME}_FIND_REQUIRED_shared_C true)
  endif ()
endif ()

# Handle requested components:
list (REMOVE_DUPLICATES ${HDF4_PACKAGE_NAME}_FIND_COMPONENTS)
foreach (comp IN LISTS ${HDF4_PACKAGE_NAME}_FIND_COMPONENTS)
  if (comp STREQUAL "shared")
    list (REMOVE_ITEM ${HDF4_PACKAGE_NAME}_FIND_COMPONENTS ${comp})
    set (${HDF4_PACKAGE_NAME}_LIB_TYPE ${${HDF4_PACKAGE_NAME}_LIB_TYPE} ${comp})
  elseif (comp STREQUAL "static")
    list (REMOVE_ITEM ${HDF4_PACKAGE_NAME}_FIND_COMPONENTS ${comp})
    set (${HDF4_PACKAGE_NAME}_LIB_TYPE ${${HDF4_PACKAGE_NAME}_LIB_TYPE} ${comp})
  endif ()
endforeach ()
foreach (libtype IN LISTS ${HDF4_PACKAGE_NAME}_LIB_TYPE)
  foreach (comp IN LISTS ${HDF4_PACKAGE_NAME}_FIND_COMPONENTS)
    set (hdf4_comp2)
    if (comp STREQUAL "C")
      set (hdf4_comp "hdf")
    elseif (comp STREQUAL "Java")
      set (hdf4_comp "hdf_java")
    elseif (comp STREQUAL "Fortran")
      set (hdf4_comp2 "hdf_fcstub")
      set (hdf4_comp "hdf_fortran")
    endif ()
    if (comp STREQUAL "Java")
      list (FIND ${HDF4_PACKAGE_NAME}_EXPORT_LIBRARIES "${hdf4_comp}" HAVE_COMP)
      if (${HAVE_COMP} LESS 0)
        set (${HDF4_PACKAGE_NAME}_${comp}_FOUND 0)
      else ()
        set (${HDF4_PACKAGE_NAME}_${comp}_FOUND 1)
        string(TOUPPER ${HDF4_PACKAGE_NAME}_${comp}_LIBRARY COMP_LIBRARY)
        set (${COMP_LIBRARY} ${${COMP_LIBRARY}} @HDF4_PACKAGE@::${hdf4_comp})
      endif ()
    else ()
      list (FIND ${HDF4_PACKAGE_NAME}_EXPORT_LIBRARIES "${hdf4_comp}-${libtype}" HAVE_COMP)
      list (FIND ${HDF4_PACKAGE_NAME}_EXPORT_LIBRARIES "mf${hdf4_comp}-${libtype}" HAVE_MFCOMP)
      if (${HAVE_COMP} LESS 0 OR ${HAVE_MFCOMP} LESS 0)
        set (${HDF4_PACKAGE_NAME}_${libtype}_${comp}_FOUND 0)
      else ()
        if (hdf4_comp2)
          list (FIND ${HDF4_PACKAGE_NAME}_EXPORT_LIBRARIES "${hdf4_comp2}-${libtype}" HAVE_COMP2)
          list (FIND ${HDF4_PACKAGE_NAME}_EXPORT_LIBRARIES "mf${hdf4_comp2}-${libtype}" HAVE_MFCOMP2)
          if (${HAVE_COMP2} LESS 0 OR ${HAVE_MFCOMP2} LESS 0)
            set (${HDF4_PACKAGE_NAME}_${libtype}_${comp}_FOUND 0)
          else ()
            set (${HDF4_PACKAGE_NAME}_${libtype}_${comp}_FOUND 1)
            string(TOUPPER ${HDF4_PACKAGE_NAME}_${comp}_${libtype}_LIBRARY COMP_LIBRARY)
            set (${COMP_LIBRARY} ${${COMP_LIBRARY}} @HDF_PACKAGE_NAMESPACE@${hdf4_comp2}-${libtype} @HDF_PACKAGE_NAMESPACE@${hdf4_comp}-${libtype} @HDF4_PACKAGE@::mf${hdf4_comp2}-${libtype} @HDF4_PACKAGE@::mf${hdf4_comp}-${libtype})
          endif ()
        else ()
          set (${HDF4_PACKAGE_NAME}_${libtype}_${comp}_FOUND 1)
          string(TOUPPER ${HDF4_PACKAGE_NAME}_${comp}_${libtype}_LIBRARY COMP_LIBRARY)
          set (${COMP_LIBRARY} ${${COMP_LIBRARY}} @HDF_PACKAGE_NAMESPACE@${hdf4_comp}-${libtype} @HDF_PACKAGE_NAMESPACE@mf${hdf4_comp}-${libtype})
        endif ()
      endif ()
    endif ()
  endforeach ()
endforeach ()

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