if(POLICY CMP0028)
  cmake_policy(SET CMP0028 NEW)
endif()

if(POLICY CMP0074)
  cmake_policy(SET CMP0074 NEW)
endif()

include(CMakeFindDependencyMacro)

enable_language(C)
enable_language(CXX)

set(ADIOS2_HAVE_Fortran )
if(ADIOS2_HAVE_Fortran)
  enable_language(Fortran)
endif()

set(ADIOS2_HAVE_MPI TRUE)
if(ADIOS2_HAVE_MPI)
  find_dependency(MPI)
endif()

if(NOT ON)
  set(ADIOS2_HAVE_BZip2 )
  if(ADIOS2_HAVE_BZip2)
    find_dependency(BZip2)
  endif()

  set(ADIOS2_HAVE_ZFP )
  if(ADIOS2_HAVE_ZFP)
    find_dependency(zfp)
  endif()
  
  set(ADIOS2_HAVE_MGARD )
  if(ADIOS2_HAVE_MGARD)
    find_dependency(MGARD)
  endif()

  set(ADIOS2_HAVE_DataSpaces )
  if(ADIOS2_HAVE_DataSpaces)
    find_dependency(DataSpaces)
  endif()

  set(ADIOS2_HAVE_ZeroMQ )
  if(ADIOS2_HAVE_ZeroMQ)
    find_dependency(ZeroMQ)
  endif()

  set(ADIOS2_HAVE_HDF5 )
  if(ADIOS2_HAVE_HDF5)
    find_dependency(HDF5 COMPONENTS C)
  endif()

  set(ADIOS2_HAVE_SST )
  if(ADIOS2_HAVE_SST)
    set(ADIOS2_SST_HAVE_LIBFABRIC )
    if(ADIOS2_SST_HAVE_LIBFABRIC)
      find_dependency(LIBFABRIC)
    endif()

    find_dependency(EVPath COMPONENTS C)
    add_library(adios2::thirdparty::EVPath INTERFACE IMPORTED)
    set_target_properties(adios2::thirdparty::EVPath PROPERTIES
      INTERFACE_LINK_LIBRARIES EVPath::EVPath
    )
  endif()

endif()

include("${CMAKE_CURRENT_LIST_DIR}/adios2-config-version.cmake")

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(${CMAKE_FIND_PACKAGE_NAME} CONFIG_MODE)

if(NOT TARGET adios2::adios2)
  include("${CMAKE_CURRENT_LIST_DIR}/adios2-targets.cmake")
endif()

# backwards compatibility for things that still use package variables
set(${CMAKE_FIND_PACKAGE_NAME}_INCLUDE_DIRS)
set(${CMAKE_FIND_PACKAGE_NAME}_LIBRARIES adios2::adios2)
