#-----------------------------------------------------------------------------
# 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
)

#-----------------------------------------------------------------------------
# User Options
#-----------------------------------------------------------------------------
set (${HDF4_PACKAGE_NAME}_BUILD_FORTRAN   @HDF4_BUILD_FORTRAN@)
set (${HDF4_PACKAGE_NAME}_BUILD_JAVA      @HDF4_BUILD_JAVA@)
set (${HDF4_PACKAGE_NAME}_BUILD_XDR_LIB   @HDF4_BUILD_XDR_LIB@)
set (${HDF4_PACKAGE_NAME}_BUILD_TOOLS     @HDF4_BUILD_TOOLS@)
set (${HDF4_PACKAGE_NAME}_BUILD_UTILS     @HDF4_BUILD_UTILS@)
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}_BUILD_SHARED_LIBS    @BUILD_SHARED_LIBS@)
set (${HDF4_PACKAGE_NAME}_PACKAGE_EXTLIBS      @HDF4_PACKAGE_EXTLIBS@)
set (${HDF4_PACKAGE_NAME}_EXPORT_LIBRARIES @HDF4_LIBRARIES_TO_EXPORT@)
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-1.7.5.jar
      @PACKAGE_CURRENT_BUILD_DIR@/lib/slf4j-nop-1.7.5.jar
  )
  set (${HDF4_PACKAGE_NAME}_JAVA_LIBRARY "@PACKAGE_CURRENT_BUILD_DIR@/lib")
  set (${HDF4_PACKAGE_NAME}_JAVA_LIBRARIES "${${HDF4_PACKAGE_NAME}_JAVA_LIBRARY}")
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 AND NOT TARGET "jpeg")
    include (@PACKAGE_SHARE_INSTALL_DIR@/@JPEG_PACKAGE_NAME@/@JPEG_PACKAGE_NAME@@HDF_PACKAGE_EXT@-targets.cmake)
  endif ()
  if (${HDF4_PACKAGE_NAME}_ENABLE_Z_LIB_SUPPORT AND ${HDF4_PACKAGE_NAME}_PACKAGE_EXTLIBS AND NOT TARGET "zlib")
    include (@PACKAGE_SHARE_INSTALL_DIR@/@ZLIB_PACKAGE_NAME@/@ZLIB_PACKAGE_NAME@@HDF_PACKAGE_EXT@-targets.cmake)
  endif ()
  if (${HDF4_PACKAGE_NAME}_ENABLE_SZIP_SUPPORT AND ${HDF4_PACKAGE_NAME}_PACKAGE_EXTLIBS AND NOT TARGET "szip")
    include (@PACKAGE_SHARE_INSTALL_DIR@/@SZIP_PACKAGE_NAME@/@SZIP_PACKAGE_NAME@@HDF_PACKAGE_EXT@-targets.cmake)
  endif ()
  include (@PACKAGE_SHARE_INSTALL_DIR@/@HDF4_PACKAGE@/@HDF4_PACKAGE@@HDF_PACKAGE_EXT@-targets.cmake)
endif ()

# Handle default component(static) :
if (NOT ${HDF4_PACKAGE_NAME}_FIND_COMPONENTS)
    set (${HDF4_PACKAGE_NAME}_LIB_TYPE)
    set (${HDF4_PACKAGE_NAME}_FIND_COMPONENTS C static)
    set (${HDF4_PACKAGE_NAME}_FIND_REQUIRED_static_C true)
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 "hdf4_java")
    elseif (${comp} STREQUAL "Fortran")
      set (hdf4_comp2 "hdf_fcstub")
      set (hdf4_comp "hdf_fortran")
    endif ()
    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}} @HDF4_PACKAGE@::${hdf4_comp2}-${libtype} @HDF4_PACKAGE@::${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}} @HDF4_PACKAGE@::${hdf4_comp}-${libtype} @HDF4_PACKAGE@::mf${hdf4_comp}-${libtype})
      endif ()
    endif ()
  endforeach ()
endforeach ()

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