cmake_minimum_required(VERSION 2.8.0)

#move here bedore project, otherwise SET(CMAKE_INSTALL_PREFIX < install_path>) will not work
if(NOT CMAKE_INSTALL_PREFIX)
  # if CMAKE_INSTALL_PREFIX isn't set, try to get it from the INSTALL_PREFIX environment variable
  set(CMAKE_INSTALL_PREFIX $ENV{INSTALL_PREFIX} CACHE PATH "Prefix prepended to install directories" FORCE)
endif()

project(ADIOS_PROJECT)

SET_PROPERTY(GLOBAL PROPERTY ALLOW_DUPLICATE_CUSTOM_TARGETS 1)

#set(LANGUAGE "" CACHE FILEPATH "")  #C/CXX/Fortran

#enable_language(${LANGUAGE})
#message(STATUS "CMAKE_${LANGUAGE}_COMPILER_WORKS = ${CMAKE_${LANGUAGE}_COMPILER_WORKS}")

include_directories(${PROJECT_SOURCE_DIR})
link_directories(${PROJECT_BINARY_DIR})
#message("${PROJECT_SOURCE_DIR}")

#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})

#if(NOT CMAKE_INSTALL_PREFIX)
#  set(CMAKE_INSTALL_PREFIX $ENV{INSTALL_PREFIX} CACHE PATH "Prefix prepended to install directories" FORCE)
#endif()

set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${prefix})
set(bindir ${exec_prefix}/bin)
#set(datadir ${prefix}/share)
set(libdir ${exec_prefix}/lib)
set(includedir ${prefix}/include)
set(sysconfdir ${prefix}/etc)

#set(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
find_package(PythonInterp)
#message(STATUS "PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}")
#message(STATUS "PYTHONINTERP_FOUND = ${PYTHONINTERP_FOUND}")
#message(STATUS "PYTHON_VERSION_STRING = ${PYTHON_VERSION_STRING}")
#message(STATUS "PYTHON_VERSION_MAJOR = ${PYTHON_VERSION_MAJOR}")
if (NOT PYTHONINTERP_FOUND OR NOT ${PYTHON_VERSION_MAJOR} GREATER 1)
    message(FATAL_ERROR "Python 2.x or 3.x is required to build ADIOS.")
else()
    message(STATUS "Python ${PYTHON_VERSION_STRING} will be used in building ADIOS")
endif()



if(DEFINED ENV{MACRODEFFLAG})
  set(MACRODEFFLAG $ENV{MACRODEFFLAG})
else()
  set(MACRODEFFLAG "-D")
endif()
message(STATUS "MACRODEFFLAG = ${MACRODEFFLAG}")

set(LIBS "")
set(CPPFLAGS "$ENV{CPPFLAGS}")
set(CFLAGS "$ENV{CFLAGS}")
if(DEFINED ENV{EXTRA_CFLAGS})
    set(EXTRA_CFLAGS "$ENV{EXTRA_CFLAGS}")
endif()
if(DEFINED ENV{EXTRA_LIBS})
    set(EXTRA_LIBS "$ENV{EXTRA_LIBS}")
endif()
######## file moved from initial_cache.cmake to indicate external library is used(ON) or not (OFF)######
if(DEFINED ENV{BUILD_WRITE})
  if("$ENV{BUILD_WRITE}" STREQUAL "")
    set(BUILD_WRITE ON CACHE BOOL "")
  else()
    set(BUILD_WRITE $ENV{BUILD_WRITE})
  endif()
  if(BUILD_WRITE)
    set(BUILD_WRITE ON CACHE BOOL "")
  else()
    set(BUILD_WRITE OFF CACHE BOOL "")
  endif()
else()
  set(BUILD_WRITE ON CACHE BOOL "")
endif()

if(DEFINED ENV{BUILD_FORTRAN})
  if("$ENV{BUILD_FORTRAN}" STREQUAL "")
    set(BUILD_FORTRAN ON CACHE BOOL "")
  else()
    set(BUILD_FORTRAN $ENV{BUILD_FORTRAN})
  endif()
  if(BUILD_FORTRAN)
    set(BUILD_FORTRAN ON CACHE BOOL "")
  else()
    set(BUILD_FORTRAN OFF CACHE BOOL "")
  endif()
else()
  set(BUILD_FORTRAN ON CACHE BOOL "")
endif()

if(DEFINED ENV{adios_timers})
  if("$ENV{adios_timers}" STREQUAL "")
    set(ADIOS_TIMERS 0)
  elseif("$ENV{adios_timers}" STREQUAL "ON")
    set(ADIOS_TIMERS 1)
  elseif("$ENV{adios_timers}" STREQUAL "on")
    set(ADIOS_TIMERS 1)
  elseif("$ENV{adios_timers}" STREQUAL "OFF")
    set(ADIOS_TIMERS 0)
  elseif("$ENV{adios_timers}" STREQUAL "off")
    set(ADIOS_TIMERS 0)
  else()
    set(ADIOS_TIMERS 0)
  endif()
  if(ADIOS_TIMERS)
    set(SKEL_HAVE_ADIOS_TIMING True)
  else()
    set(SKEL_HAVE_ADIOS_TIMING False)
  endif()
else()
  # default is on if not specified
  set(ADIOS_TIMERS 1)
  set(SKEL_HAVE_ADIOS_TIMING True)
endif()

if(DEFINED ENV{adios_timer_events})
  if("$ENV{adios_timer_events}" STREQUAL "")
    set(ADIOS_TIMER_EVENTS 0)
  elseif("$ENV{adios_timer_events}" STREQUAL "ON")
    set(ADIOS_TIMER_EVENTS 1)
  elseif("$ENV{adios_timer_events}" STREQUAL "on")
    set(ADIOS_TIMER_EVENTS 1)
  elseif("$ENV{adios_timer_events}" STREQUAL "OFF")
    set(ADIOS_TIMER_EVENTS 0)
  elseif("$ENV{adios_timer_events}" STREQUAL "off")
    set(ADIOS_TIMER_EVENTS 0)
  else()
    set(ADIOS_TIMER_EVENTS 0)
  endif()
else()
  #default is off if not specified
  set(ADIOS_TIMER_EVENTS 0)
endif()

if(DEFINED ENV{bgq})
  if("$ENV{bgq}" STREQUAL "")
    set(HAVE_BGQ 0)
    set(BGQ OFF CACHE BOOL "")
  elseif("$ENV{bgq}" STREQUAL "ON")
    set(HAVE_BGQ 1)
    set(BGQ ON CACHE BOOL "")
  elseif("$ENV{bgq}" STREQUAL "on")
    set(HAVE_BGQ 1)
    set(BGQ ON CACHE BOOL "")
  elseif("$ENV{bgq}" STREQUAL "OFF")
    set(HAVE_BGQ 0)
    set(BGQ OFF CACHE BOOL "")
  elseif("$ENV{bgq}" STREQUAL "Off")
    set(HAVE_BGQ 0)
    set(BGQ OFF CACHE BOOL "")
  else()
    set(HAVE_BGQ 0)
    set(BGQ OFF CACHE BOOL "")
  endif()
else()
  set(HAVE_BGQ 0)
  set(BGQ OFF CACHE BOOL "")
endif()

if(DEFINED ENV{research_transports})
  if("$ENV{research_transports}" STREQUAL "")
    set(RESEARCH_TRANSPORTS 0)
    message("research_transports is NOT enabled")
  elseif("$ENV{research_transports}" STREQUAL "OFF")
    set(RESEARCH_TRANSPORTS 0)
    message("research_transports is NOT enabled")
  elseif("$ENV{research_transports}" STREQUAL "off")
    set(RESEARCH_TRANSPORTS 0)
    message("research_transports is NOT enabled")
  elseif("$ENV{research_transports}" STREQUAL "on")
    set(RESEARCH_TRANSPORTS 1)
    message("research_transports is enabled")
  elseif("$ENV{research_transports}" STREQUAL "ON")
    set(RESEARCH_TRANSPORTS 1)
    message("research_transports is enabled")
  else()
    set(RESEARCH_TRANSPORTS 0)
    message("research_transports is NOT enabled")
  endif()
else()
  set(RESEARCH_TRANSPORTS 0)
  message("research_transports is NOT enabled")
endif()

set(MXML_DIR $ENV{MXML_DIR}  CACHE FILEPATH "path to mxml dir")

set(DATATAP OFF CACHE BOOL "")

set(NSSI OFF CACHE BOOL "")

if(DEFINED ENV{SEQ_NC_DIR})
  if("$ENV{SEQ_NC_DIR}" STREQUAL "")
    set(NETCDF OFF CACHE BOOL "")
  else()
    set(NETCDF ON CACHE BOOL "")
    set(NETCDF_DIR "$ENV{SEQ_NC_DIR}" CACHE FILEPATH "path to suquential NETCDF dir")
  endif()
else()
  set(NETCDF OFF CACHE BOOL "")
endif()

if(DEFINED ENV{PAR_NC_DIR})
  if("$ENV{PAR_NC_DIR}" STREQUAL "")
    set(NC4PAR OFF CACHE BOOL "")
  else()
    set(NC4PAR ON CACHE BOOL "")
    set(NC4PAR_DIR "$ENV{PAR_NC_DIR}" CACHE FILEPATH "path to parallel NETCDFdir")
  endif()
else()
  set(NC4PAR OFF CACHE BOOL "")
endif()

#if(DEFINED ENV{PAR_NC_DIR} AND DEFINED ENV{PAR_NC_CLIB})
#  set(NC4PAR ON CACHE BOOL "")
#  set(NC4PAR_DIR $ENV{PAR_NC_DIR} CACHE FILEPATH "")
#  set(NC4PAR_CPPFLAGS "-I${NC4PAR_DIR}/include")
#  set(NC4PAR_LIBS $ENV{PAR_NC_CLIB} CACHE STRING "parallel netcdf")
#else()
#  set(NC4PAR OFF CACHE BOOL "")
#endif()

#if(DEFINED ENV{SEQ_NC_DIR} AND DEFINED ENV{SEQ_NC_CLIB})
#  set(NETCDF ON CACHE BOOL "")
#  set(NETCDF_DIR $ENV{SEQ_NC_DIR} CACHE FILEPATH "")
#  set(NETCDF_CPPFLAGS "-I${NETCDF_DIR}/include")
#  set(NETCDF_LIBS $ENV{SEQ_NC_CLIB} CACHE STRING "")
#else()
#  set(NETCDF OFF CACHE BOOL "")
#endif()

#if(DEFINED ENV{PAR_HDF5_DIR} AND DEFINED ENV{PAR_HDF5_CLIB})
#  set(PHDF5 ON CACHE BOOL "")
#  set(PHDF5_DIR $ENV{PAR_HDF5_DIR} CACHE FILEPATH "path to parallel hdf5 dir")
#  set(PHDF5_FLAGS "-I${PHDF5_DIR}/include")
#  set(PHDF5_LIBS $ENV{PAR_HDF5_CLIB} CACHE STRING "parallel hdf5")
#else()
#  set(PHDF5 OFF CACHE BOOL "")
#endif()

if(DEFINED ENV{PAR_HDF5_DIR})
  if("$ENV{PAR_HDF5_DIR}" STREQUAL "")
    set(PHDF5 OFF CACHE BOOL "")
  else()
    set(PHDF5 ON CACHE BOOL "")
    set(PHDF5_DIR $ENV{PAR_HDF5_DIR} CACHE FILEPATH "path to parallel hdf5 dir")
    set(PHDF5_FLAGS "-I${PHDF5_DIR}/include")
#   set(PHDF5_LIBS $ENV{PAR_HDF5_CLIB} CACHE STRING "parallel hdf5")
  endif()
else()
  set(PHDF5 OFF CACHE BOOL "")
endif()

if(DEFINED ENV{PORTALS_DIR})
  if("$ENV{PORTALS_DIR}" STREQUAL "")
    set(PORTALS OFF CACHE BOOL "")
  else()
    set(PORTALS_DIR "$ENV{PROTALS_DIR}" CACHE STRING "path to protals")
    set(PORTALS ON CACHE BOOL "")
  endif()
elseif(DEFINED ENV{PORTALS})
  if("$ENV{PORTALS}" STREQUAL "")
    set(PORTALS OFF CACHE BOOL "")
  else()
    set(PORTALS_DIR "$ENV{PROTALS}" CACHE STRING "path to protals")
    set(PORTALS ON CACHE BOOL "")
  endif()
else()
  set(PORTALS OFF CACHE BOOL "")
endif()

if(DEFINED ENV{DATASPACES_INCDIR})
  if("${DATASPACES_INCDIR}" STREQUAL "")
    set(DATASPACES OFF CACHE BOOL "")
  else()
    set(DATASPACES_INCDIR "$ENV{DATASPACES_INCDIR}" CACHE INTERNAL "Internal variable")
  endif()
else()
  set(DATASPACES OFF CACHE BOOL "")
endif()
if(DEFINED ENV{DATASPACES_LIBDIR})
  if("${DATASPACES_LIBDIR}" STREQUAL "")
    set(DATASPACES OFF CACHE BOOL "" FORCE)
  else()
    set(DATASPACES_LIBDIR $ENV{DATASPACES_LIBDIR} CACHE INTERNAL "Internal variable")
  endif()
else()
  set(DATASPACES OFF CACHE BOOL "" FORCE)
endif()
if(DEFINED DATASPACES_INCDIR)
  if(DEFINED DATASPACES_LIBDIR)
    set(DATASPACES ON CACHE BOOL "" FORCE)
    set(DATASPACES_INCDIR "$ENV{DATASPACES_INCDIR}" CACHE STRING "" FORCE)
    set(DATASPACES_LIBDIR $ENV{DATASPACES_LIBDIR} CACHE STRING "" FORCE)
  endif()
endif()
if("${DATASPACES}" STREQUAL "OFF")
  if(DEFINED ENV{DATASPACES_DIR})
    if(NOT "$ENV{DATASPACES_DIR}" STREQUAL "")
      set(DATASPACES ON CACHE BOOL "" FORCE)
      set(DATASPACES_DIR $ENV{DATASPACES_DIR} CACHE FILEPATH "path to dataspaces dir")
    endif()
#  set(DATASPACES_LIBS "-L$ENV{DATASPACES_DIR}/libs -ldspaces -ldscommon
#  -ldar" CACHE STRING "dataspace libs")
  else()
    if(NOT "$ENV{DATASPACES}" STREQUAL "")
      set(DATASPACES_DIR $ENV{DATASPACES} CACHE FILEPATH "path to dataspaces dir")
      set(DATASPACES ON CACHE BOOL "" FORCE)
    endif()
  endif()
endif()

if(DEFINED ENV{CRAY_PMI_DIR})
  set(CRAY_PMI_DIR $ENV{CRAY_PMI_DIR})
  if(CRAY_PMI_DIR)
    set(CRAY_PMI ON CACHE BOOL "")
    set(CRAY_PMI_LIBS_PATH "${CRAY_PMI_DIR}/lib64" CACHE STRING "")
    set(CRAY_PMI_CPPFLAGS "-I${CRAY_PMI_DIR}/include" CACHE STRING "")
  else()
    set(CRAY_PMI OFF CACHE BOOL "")
  endif()
else()
  set(CRAY_PMI OFF CACHE BOOL "")
endif()

if(DEFINED ENV{CRAY_UGNI_DIR})
  set(CRAY_UGNI_DIR $ENV{CRAY_UGNI_DIR})
  if(CRAY_UGNI_DIR)
    set(CRAY_UGNI ON CACHE BOOL "")
    set(CRAY_UGNI_LIBS_PATH "${CRAY_UGNI_DIR}/lib64" CACHE STRING "")
    set(CRAY_UGNI_CPPFLAGS "-I${CRAY_UGNI_DIR}/include")
  else()
    set(CRAY_UGNI OFF CACHE BOOL "")
  endif()
else()
  set(CRAY_UGNI OFF CACHE BOOL "")
endif()

if(DATASPACES)
  set(DIMES ON CACHE BOOL "")
else()
  set(DIMES OFF CACHE BOOL "")
endif()

if(DEFINED ENV{FLEXPATH_INCDIR})
  if("${FLEXPATH_INCDIR}" STREQUAL "")
    set(FLEXPATH OFF CACHE BOOL "")
  else()
    set(FLEXPATH_INCDIR "$ENV{FLEXPATH_INCDIR}" CACHE INTERNAL "Internal variable")
  endif()
else()
  set(FLEXPATH OFF CACHE BOOL "")
endif()
if(DEFINED ENV{FLEXPATH_LIBDIR})
  if("${FLEXPATH_LIBDIR}" STREQUAL "" FORCE)
    set(FLEXPATH OFF CACHE BOOL "")
  else()
    set(FLEXPATH_LIBDIR $ENV{FLEXPATH_LIBDIR} CACHE INTERNAL "Internal variable")
  endif()
else()
  set(FLEXPATH OFF CACHE BOOL "" FORCE)
endif()
if(DEFINED FLEXPATH_INCDIR)
  if(DEFINED FLEXPATH_LIBDIR)
    set(FLEXPATH ON CACHE BOOL "" FORCE)
    set(FLEXPATH_INCDIR "$ENV{FLEXPATH_INCDIR}" CACHE STRING "" FORCE)
    set(FLEXPATH_LIBDIR $ENV{FLEXPATH_LIBDIR} CACHE STRING "" FORCE)
  endif()
endif()
if("${FLEXPATH}" STREQUAL "OFF")
  if(DEFINED ENV{FLEXPATH_DIR})
    if(NOT "$ENV{FLEXPATH_DIR}" STREQUAL "")
      set(FLEXPATH ON CACHE BOOL "" FORCE)
      set(FLEXPATH_DIR $ENV{FLEXPATH_DIR} CACHE FILEPATH "path to flexpath dir")
    endif()
  else()
    if(NOT "$ENV{FLEXPATH}" STREQUAL "")
      set(FLEXPATH_DIR $ENV{FLEXPATH} CACHE FILEPATH "path to flexpath dir")
      set(FLEXPATH ON CACHE BOOL "" FORCE)
    endif()
  endif()
endif()

if(DEFINED ENV{FASTBIT_DIR})
  if(NOT "$ENV{FASTBIT_DIR}" STREQUAL "")
    set(FASTBIT ON CACHE BOOL "")
    set(FASTBIT_DIR "$ENV{FASTBIT_DIR}" CACHE FILEPATH "path to fastbit dir")
  else()
    set(FASTBIT OFF CACHE BOOL "")
  endif()
else()
  if(NOT "$ENV{FASTBIT}" STREQUAL "")
    set(FASTBIT_DIR $ENV{FASTBIT} CACHE FILEPATH "path to fastbit dir")
    set(FASTBIT ON CACHE BOOL "" FORCE)
  endif()
endif()

#if(DEFINED ENV{SEQ_HDF5_DIR} AND DEFINED ENV{SEQ_HDF5_CLIB})
#  set(HDF5 ON CACHE BOOL "")
#  set(HDF5_DIR "$ENV{SEQ_HDF5_DIR}" CACHE FILEPATH "path to hdf5 dir")
#  set(HDF5_FLAGS "-I${HDF5_DIR}/include")
#  set(HDF5_LIBS "$ENV{SEQ_HDF5_CLIB}" CACHE FILEPATH "sequential hdf5")
#else()
#  set(HDF5 OFF CACHE BOOL "")
#endif()

if(DEFINED ENV{SEQ_HDF5_DIR})
  if("$ENV{SEQ_HDF5_DIR}" STREQUAL "")
    set(HDF5 OFF CACHE BOOL "")
  else()
    set(HDF5 ON CACHE BOOL "" FORCE)
    set(HDF5_DIR "$ENV{SEQ_HDF5_DIR}" CACHE FILEPATH "path to hdf5 dir")
    set(HDF5_FLAGS "-I${HDF5_DIR}/include")
#    set(HDF5_LIBS "$ENV{SEQ_HDF5_CLIB}" CACHE FILEPATH "sequential hdf5")
  endif()
else()
  set(HDF5 OFF CACHE BOOL "")
endif()

set(DMALLOC OFF CACHE BOOL "")

if(DEFINED ENV{LUSTRE_DIR})
  set(LUSTRE_DIR "$ENV{LUSTRE_DIR}" CACHE FILEPATH "path to lustre dir")
  set(LUSTRE ON CACHE BOOL "")
else()
  set(LUSTRE OFF CACHE BOOL "")
endif()

if(DEFINED ENV{GLIB_DIR})
  if("$ENV{GLIB_DIR}" STREQUAL "")
    set(GLIB OFF CACHE BOOL "")
  else()
    set(GLIB ON CACHE BOOL "")
    set(GLIB_DIR "$ENV{GLIB_DIR}")
  endif()
elseif(DEFINED ENV{GLIB})
  if("$ENV{GLIB}" STREQUAL "")
    set(GLIB OFF CACHE BOOL "")
  else()
    set(GLIB ON CACHE BOOL "")
    set(GLIB_DIR "$ENV{GLIB}")
  endif()
endif()

if(GLIB)
  if(DEFINED ENV{FGR_DIR})
    if("$ENV{FGR_DIR}" STREQUAL "")
      set(FGR OFF CACHE BOOL "")
    else()
      set(FGR ON CACHE BOOL "")
      set(FGR_DIR "$ENV{FGR_DIR}")
    endif()
  elseif(DEFINED ENV{FGR})
    if("$ENV{FGR}" STREQUAL "")
      set(FGR OFF CACHE BOOL "")
    else()
      set(FGR ON CACHE BOOL "")
      set(FGR_DIR "$ENV{FGR}")
    endif()
  endif()
else()
  set(FGR OFF CACHE BOOL "")
endif()

if(DEFINED ENV{BZIP2_DIR})
  if("$ENV{BZIP2_DIR}" STREQUAL "")
    set(BZIP2 OFF CACHE BOOL "")
  else()
    set(BZIP2 ON CACHE BOOL "")
    set(BZIP2_DIR "$ENV{BZIP2_DIR}")
  endif()
elseif(DEFINED ENV{BZIP2})
  if("$ENV{BZIP2}" STREQUAL "")
    set(BZIP2 OFF CACHE BOOL "")
  else()
    set(BZIP2 ON CACHE BOOL "")
    set(BZIP2_DIR "$ENV{BZIP2}")
  endif()
endif()

if(DEFINED ENV{LZ4_DIR})
  if("$ENV{LZ4_DIR}" STREQUAL "")
    set(LZ4 OFF CACHE BOOL "")
  else()
    set(LZ4 ON CACHE BOOL "")
    set(LZ4_DIR "$ENV{LZ4_DIR}")
  endif()
elseif(DEFINED ENV{LZ4})
  if("$ENV{LZ4}" STREQUAL "")
    set(LZ4 OFF CACHE BOOL "")
  else()
    set(LZ4 ON CACHE BOOL "")
    set(LZ4_DIR "$ENV{LZ4}")
  endif()
endif()

if(DEFINED ENV{BLOSC_DIR})
  if("$ENV{BLOSC_DIR}" STREQUAL "")
    set(BLOSC OFF CACHE BOOL "")
  else()
    set(BLOSC ON CACHE BOOL "")
    set(BLOSC_DIR "$ENV{BLOSC_DIR}")
  endif()
elseif(DEFINED ENV{BLOSC})
  if("$ENV{BLOSC}" STREQUAL "")
    set(BLOSC OFF CACHE BOOL "")
  else()
    set(BLOSC ON CACHE BOOL "")
    set(BLOSC_DIR "$ENV{BLOSC}")
  endif()
endif()

if(DEFINED ENV{SZIP_DIR})
  if("$ENV{SZIP_DIR}" STREQUAL "")
    set(SZIP OFF CACHE BOOL "")
  else()
    set(SZIP ON CACHE BOOL "")
    set(SZIP_DIR $ENV{SZIP_DIR})
  endif()
elseif(DEFINED ENV{SZIP})
  if(NOT "$ENV{SZIP}" STREQUAL "")
    set(SZIP OFF CACHE BOOL "")
  else()
    set(SZIP_DIR $ENV{SZIP})
    set(SZIP ON CACHE BOOL "")
  endif()
endif()

if(DEFINED ENV{ISOBAR_DIR})
  if("$ENV{ISOBAR_DIR}" STREQUAL "")
    set(ISOBAR OFF CACHE BOOL "")
  else()
    set(ISOBAR ON CACHE BOOL "")
    set(ISOBAR_DIR $ENV{ISOBAR_DIR})
  endif()
elseif(DEFINED ENV{ISOBAR})
  if("$ENV{ISOBAR}" STREQUAL "")
    set(ISOBAR OFF CACHE BOOL "")
  else()
    set(ISOBAR ON CACHE BOOL "")
    set(ISOBAR_DIR $ENV{ISOBAR})
  endif()
endif()

if(DEFINED ENV{APLOD_DIR})
  if("$ENV{APLOD_DIR}" STREQUAL "")
    set(APLOD OFF CACHE BOOL "")
  else()
    set(APLOD ON CACHE BOOL "")
    set(APLOD_DIR $ENV{APLOD_DIR})
  endif()
elseif(DEFINED ENV{APLOD})
  if("$ENV{APLOD}" STREQUAL "")
    set(APLOD OFF CACHE BOOL "")
  else()
    set(APLOD ON CACHE BOOL "")
    set(${APLOD_DIR} $ENV{APLOD})
  endif()
endif()

if(DEFINED ENV{ALACRITY_DIR})
  if("$ENV{ALACRITY_DIR}" STREQUAL "")
    set(ALACRITY OFF CACHE BOOL "")
  else()
    set(ALACRITY ON CACHE BOOL "")
    set(ALACRITY_DIR $ENV{ALACRITY_DIR})
  endif()
elseif(DEFINED ENV{ALACRITY})
  if("$ENV{ALACRITY}" STREQUAL "")
    set(ALACRITY OFF CACHE BOOL "")
  else()
    set(ALACRITY ON CACHE BOOL "")
    set(ALACRITY_DIR $ENV{ALACRITY})
  endif()
endif()

if(DEFINED ENV{ZFP_DIR})
  if("$ENV{ZFP_DIR}" STREQUAL "")
    set(ZFP OFF CACHE BOOL "")
  else()
    set(ZFP ON CACHE BOOL "")
    set(ZFP_DIR "$ENV{ZFP_DIR}")
  endif()
elseif(DEFINED ENV{ZFP})
  if("$ENV{ZFP}" STREQUAL "")
    set(ZFP OFF CACHE BOOL "")
  else()
    set(ZFP ON CACHE BOOL "")
    set(ZFP_DIR "$ENV{ZFP}")
  endif()
else()
    set(BUILD_ZFP ON CACHE BOOL "")
    set(ZFP ON CACHE BOOL "")
    set(ZFP_DIR ${PROJECT_SOURCE_DIR}/src/zfp/zfp-0.5.0)
endif()

if(DEFINED ENV{SZ_DIR})
  if("$ENV{SZ_DIR}" STREQUAL "")
    set(SZ OFF CACHE BOOL "")
  else()
    set(SZ ON CACHE BOOL "")
    set(SZ_DIR $ENV{SZ_DIR})
  endif()
elseif(DEFINED ENV{SZ})
  if(NOT "$ENV{SZ}" STREQUAL "")
    set(SZ OFF CACHE BOOL "")
  else()
    set(SZ_DIR $ENV{SZ})
    set(SZ ON CACHE BOOL "")
  endif()
endif()


###################### end of external library is used(ON) or not (OFF) ##############################


#################################### start generating config.h #######################################
set(BUILD_WITH_CMAKE 1)

include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckLibraryExists)

# Define to dummy `main' function (if any) required to link to the Fortran
# libraries.

# Define if F77 and FC dummy `main' functions are identical.

# Define to a macro mangling the given C identifier (in lower and upper case),
# which must not contain underscores, for linking with Fortran.
set(FC_FUNC FC_GLOBAL)

# As FC_FUNC, but for C identifiers containing underscores.
set(FC_FUNC_ FC_GLOBAL_)
# Define to 1 if your Fortran compiler doesn't accept -c and -o together.

# Define to 1 if you have the <Attributes.h> header file.
CHECK_INCLUDE_FILES(Attributes.h HAVE_ATTRIBUTES_H)

# Define to 1 if you have the `nanosleep' function.
CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)

# Define to 1 if you have the `gettimeofday' function.
CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)

# Define to 1 if you have the `clock_gettime' function.
CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME)

# Define to 1 if you have the `clock_get_time' function. On OSX.
CHECK_FUNCTION_EXISTS(clock_get_time HAVE_CLOCK_GET_TIME)

# Check if clockid_t type exist
include(CheckTypeSize)
CHECK_TYPE_SIZE("clockid_t" CLOCKID_T)

# Define if you have CRAY_PMI.
set(HAVE_CRAY_PMI 0)
if(CRAY_PMI)
  find_library(CRAY_PMI_LIBS NAMES pmi PATHS ${CRAY_PMI_LIBS_PATH})
  if(CRAY_PMI_LIBS)
    set(HAVE_CRAY_PMI 1)
#  set(LIBS "${LIBS} ${CRAY_PMI_LIBS}")
#    set(CPPFLAGS "${CPPFLAGS} ${CRAY_PMI_CPPFLAGS}")
  endif()
endif()

# Define if you have CRAY_UGNI.
set(HAVE_CRAY_UGNI 0)
if(CRAY_UGNI)
  find_library(CRAY_UGNI_LIBS NAMES ugni PATHS ${CRAY_UGNI_LIBS_PATH})
  if(CRAY_UGNI_LIBS)
    set(HAVE_CRAY_UGNI 1)
#   set(LIBS "${LIBS} ${CRAY_UGNI_LIBS}")
#    set(CPPFLAGS "${CPPFLAGS} ${CRAY_UGNI_CPPFLAGS}")
  endif()
endif()

# Define to 1 if you have <infiniband/verbs.h>.
CHECK_INCLUDE_FILES(infiniband/verbs.h HAVE_IBVERBS_H)

CHECK_FUNCTION_EXISTS(ibv_alloc_pd HAVE_IBVERBS)

# Define if you have the Infiniband.
set(HAVE_INFINIBAND 0)
if(HAVE_IBVERBS_H AND HAVE_IBVERBS)
  set(HAVE_INFINIBAND 1)
  set(INFINIBAND ON CACHE BOOL "")
  set(INFINIBAND_LIBS "-libverbs")
#  set(LIBS "${LIBS} ${INFINIBAND_LIBS}")
endif()

CHECK_FUNCTION_EXISTS(PtlInit HAVE_PTLINIT)

# Define to 1 if you have <portals3.h>.
#set(HAVE_PORTALS3_H 0)
CHECK_INCLUDE_FILES(portals3.h HAVE_PORTALS3_H)

# Define to 1 if you have <portals/portals3.h>.
#set(HAVE_PORTALS_PORTALS3_H 0)
CHECK_INCLUDE_FILES(portals/portals3.h HAVE_PORTALS_PORTALS3_H)

# Define to 1 if you have the <p3nal_utcp.h> header file.
CHECK_INCLUDE_FILES(p3nal_utcp.h HAVE_P3NAL_UTCP_H)

# Define to 1 if you have the <p3rt/p3rt.h> header file.
CHECK_INCLUDE_FILES(p3rt/p3rt.h HAVE_P3RT_P3RT_H)

# Define if you have the Portals.
if(PORTALS)
  set(PORTALS_LIBS "-L${PORTALS_DIR}/lib")
#  set(LIBS "${LIBS} ${PORTALS_LIBS}")
  set(PORTALS_CPPFLAGS "-I${PORTALS_DIR}/include")
  if(HAVE_PORTALS3_H)
    set(HAVE_PORTALS 1)
    set(PORTALS_CFLAGS "${PORTALS_CFLAGS} ${EXTRA_CFLAGS}")
    set(CFLAGS "${CFLAGS} ${PORTALS_CFLAGS}")
    set(PORTALS_CPPFLAGS "${PORTALS_CPPFLAGS} ${EXTRA_CPPFLAGS}")
#    set(CPPFLAGS "${CPPFLAGS} ${PORTALS_CPPFLAGS}")
  elseif(HAVE_PORTALS_PORTALS3_H)
    set(HAVE_PORTALS 1)
    set(PORTALS_CFLAGS "${PORTALS_CFLAGS} ${EXTRA_CFLAGS}")
    set(CFLAGS "${CFLAGS} ${PORTALS_CFLAGS}")
    set(PORTALS_CPPFLAGS "${PORTALS_CPPFLAGS} ${EXTRA_CPPFLAGS}")
#    set(CPPFLAGS "${CPPFLAGS} ${PORTALS_CPPFLAGS}")
 endif()
#else()
#  find_package(TPLPortals)
#  if(TPLPortals_FOUND)
#    set(PORTALS ON CACHE BOOL "" FORCE)
#    set(HAVE_PORTALS 1)
#    set(PORTALS_CPPFLAGS "${TPLPortals_INCLUDE_DIRS}")
#    set(CPPFLAGS "${CPPFLAGS} ${PORTALS_CPPFLAGS}")
#    set(PORTALS_LIBS "${TPLPortals_LIBRARIES}")
#    set(LIBS "${LIBS} ${PORTALS_LIBS}")
#  else()
#    set(HAVE_PORTALS 0)
#  endif()
endif()


# Define to 1 if you have the <dataspaces.h> header file.
set(HAVE_DATASPACES_H 0)
if(DATASPACES)
  if(DEFINED DATASPACES_INCDIR)
    if("${DATASPACES_INCDIR}" STREQUAL "")
      set(DATASPACES_INCDIR "$ENV{DATASPACES_DIR}/include")
    endif()
  else()
    set(DATASPACES_INCDIR "$ENV{DATASPACES_DIR}/include")
  endif()
#  message(STATUS "DATASPACES_INCDIR is: ${DATASPACES_INCDIR}")
  find_path(DATASPACES_INCLUDE_DIR NAMES dataspaces.h PATHS ${DATASPACES_INCDIR})
  if(DATASPACES_INCLUDE_DIR)
    set(HAVE_DATASPACES_H 1)
    set(DATASPACES_CPPFLAGS "-I${DATASPACES_INCLUDE_DIR}")
#include_directories(${DATASPACES_INCLUDE_DIR})
  endif()
endif()

# Define if you have the DATASPACES.
set(HAVE_DATASPACES 0)
if(HAVE_DATASPACES_H)
#  set(CPPFLAGS "${CPPFLAGS} ${DATASPACES_CPPFLAGS}")
  if(DEFINED DATASPACES_LIBDIR)
    if("${DATASPACES_LIBDIR}" STREQUAL "")
#      set(HAVE_DATASPACES 0)
#    else()
      set(DATASPACES_LIBDIR "$ENV{DATASPACES_DIR}/lib")
    endif()
  else()
    set(DATASPACES_LIBDIR "$ENV{DATASPACES_DIR}/lib")
  endif()

  # 1.6.2 has a config file
  set(DATASPACES_BINDIR "$ENV{DATASPACES_DIR}/bin")
  #message("DATASPACES: look for dspaces_config")
  find_program (DSPACES_CONFIG NAMES dspaces_config 
                PATHS "$ENV{DATASPACES_DIR}/bin" NO_DEFAULT_PATH)

  if(DSPACES_CONFIG)
    #message("DATASPACES: run dspaces_config")
    execute_process(COMMAND ${DSPACES_CONFIG} "-l"
        OUTPUT_VARIABLE dspaces_config_out
        RESULT_VARIABLE dspaces_config_ret
        OUTPUT_STRIP_TRAILING_WHITESPACE
    )
    #message("DATASPACES: return value = ${dspaces_config_ret}")
    #message("DATASPACES: output = ${dspaces_config_out}")
    if(dspaces_config_ret EQUAL 0)
        string(REPLACE " " ";" dspaces_config_list ${dspaces_config_out})
    #message("DATASPACES: list = ${dspaces_config_list}")
        set(dspaces_libs)
        set(dspaces_lib_hints)
        set(dspaces_lib_flags)
        foreach(OPT IN LISTS dspaces_config_list)
            if(OPT MATCHES "^-L(.*)")
                list(APPEND dspaces_lib_hints "${CMAKE_MATCH_1}")
            elseif(OPT MATCHES "^-l(.*)")
                list(APPEND dspaces_libs "${CMAKE_MATCH_1}")
            else()
                list(APPEND dspaces_lib_flags "${OPT}")
            endif()
        endforeach()
        set(HAVE_DATASPACES 1)
    endif()
    #message("DATASPACES: hints = ${dspaces_lib_hints}")
    #message("DATASPACES: libs = ${dspaces_libs}")
    #message("DATASPACES: flags = ${dspaces_lib_flags}")
    set(DATASPACES_LIBS)
    foreach(lib IN LISTS dspaces_libs)
      find_library(dspaces_${lib}_LIBRARY NAME ${lib} HINTS ${dspaces_lib_hints})
      if(dspaces_${lib}_LIBRARY)
          list(APPEND DATASPACES_LIBS ${dspaces_${lib}_LIBRARY})
      else()
        list(APPEND DATASPACES_LIBS ${lib})
      endif()
    endforeach()

  elseif(HAVE_INFINIBAND)
    set(DATASPACES_LIBS1 "${DATASPACES_LIBS1}" CACHE INTERNAL "Internal variable")
    find_library(DATASPACES_LIBS1 NAMES libdspaces.a PATHS ${DATASPACES_LIBDIR})
    find_library(DATASPACES_LIBS2 NAMES libdscommon.a PATHS ${DATASPACES_LIBDIR})
    set(DATASPACES_LIBS2 "${DATASPACES_LIBS2}" CACHE INTERNAL "Internal variable")
    find_library(DATASPACES_LIBS3 NAMES libdart.a  PATHS ${DATASPACES_LIBDIR})
    set(DATASPACES_LIBS3 "${DATASPACES_LIBS3}" CACHE INTERNAL "Internal variable")
    find_library(DATASPACES_LIBS4 NAMES rdmacm  PATHS ${DATASPACES_LIBDIR} /usr/lib64)
    set(DATASPACES_LIBS4 "${DATASPACES_LIBS4}" CACHE INTERNAL "Internal variable")
    if(DATASPACES_LIBS1 AND DATASPACES_LIBS2 AND DATASPACES_LIBS3 AND DATASPACES_LIBS4)
      set(DATASPACES_LIBS ${DATASPACES_LIBS1} ${DATASPACES_LIBS2} ${DATASPACES_LIBS3} ${DATASPACES_LIBS4})
      set(DATASPACES_LIBS ${DATASPACES_LIBS} CACHE STRING "")
      set(HAVE_DATASPACES 1)
#      set(LIBS "${LIBS} ${DATASPACES_LIBS}")
    else()
      set(DATASPACES OFF CACHE BOOL "do not find supporting library" FORCE)
    endif()
  elseif(HAVE_PORTALS)
    find_library(DATASPACES_LIBS1 NAMES libdart2.a PATHS ${DATASPACES_LIBDIR})
    set(DATASPACES_LIBS1 "${DATASPACES_LIBS1}" CACHE INTERNAL "Internal variable")
    find_library(DATASPACES_LIBS2 NAMES libspaces.a PATHS ${DATASPACES_LIBDIR})
    set(DATASPACES_LIBS2 "${DATASPACES_LIBS2}" CACHE INTERNAL "Internal variable")
    if(DATASPACES_LIBS1 AND DATASPACES_LIBS2)
      set(DATASPACES_LIBS ${DATASPACES_LIBS1} ${DATASPACES_LIBS2})
      set(DATASPACES_LIBS ${DATASPACES_LIBS} CACHE STRING "")
      set(HAVE_DATASPACES 1)
#      set(LIBS "${LIBS} ${DATASPACES_LIBS}")
    else()
      set(DATASPACES OFF CACHE BOOL "do not find supporting library" FORCE)
    endif()
  elseif(HAVE_CRAY_PMI AND HAVE_CRAY_UGNI)
    find_library(DATASPACES_LIBS1 NAMES libdspaces.a PATHS ${DATASPACES_LIBDIR})
    set(DATASPACES_LIBS1 "${DATASPACES_LIBS1}" CACHE INTERNAL "Internal variable")
    find_library(DATASPACES_LIBS2 NAMES libdscommon.a PATHS ${DATASPACES_LIBDIR})
    set(DATASPACES_LIBS2 "${DATASPACES_LIBS2}" CACHE INTERNAL "Internal variable")
    find_library(DATASPACES_LIBS3 NAMES libdart.a PATHS ${DATASPACES_LIBDIR})
    set(DATASPACES_LIBS3 "${DATASPACES_LIBS3}" CACHE INTERNAL "Internal variable")
    if(DATASPACES_LIBS1 AND DATASPACES_LIBS2 AND DATASPACES_LIBS3)
      set(DATASPACES_LIBS ${DATASPACES_LIBS1} ${DATASPACES_LIBS2} ${DATASPACES_LIBS3})
      set(DATASPACES_LIBS ${DATASPACES_LIBS} CACHE STRING "")
      set(HAVE_DATASPACES 1)
#      set(LIBS "${LIBS} ${DATASPACES_LIBS}")
     else()
      set(DATASPACES OFF CACHE BOOL "do not find supporting library" FORCE)
    endif()
  else()
    set(HAVE_DATASPACES 0)
    set(DATASPACES OFF CACHE BOOL "do not find supporting library" FORCE)
  endif()
endif()

# Define to 1 if you have the <dimes.h> header file.
set(HAVE_DIMES_H 0)
if(HAVE_DATASPACES_H)
  find_path(DIMES_INCLUDE_DIR NAMES dimes_interface.h PATHS ${DATASPACES_INCDIR})
  if(DIMES_INCLUDE_DIR)
    set(HAVE_DIMES_H 1)
  endif()
endif()

# Define if you have the DIMES.
set(HAVE_DIMES 0)
if(HAVE_DIMES_H)
  if(HAVE_INFINIBAND)
    set(DIMES OFF CACHE BOOL "" FORCE)
    message("DIMES currently NOT supported for Infiniband!")
  elseif(HAVE_PORTALS)
    set(DIMES OFF CACHE BOOL "" FORCE)
    message("DIMES currently NOT supported for Cray Portals!")
  else()
    set(HAVE_DIMES 1)
    set(DIMES_LIBS ${DATASPACES_LIBS})
    set(DIMES_CFLAGS ${DATASPACES_CFLAGS})
    set(DIMES_CPPFLAGS ${DATASPACES_CPPFLAGS})
  endif()
endif()

# Define to 1 if you have the <dlfcn.h> header file.
CHECK_INCLUDE_FILES(dlfcn.h HAVE_DLFCN_H)

# Define if you have DMALLOC.
set(HAVE_DMALLOC 0)

# Define to 1 if you have the <dmalloc.h> header file.
CHECK_INCLUDE_FILES(dmalloc.h HAVE_DMALLOC_H)

# Define to 1 if you have the `fdatasync' function.
CHECK_FUNCTION_EXISTS(fdatasync HAVE_FDATASYNC)

set(HAVE_FLEXPATH 0)
set(NO_FLEXPATH 1)
set(HAVE_FLEXPATH_H 0)
if(FLEXPATH)
  # 4.2.1 has a config file
  set(FLEXPATH_BINDIR "$ENV{FLEXPATH_DIR}/bin")
  # message("FLEXPATH: look for evpath_config")
  find_program (EVPATH_CONFIG NAMES evpath_config 
                PATHS "$ENV{FLEXPATH_DIR}/bin" NO_DEFAULT_PATH)

  if(EVPATH_CONFIG)
    # message("FLEXPATH: run evpath_config")
    execute_process(COMMAND ${EVPATH_CONFIG} "-l"
        OUTPUT_VARIABLE evpath_config_out
        RESULT_VARIABLE evpath_config_ret
        OUTPUT_STRIP_TRAILING_WHITESPACE
    )
    # message("FLEXPATH: return value = ${evpath_config_ret}")
    # message("FLEXPATH: output = ${evpath_config_out}")
    if(evpath_config_ret EQUAL 0)
        string(REPLACE " " ";" evpath_config_list ${evpath_config_out})
    # message("FLEXPATH: list = ${evpath_config_list}")
        set(evpath_libs)
        set(evpath_lib_hints)
        set(evpath_lib_flags)
        foreach(OPT IN LISTS evpath_config_list)
            if(OPT MATCHES "^-L(.*)")
                list(APPEND evpath_lib_hints "${CMAKE_MATCH_1}")
            elseif(OPT MATCHES "^-l(.*)")
                list(APPEND evpath_libs "${CMAKE_MATCH_1}")
            else()
                list(APPEND evpath_libs "${OPT}")
            endif()
        endforeach()
        set(HAVE_FLEXPATH 1)
    endif()
    # message("FLEXPATH: hints = ${evpath_lib_hints}")
    # message("FLEXPATH: libs = ${evpath_libs}")
    # message("FLEXPATH: flags = ${evpath_lib_flags}")
    set(FP_LIBS)
    foreach(lib IN LISTS evpath_libs)
      find_library(evpath_${lib}_LIBRARY NAME ${lib} HINTS ${evpath_lib_hints})
      if(evpath_${lib}_LIBRARY)
          list(APPEND FP_LIBS ${evpath_${lib}_LIBRARY})
      else()
        list(APPEND FP_LIBS ${lib})
      endif()
    endforeach()
    set(HAVE_FLEXPATH 1)
    set(NO_FLEXPATH 0)
    set(FP_LIBS "${FP_LIBS}" CACHE STRING "")
    set(FP_CPPFLAGS "-I${FLEXPATH_DIR}/include")
    message("-- Found FLEXPATH: ${FP_LIBS}")
    message("-- FLEXPATH cppflags = ${FP_CPPFLAGS}")

  else(EVPATH_CONFIG)

    if(DEFINED FLEXPATH_INCDIR)
        if("${FLEXPATH_INCDIR}" STREQUAL "")
        set(FLEXPATH_INCDIR "$ENV{FLEXPATH_DIR}/include")
        endif()
    else()
        set(FLEXPATH_INCDIR "$ENV{FLEXPATH_DIR}/include")
    endif()
    find_path(FLEXPATH_INCLUDE_DIR1 NAMES evpath.h PATHS ${FLEXPATH_INCDIR})
    set(FLEXPATH_INCLUDE_DIR1 "${FLEXPATH_INCLUDE_DIR1}" CACHE INTERNAL "Internal variable")
    find_path(FLEXPATH_INCLUDE_DIR2 NAMES ffs.h PATHS ${FLEXPATH_INCDIR})
    set(FLEXPATH_INCLUDE_DIR2 "${FLEXPATH_INCLUDE_DIR2}" CACHE INTERNAL "Internal variable")
    find_path(FLEXPATH_INCLUDE_DIR3 NAMES atl.h PATHS ${FLEXPATH_INCDIR})
    set(FLEXPATH_INCLUDE_DIR3 "${FLEXPATH_INCLUDE_DIR3}" CACHE INTERNAL "Internal variable")
    find_path(FLEXPATH_INCLUDE_DIR4 NAMES dill.h PATHS ${FLEXPATH_INCDIR})
    set(FLEXPATH_INCLUDE_DIR4 "${FLEXPATH_INCLUDE_DIR4}" CACHE INTERNAL "Internal variable")
    find_path(FLEXPATH_INCLUDE_DIR5 NAMES cercs_env.h PATHS ${FLEXPATH_INCDIR})
    set(FLEXPATH_INCLUDE_DIR5 "${FLEXPATH_INCLUDE_DIR5}" CACHE INTERNAL "Internal variable")
    if(FLEXPATH_INCLUDE_DIR1 AND FLEXPATH_INCLUDE_DIR2 AND FLEXPATH_INCLUDE_DIR3 AND FLEXPATH_INCLUDE_DIR4 AND FLEXPATH_INCLUDE_DIR5)
        set(HAVE_FLEXPATH_H 1)
        set(FLEXPATH_INCLUDE_DIR ${FLEXPATH_INCDIR})
    endif()
    if(DEFINED FLEXPATH_LIBDIR)
        if("${FLEXPATH_LIBDIR}" STREQUAL "")
            set(FLEXPATH_LIBDIR "$ENV{FLEXPATH_DIR}/lib")
        endif()
    else()
        set(FLEXPATH_LIBDIR "$ENV{FLEXPATH_DIR}/lib")
    endif()
    find_library(FLEXPATH_LIBS1 NAMES evpath PATHS ${FLEXPATH_LIBDIR})
    set(FLEXPATH_LIBS1 "${FLEXPATH_LIBS1}" CACHE INTERNAL "Internal variable")
    find_library(FLEXPATH_LIBS2 NAMES ffs PATHS ${FLEXPATH_LIBDIR})
    set(FLEXPATH_LIBS2 "${FLEXPATH_LIBS2}" CACHE INTERNAL "Internal variable")
    find_library(FLEXPATH_LIBS3 NAMES atl PATHS ${FLEXPATH_LIBDIR})
    set(FLEXPATH_LIBS3 "${FLEXPATH_LIBS3}" CACHE INTERNAL "Internal variable")
    find_library(FLEXPATH_LIBS4 NAMES dill PATHS ${FLEXPATH_LIBDIR})
    set(FLEXPATH_LIBS4 "${FLEXPATH_LIBS4}" CACHE INTERNAL "Internal variable")
    find_library(FLEXPATH_LIBS5 NAMES cercs_env PATHS ${FLEXPATH_LIBDIR})
    set(FLEXPATH_LIBS5 "${FLEXPATH_LIBS5}" CACHE INTERNAL "Internal variable")
    if(FLEXPATH_LIBS1 AND FLEXPATH_LIBS2 AND FLEXPATH_LIBS3 AND FLEXPATH_LIBS4 AND FLEXPATH_LIBS5 AND HAVE_FLEXPATH_H)
        set(HAVE_FLEXPATH 1)
        set(NO_FLEXPATH 0)
        set(FP_LIBS ${FLEXPATH_LIBS1} ${FLEXPATH_LIBS2} ${FLEXPATH_LIBS3} ${FLEXPATH_LIBS4} ${FLEXPATH_LIBS5})
        set(FP_LIBS "${FP_LIBS}" CACHE STRING "")
        set(FP_CPPFLAGS "-I${FLEXPATH_INCLUDE_DIR}")
#       set(FP_CFLAGS ${FP_CPPFLAGS})
#       include_directories(${FLEXPATH_INCLUDE_DIR})
        message("-- Found FLEXPATH: ${FP_LIBS}")
        message("-- FLEXPATH cppflags = ${FP_CPPFLAGS}")
    else()
        set(FLEXPATH OFF CACHE BOOL "do not find supporting library" FORCE)
        message("-- FLEXPATH was not found")
    endif()
  endif(EVPATH_CONFIG)
endif()

if(HAVE_FLEXPATH)
  set(HAVE_ICEE 1)
else()
  set(HAVE_ICEE 0)
endif()

set(HAVE_FASTBIT 0)
if(FASTBIT)
  set(FASTBIT_INCDIR "${FASTBIT_DIR}/include/fastbit")
  set(FASTBIT_LIBDIR "${FASTBIT_DIR}/lib")
  find_path(FASTBIT_INCLUDE_DIR NAMES iapi.h PATHS ${FASTBIT_INCDIR})
  if(NOT FASTBIT_INCLUDE_DIR)
    message("Cannot find iapi.h from the FastBit lib. Make sure it has been
    properly installed at the path specified ${FASTBIT_DIR}")
  else()
    set(HAVE_IAPI_H 1)
  endif()
  find_library(FASTBIT_LIB NAMES fastbit PATHS ${FASTBIT_LIBDIR})
  if(FASTBIT_INCLUDE_DIR AND FASTBIT_LIB)
    set(HAVE_FASTBIT 1)
    set(FASTBIT_CPPFLAGS "-I${FASTBIT_INCDIR}")
    set(FASTBIT_LIBS ${FASTBIT_LIB} -lstdc++ CACHE STRING "")
  else()
    set(FASTBIT OFF CACHE BOOL "" FORCE)
  endif()
endif()

set(HAVE_MPI 0)

# Define if you have the MPI library.
if(BUILD_FORTRAN)
  find_package(MPI COMPONENTS Fortran)
  if(MPI_FOUND)
#    if(MPI_LIBRARIES AND MPI_INCLUDE_PATH)
      message(STATUS "find MPI")
      set (HAVE_MPI 1)
#      set(MPILIBS ${MPI_LIBRARIES})
#include_directories(${MPI_INCLUDE_PATH})
#      set(LIBS ${MPILIBS})
  endif(MPI_FOUND)
else()
  find_package(MPI)
  if(MPI_FOUND)
#    if(MPI_LIBRARIES AND MPI_INCLUDE_PATH)
      message(STATUS "find MPI")
      set (HAVE_MPI 1)
#      set(MPILIBS ${MPI_LIBRARIES})
#    set(MPILIBS ${MPILIBS})
#include_directories(${MPI_INCLUDE_PATH})
#      set(LIBS ${MPILIBS})
  endif(MPI_FOUND)
endif(BUILD_FORTRAN)

# Define to 1 if you have the <hdf5.h> header file.
if(HDF5)
   set(HAVE_HDF5 1)
#    link_directories(${HDF5_DIR}/lib)
   set(HDF5_LIBS $ENV{SEQ_HDF5_LIBS} CACHE STRING "" FORCE)

  find_path(HDF5_INCLUDE_DIR hdf5.h ${HDF5_DIR}/include)
  if(HDF5_INCLUDE_DIR)
    set(HAVE_HDF5_H 1)
#    include_directories(${HDF5_INCLUDE_DIR})
#    set(CPPFLAGS "${CPPFLAGS} ${HDF5_FLAGS}")
#      set(LIBS "${LIBS} ${HDF5_LIBS}")
  else()
    set(HAVE_HDF5_H 0)
  endif()
else()
  set(HAVE_HDF5 0)
  set(HAVE_HDF5_H 0)
endif(HDF5)

# Define to 1 if you have the <inttypes.h> header file.
CHECK_INCLUDE_FILES(inttypes.h HAVE_INTTYPES_H)

# Define to 1 if you have the `rt' library (-lrt).
set(HAVE_LIBRT 0)

# Define if you have LUSTRE.
if(LUSTRE)
  set(LUSTRE_DIR "$ENV{LUSTRE_DIR}" CACHE STRING "")
  if(LUSTRE_DIR)
    find_library(LUSTRE_LIBS NAMES lustreapi PATHS "${LUSTRE_DIR}")
    if(LUSTRE_LIBS)
      message(STATUS "find LUSTRE library")
      set(HAVE_LUSTRE 1)
    endif()
  else()
    set(HAVE_LUSTRE 0)
  endif(LUSTRE_DIR)
else()
  set(HAVE_LUSTRE 0)
endif(LUSTRE)

# Define to 1 if you have the <memory.h> header file.
CHECK_INCLUDE_FILES(memory.h HAVE_MEMORY_H)

set(HAVE_MXML 0)
if (MXML_DIR)
  # Use a preinstalled MXML library pointed by the user
  # Define to 1 if you have the <mxml.h> header file.
  find_path(MXML_INCLUDE_DIR NAMES mxml.h PATHS ${MXML_DIR}/include)
  if(NOT MXML_INCLUDE_DIR-NOTFOUND)
    message(STATUS "find mxml header")
    set(HAVE_MXML_H 1)
  endif(NOT MXML_INCLUDE_DIR-NOTFOUND)

  # Define if you have the MXML.
  # MXML: /sw/analysis-x64/mxml/2.6/centos5.5_pgi10./9
  find_library(MXML_LIBS NAMES mxml PATHS ${MXML_DIR}/lib)
  if(MXML_LIBS)
    message(STATUS "find mxml library")
  endif()
  if(MXML_LIBS AND HAVE_MXML_H)
    set(HAVE_MXML 1)
  endif()
endif(MXML_DIR)

if (NOT HAVE_MXML)
  # Build the supplied mxml directory
  message(STATUS "MXML will be built for ADIOS in ./src/mxml")
  set(HAVE_MXML 1)
  set(BUILD_MXML 1)
  set(MXML_LIBS "")
  set(MXML_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src/mxml/mxml-2.9)
  message(STATUS "Checking type long long int")
  try_compile(HAVE_LONG_LONG ${PROJECT_BINARY_DIR}/src/mxml SOURCES ${PROJECT_SOURCE_DIR}/src/mxml/cmake_try_longlong.c)
endif (NOT HAVE_MXML)


# Define if you have NETCDF.
if(NETCDF)
  find_path(NETCDF_INCLUDE_DIR NAMES netcdf.h PATHS ${NETCDF_DIR}/include)
  if(NETCDF_INCLUDE_DIR)
# Define to 1 if you have the <netcdf.h> header file.
    set(HAVE_NETCDF_H 1)
#    include_directories(${NETCDF_INCLUDE_DIR})
    set(NETCDF_CPPFLAGS "-I${NETCDF_INCLUDE_DIR}")
#    set(CPPFLAGS "${CPPFLAGS} ${NETCDF_CPPFLAGS}")
  else()
    set(HAVE_NETCDF_H 0)
  endif()
else()
  set(HAVE_NETCDF_H 0)
endif()

if(HAVE_NETCDF_H)
  set(NETCDF_LIBS $ENV{SEQ_NC_LIBS} CACHE STRING "")
  set(HAVE_NETCDF 1)
else()
  set(HAVE_NETCDF 0)
endif()

#if(NETCDF)
#  if(NETCDF_LIBS AND NETCDF_CPPFLAGS)
#    set(HAVE_NETCDF 1)
#    find_path(NETCDF_INCLUDE_DIR netcdf.h ${NETCDF_DIR}/include)
#    if(NETCDF_INCLUDE_DIR)
#      set(HAVE_NETCDF_H 1)
#      include_directories(${NETCDF_INCLUDE_DIR})
#      set(CPPFLAGS "${CPPFLAGS} ${NETCDF_CPPFLAGS}")
##      set(LIBS "${LIBS} ${NETCDF_LIBS}")
#    else()
#      set(HAVE_NETCDF_H 0)
#      set(HAVE_NETCDF 0)
#    endif()
#  else()
#    set(HAVE_NETCDF 0)
#  endif()
#else()
#  set(HAVE_NETCDF 0)
#  set(HAVE_NETCDF_H 0)
#endif(NETCDF)

# Define if you have NC4PAR.
if(NC4PAR)
  find_path(NC4PAR_INCLUDE_DIR NAMES netcdf.h PATHS ${NC4PAR_DIR}/include)
  if(NC4PAR_INCLUDE_DIR)
    set(HAVE_NC4PAR_H 1)
#include_directories(${NC4PAR_INCLUDE_DIR})
    set(NC4PAR_CPPFLAGS "-I${NC4PAR_INCLUDE_DIR}")
#    set(CPPFLAGS "${CPPFLAGS} ${NC4PAR_CPPFLAGS}")
  else()
    set(HAVE_NC4PAR_H 0)
  endif()
else()
  set(HAVE_NC4PAR_H 0)
endif()

if(HAVE_NC4PAR_H)
  set(NC4PAR_LIBS $ENV{PAR_NC_LIBS} CACHE STRING "")
#    set(LIBS "${LIBS} ${NC4PAR_LIBS}")
  set(HAVE_NC4PAR 1)
else()
  set(HAVE_NC4PAR 0)
endif()

#if(NC4PAR)
#  if(NC4PAR_LIBS AND NC4PAR_CPPFLAGS)
#    set(HAVE_NC4PAR 1)
#    find_path(NC4PAR_INCLUDE_DIR netcdf.h ${NC4PAR_DIR}/include)
#    if(NC4PAR_INCLUDE_DIR)
#      set(HAVE_NC4PAR_H 1)
#      include_directories(${NC4PAR_INCLUDE_DIR})
#      set(CPPFLAGS "${CPPFLAGS} ${NC4PAR_CPPFLAGS}")
#      set(LIBS "${LIBS} ${NC4PAR_LIBS}")
#    else()
#      set(HAVE_NC4PAR_H 0)
#      set(HAVE_NC4PAR 0)
#    endif()
#  else()
#    set(HAVE_NC4PAR 0)
#  endif()
#else()
#  set(HAVE_NC4PAR 0)
#  set(HAVE_NC4PAR_H 0)
#endif(NC4PAR)


# Use NC4PAR for bp2ncd if no sequential NETCDF was found
if(HAVE_NC4PAR)
  if(NOT HAVE_NETCDF)
    set(NETCDF_CPPFLAGS "${NC4PAR_CPPFLAGS}")
    set(NETCDF_CFLAGS "${NC4PAR_CFLAGS}")
    set(NETCDF_LIBS "${NC4PAR_LIBS}")
    set(HAVE_NETCDF 1)
    set(USE_PARALLEL_COMPILER 1)
    message(STATUS "Use NC4PAR for sequential NETCDF tools")
  endif()
endif()

# Define if you have NSSI.
set(HAVE_NSSI 0)

# Define if you have the Pablo.
set(HAVE_PABLO 0)

# Define if you have PHDF5.
if(PHDF5)
  set(PHDF5_LIBS $ENV{PAR_HDF5_LIBS} CACHE STRING "paralllel hdf5 libs")
  set(HAVE_PHDF5 1)
  find_path(PHDF5_INCLUDE_DIR hdf5.h ${PHDF5_DIR}/include)
  if(PHDF5_INCLUDE_DIR)
    set(HAVE_PHDF5_H 1)
#include_directories(${PHDF5_INCLUDE_DIR})
#    set(CPPFLAGS "${CPPFLAGS} ${PHDF5_FLAGS}")
#      set(LIBS "${LIBS} ${PHDF5_LIBS}")
  else()
    set(HAVE_PHDF5_H 0)
  endif()
else()
  set(HAVE_PHDF5_H 0)
  set(HAVE_PHDF5 0)
endif(PHDF5)

# Use PHDF5 for bp2h5 if no sequential HDF5 was found
if(HAVE_PHDF5)
  if(NOT HAVE_HDF5)
    set(HDF5_FLAGS "${PHDF5_FLAGS}")
    set(HDF5_LIBS "${PHDF5_LIBS}")
    set(HAVE_HDF5 1)
#    include_directories(${PHDF5_INCLUDE_DIR})
    set(USE_PARALLEL_COMPILER 1)
#    set(CPPFLAGS "${CPPFLAGS} ${PHDF5_FLAGS}")
#    set(LIBS "${LIBS} ${PHDF5_LIBS}")
    message(STATUS "Use PHDF5 for sequential HDF5 tools")
  endif()
endif()


# Define if you have POSIX threads libraries and header files.
set(HAVE_PTHREAD 0)
find_package(Threads)
if(Threads_FOUND)
  set(HAVE_PTHREAD 1)
  #INCLUDE_DIRECTORIES(${Threads_INCLUDE_PATH})
endif(Threads_FOUND)

# Define to 1 if you have the `pthread_yield' function.
CHECK_FUNCTION_EXISTS(pthread_yield HAVE_PTHREAD_YIELD)

# Define to 1 if you have the `PtlACEntry' function.
CHECK_FUNCTION_EXISTS(PtlACEntry HAVE_PTLACENTRY)
#set(HAVE_PTLACENTRY 0)

# Define to 1 if you have the `PtlErrorStr' function.
CHECK_FUNCTION_EXISTS(PtlErrorStr HAVE_PTLERRORSTR)

# Define to 1 if you have the `PtlEventKindStr' function.
CHECK_FUNCTION_EXISTS(PtlEventKindStr HAVE_PTLEVENTKINDSTR)

# Define to 1 if you have the `PtlGetJid' function.
CHECK_FUNCTION_EXISTS(PtlGetJid HAVE_PTLGETJID)

# Define to 1 if you have the `PtlNIFailStr' function.
CHECK_FUNCTION_EXISTS(PtlNIFailStr HAVE_PTLNIFAILSTR)

# Define to 1 if the system has the type `ptl_eq_handler_t'.
set(HAVE_PTL_EQ_HANDLER_T 0)

# Define if you have PTL_NOACK_REQ.
set(HAVE_PTL_NOACK_REQ 0)

# Define if you have PTL_NO_ACK_REQ.
set(HAVE_PTL_NO_ACK_REQ 0)

# Define to 1 if the system has the type `ptl_time_t'.
set(HAVE_PTL_TIME_T 0)

# Define to 1 if you have the `sched_yield' function.
CHECK_FUNCTION_EXISTS(sched_yield HAVE_SCHED_YIELD)

# Define to 1 if you have the <stdint.h> header file.
CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)

# Define to 1 if you have the <stdlib.h> header file.
CHECK_INCLUDE_FILES(stdlib.h HAVE_STDLIB_H)

# Define to 1 if you have the `strerror' function.
CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR)

# Define to 1 if cpp supports the ANSI  stringizing operator.
set(HAVE_STRINGIZE 0)

# Define to 1 if you have the <strings.h> header file.
CHECK_INCLUDE_FILES(strings.h HAVE_STRINGS_H)

# Define to 1 if you have the <string.h> header file.
CHECK_INCLUDE_FILES(string.h HAVE_STRING_H)

# Define to 1 if you have the `strncpy' function.
CHECK_FUNCTION_EXISTS(strncpy HAVE_STRNCPY)

# Define to 1 if you have the `strdup' function.
CHECK_FUNCTION_EXISTS(strdup HAVE_STRDUP)

# Define to 1 if you have the `strndup' function.
CHECK_FUNCTION_EXISTS(strndup HAVE_STRNDUP)

# Define to 1 if you have the `snprintf' function.
CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)

# Define to 1 if you have the `vsnprintf' function.
CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)

# Define to 1 if you have the <sys/stat.h> header file.
CHECK_INCLUDE_FILES(sys/stat.h HAVE_SYS_STAT_H)

# Define to 1 if you have the <sys/types.h> header file.
CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)

# Define to 1 if you have the <unistd.h> header file.
CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)

# Datatap is disabled
set(NO_DATATAP 1)

set(HAVE_ZLIB 0)
set(HAVE_ZLIB_H 0)
#CHECK_INCLUDE_FILES(zlib.h HAVE_ZLIB_H)
#find_library(ZLIB_LIBS NAMES libz.a PATHS ${ZIP_DIR}/lib)
#if(HAVE_ZLIB_H AND ZLIB_LIBS)

set(HAVE_ZLIB 0)
set(HAVE_ZLIB_H 0)
find_package(ZLIB)
if(ZLIB_FOUND)
  set(HAVE_ZLIB 1)
  set(HAVE_ZLIB_H 1)
#include_directories(${ZLIB_INCLUDE_DIRS})
  set(ZLIB_LIBS ${ZLIB_LIBRARIES})
  set(ZLIB_CPPFLAGS "-I${ZLIB_INCLUDE_DIRS}")
#  set(CPPFLAGS "${CPPFLAGS} ${ZLIB_CPPFLAGS}")
  set(ZLIB ON CACHE BOOL "")
else()
   set(ZLIB OFF CACHE BOOL "")
endif()

set(HAVE_GLIB 0)
if(GLIB)
  find_path(GLIB_INCLUDE_DIR1 NAMES glib.h PATHS ${GLIB_DIR}/include/glib-2.0/)
  set(GLIB_INCLUDE_DIR1 "${GLIB_INCLUDE_DIR1}" CACHE INTERNAL "Internal variable")
  find_path(GLIB_INCLUDE_DIR2 NAMES glibconfig.h PATHS ${GLIB_DIR}/lib/glib-2.0/include)
  set(GLIB_INCLUDE_DIR2 "${GLIB_INCLUDE_DIR2}" CACHE INTERNAL "Internal variable")
  set(GLIB_INCLUDE_DIR "${GLIB_INCLUDE_DIR1} ${GLIB_INCLUDE_DIR2}" CACHE FILEPATH "")
  find_library(GLIB_LIBS NAMES glib-2.0 PATHS ${GLIB_DIR}/lib NO_DEFAULT_PATH)
  if(GLIB_INCLUDE_DIR1 AND GLIB_INCLUDE_DIR2 AND GLIB_LIBS)
    set(HAVE_GLIB 1)
    set(GLIB_CPPFLAGS "-I${GLIB_INCLUDE_DIR1} -I${GLIB_INCLUDE_DIR2}")
  else()
    set(GLIB OFF CACHE BOOL "" FORCE)
  endif()
endif()

set(HAVE_FGR 0)
if(FGR)
  if(HAVE_GLIB)
    find_path(FGR_INCLUDE_DIR NAMES fgr.h PATHS ${FGR_DIR}/include)
    find_library(FGR_LIBS NAMES fgr PATHS ${FGR_DIR}/lib)
    if(FGR_INCLUDE_DIR AND FGR_LIBS)
      set(HAVE_FGR 1)
      set(FGR_CPPFLAGS "-I${FGR_INCLUDE_DIR}")
    else()
      set(FGR OFF CACHE BOOL "" FORCE)
    endif()
  else()
    set(FGR OFF CACHE BOOL "" FORCE)
  endif()
endif()

set(HAVE_LZ4 0)
if(LZ4)
  find_path(LZ4_INCLUDE_DIR NAMES lz4.h PATHS ${LZ4_DIR}/include)
  if(LZ4_INCLUDE_DIR)
    set(HAVE_LZ4_H 1)
  endif()
  find_library(LZ4_LIBS NAMES lz4 PATHS ${LZ4_DIR}/lib)
  if(LZ4_INCLUDE_DIR AND LZ4_LIBS)
    set(HAVE_LZ4 1)
    set(LZ4_CPPFLAGS "-I${LZ4_INCLUDE_DIR}")
  endif()
endif()

set(HAVE_BLOSC 0)
if(BLOSC)
  find_path(BLOSC_INCLUDE_DIR NAMES blosc.h PATHS ${BLOSC_DIR}/include)
  if(BLOSC_INCLUDE_DIR)
    set(HAVE_BLOSC_H 1)
  endif()
  find_library(BLOSC_LIBS NAMES blosc PATHS ${BLOSC_DIR}/lib)
  if(BLOSC_INCLUDE_DIR AND BLOSC_LIBS)
    set(HAVE_BLOSC 1)
    set(BLOSC_CPPFLAGS "-I${BLOSC_INCLUDE_DIR}")
  endif()
endif()

set(HAVE_BZIP2 0)
if(BZIP2)
  find_path(BZIP2_INCLUDE_DIR NAMES bzlib.h PATHS ${BZIP2_DIR}/include)
  if(BZIP2_INCLUDE_DIR)
    set(HAVE_BZLIB_H 1)
  endif()
  find_library(BZIP2_LIBS NAMES bz2 PATHS ${BZIP2_DIR}/lib)
  if(BZIP2_INCLUDE_DIR AND BZIP2_LIBS)
    set(HAVE_BZIP2 1)
    set(BZIP2_CPPFLAGS "-I${BZIP2_INCLUDE_DIR}")
#include_directories(${BZIP2_INCLUDE_DIR})
#    set(CPPFLAGS "${CPPFLAGS} ${BZIP2_CPPFLAGS}")
  endif()
endif()

set(HAVE_SZIP 0)
if(SZIP)
  find_path(SZIP_INCLUDE_DIR NAMES szlib.h PATHS ${SZIP_DIR}/include)
  if(SZIP_INCLUDE_DIR)
    set(HAVE_SZLIB_H 1)
  endif()
  find_library(SZIP_LIBS NAMES libsz.a PATHS ${SZIP_DIR}/lib)
  if(SZIP_INCLUDE_DIR AND SZIP_LIBS)
    set(HAVE_SZIP 1)
    set(SZIP_CPPFLAGS "-I${SZIP_INCLUDE_DIR}")
#include_directories(${SZIP_INCLUDE_DIR})
#    set(CPPFLAGS "${CPPFLAGS} ${SZIP_CPPFLAGS}")
  endif()
endif()

set(HAVE_ISOBAR 0)
if(ISOBAR)
  find_path(ISOBAR_INCLUDE_DIR NAMES isobar.h PATHS ${ISOBAR_DIR}/include)
  if(ISOBAR_INCLUDE_DIR)
    set(HAVE_ISOBAR_H 1)
  endif()
  find_library(ISOBAR_LIBS NAMES isobar PATHS ${ISOBAR_DIR}/lib)
  if(ISOBAR_INCLUDE_DIR AND ISOBAR_LIBS)
    set(HAVE_ISOBAR 1)
    set(ISOBAR_CPPFLAGS "-I${ISOBAR_INCLUDE_DIR}")
  endif()
endif()

set(HAVE_APLOD 0)
if(APLOD)
  find_path(APLOD_INCLUDE_DIR NAMES aplod.h PATHS ${APLOD_DIR}/include)
  if(APLOD_INCLUDE_DIR)
    set(HAVE_APLOD_H 1)
  endif()
  find_library(APLOD_LIBS NAMES aplod PATHS ${APLOD_DIR}/lib)
  if(APLOD_INCLUDE_DIR AND APLOD_LIBS)
    set(HAVE_APLOD 1)
    set(APLOD_CPPFLAGS "-I${APLOD_INCLUDE_DIR}")
  endif()
endif()

set(HAVE_ALACRITY 0)
if(ALACRITY)
  find_path(ALACRITY_INCLUDE_DIR NAMES alacrity.h PATHS ${ALACRITY_DIR}/include)
  find_library(ALACRITY_LIB NAMES alacrity PATHS ${ALACRITY_DIR}/lib)
  find_library(RIDCOMPRESS_LIB NAMES ridcompress PATHS ${ALACRITY_DIR}/lib)
  if(ALACRITY_INCLUDE_DIR AND ALACRITY_LIB AND RIDCOMPRESS_LIB)
    set(HAVE_ALACRITY 1)
    set(ALACRITY_CPPFLAGS "-I${ALACRITY_INCLUDE_DIR}")
    set(ALACRITY_LIBS ${ALACRITY_LIB} ${RIDCOMPRESS_LIB} -lstdc++ CACHE STRING "")
  endif()
endif()

set(HAVE_ZFP 0)
if(ZFP)
  find_path(ZFP_INCLUDE_DIR NAMES zfp.h PATHS ${ZFP_DIR}/inc ${ZFP_DIR}/include)
  if(ZFP_INCLUDE_DIR)
    set(HAVE_ZFP_H 1)
  endif()
  if (BUILD_ZFP)
    set(HAVE_ZFP 1)
    set(ZFP_CPPFLAGS "${MACRODEFFLAG}ZFP -I${ZFP_INCLUDE_DIR}")
    message(STATUS "ZFP will be built for ADIOS in ./src/zfp")
  else(BUILD_ZFP)
    find_library(ZFP_LIBS NAMES zfp PATHS ${ZFP_DIR}/lib)
    if(ZFP_INCLUDE_DIR AND ZFP_LIBS)
      set(HAVE_ZFP 1)
      set(ZFP_CPPFLAGS "${MACRODEFFLAG}ZFP -I${ZFP_INCLUDE_DIR}")
    endif()
    message(STATUS "ZFP will be used from ${ZFP_DIR}")
  endif(BUILD_ZFP)
else(ZFP)
  message(STATUS "ZFP is turned off")
endif(ZFP)

set(HAVE_SZ 0)
set(HAVE_SZ_H 0)
if(SZ)
  find_path(SZ_INCLUDE_DIR NAMES sz.h PATHS ${SZ_DIR}/include)
  if(SZ_INCLUDE_DIR)
    set(HAVE_SZ_H 1)
  endif()
  find_library(SZ_LIB1 NAMES libSZ.a PATHS ${SZ_DIR}/lib)
  find_library(SZ_LIB2 NAMES libzlib.a PATHS ${SZ_DIR}/lib)
  set(SZ_LIBS ${SZ_LIB1} ${SZ_LIB2} CACHE FILEPATH "SZ libraries")
  unset(SZ_LIB1 CACHE)
  unset(SZ_LIB2 CACHE)
  if(SZ_INCLUDE_DIR AND SZ_LIBS)
    set(HAVE_SZ 1)
    set(SZ_CPPFLAGS "-I${SZ_INCLUDE_DIR}")
  endif()
endif()

# Define to 1 if your C compiler doesn't accept -c and -o together.

# Name of package
set(PACKAGE adios)

# Define to the address where bug reports for this package should be sent.

# Define to the full name of this package.

# Define to the full name and version of this package.

# Define to the one symbol short name of this package.

# Define to the version of this package.

# Define to the necessary symbol if this constant uses a non-standard name on
# your system.

# ADIOS timing is enable

# Define to 1 if you have the ANSI C header files.

# Need to use MPI compiler for sequential utils

# Major version number
set(VERSION_MAJOR 1)

# Minor version number
set(VERSION_MINOR 13)

# Micro version number
set(VERSION_MICRO 0)

# Version number of package
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO})

# svn revision number
#set(VERSION_SVNREV 2007)

# Define HAVE_MPI_FALSE because it is used in generating the adios_config script
if(HAVE_MPI)
    set(HAVE_MPI_FALSE "#")
else(HAVE_MPI)
    set(HAVE_MPI_FALSE "")
endif(HAVE_MPI)

CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${PROJECT_BINARY_DIR}/config.h)
################################ end of generating config.h ###############################

#####################start processing src/public/adios_version.h.in #####################
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/src/public/adios_version.h.in
               ${CMAKE_CURRENT_BINARY_DIR}/src/public/adios_version.h @ONLY)
#####################end of processing src/public/adios_version.h #####################

################################ start of Fortran processing ##############################
if(BUILD_FORTRAN)
enable_language(Fortran)
message(STATUS "CMAKE_Fortran_COMPILER_WORKS =${CMAKE_Fortran_COMPILER_WORKS}")

include(FortranCInterface)
FortranCInterface_HEADER(${CMAKE_CURRENT_BINARY_DIR}/FC.h MACRO_NAMESPACE "FC_")
#FortranCInterface_VERIFY(CXX)
endif()
################################ end of Fortran processing ##############################
find_library(M_LIBS m)

# Generate flags for adios lib creation which depends on the packages we found
# ADIOSLIB_* for compiling libadios.a and libadiosf.a, and linking codes with those
# ADIOSLIB_SEQ_* for compiling libadios_nompi.a and libadiosf_nompi.a with dummy MPI
# ADIOSLIB_INT_* for codes using libadios_internal_nompi.a (like bp2ncd, bp2h5, bpdump etc)
# ADIOSREADLIB_* for codes using libadiosread.a, libadiosreadf.a
# ADIOSREADLIB_SEQ_* for codes using libadiosread_nompi.a
# adios_config will contain flags for users' code linking based on these flags
# EXTRA flags are used for compiling adios stuff, which need not go into adios_config for user codes
set(ADIOSLIB_EXTRA_CPPFLAGS "${MACRODEFFLAG}_FILE_OFFSET_BITS=64 ${MACRODEFFLAG}_LARGEFILE_SOURCE ${MACRODEFFLAG}_LARGEFILE64_SOURCE ${MACRODEFFLAG}_GNU_SOURCE ${CPPFLAGS}")
#message("${ADIOSLIB_EXTRA_CPPFLAGS}")
set(ADIOSLIB_LDADD "")
set(ADIOSLIB_CFLAGS "")
set(ADIOSLIB_CPPFLAGS "")
#message("ADIOSLIB_CPPFLAGS is ${ADIOSLIB_CPPFLAGS}")
set(ADIOSLIB_SEQ_CPPFLAGS "${MACRODEFFLAG}_NOMPI")
set(ADIOSLIB_SEQ_CFLAGS "")
set(ADIOSLIB_SEQ_LDADD "")
set(ADIOSLIB_INT_CPPFLAGS "${MACRODEFFLAG}_NOMPI")
set(ADIOSLIB_INT_CFLAGS "")
set(ADIOSLIB_INT_LDADD "")
set(ADIOSREADLIB_CPPFLAGS "")
set(ADIOSREADLIB_CFLAGS "")
set(ADIOSREADLIB_LDADD "")
set(ADIOSREADLIB_SEQ_CPPFLAGS "${MACRODEFFLAG}_NOMPI")
set(ADIOSREADLIB_SEQ_CFLAGS "")
set(ADIOSREADLIB_SEQ_LDADD "")

if(NOT NO_DATATAP)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${DT_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${DT_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${DT_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} ${DT_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${DT_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${DT_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} ${DT_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${DT_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${DT_LIBS})
endif()

if(HAVE_DATASPACES)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${DATASPACES_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${DATASPACES_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${DATASPACES_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} ${DATASPACES_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${DATASPACES_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} ${DATASPACES_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${DATASPACES_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${DATASPACES_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} ${DATASPACES_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${DATASPACES_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${DATASPACES_LIBS})
endif()

if(HAVE_DIMES)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${DIMES_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${DIMES_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${DIMES_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} ${DIMES_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${DIMES_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} ${DIMES_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${DIMES_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${DIMES_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} ${DIMES_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${DIMES_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${DIMES_LIBS})
endif()

if(HAVE_FLEXPATH)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${FP_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${FP_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${FP_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} ${FP_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${FP_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${FP_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} ${FP_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${FP_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${FP_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} ${FP_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${FP_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${FP_LIBS})
endif(HAVE_FLEXPATH)

if(HAVE_NSSI)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${NSSI_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${NSSI_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${NSSI_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} ${NSSI_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${NSSI_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${NSSI_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} ${NSSI_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${NSSI_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${NSSI_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} ${NSSI_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${NSSI_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${NSSI_LIBS})
endif()

if(HAVE_NC4PAR)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${NC4PAR_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${NC4PAR_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${NC4PAR_LIBS})
endif()

if(HAVE_PHDF5)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${PHDF5_FLAGS}")
#  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${PHDF5_FLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${PHDF5_LIBS})
endif()

if(HAVE_PORTALS)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${PORTALS_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${PORTALS_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${PORTALS_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} ${PORTALS_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${PORTALS_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${PORTALS_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} ${PORTALS_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${PORTALS_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${PORTALS_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} ${PORTALS_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${PORTALS_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${PORTALS_LIBS})
endif()

if(HAVE_INFINIBAND)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${INFINIBAND_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${INFINIBAND_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${INFINIBAND_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} ${INFINIBAND_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${INFINIBAND_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${INFINIBAND_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} ${INFINIBAND_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${INFINIBAND_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${INFINIBAND_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} ${INFINIBAND_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${INFINIBAND_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${INFINIBAND_LIBS})
endif()

if(HAVE_CRAY_PMI)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${CRAY_PMI_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${CRAY_PMI_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${CRAY_PMI_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} ${CRAY_PMI_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${CRAY_PMI_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${CRAY_PMI_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} ${CRAY_PMI_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${CRAY_PMI_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${CRAY_PMI_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} ${CRAY_PMI_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${CRAY_PMI_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${CRAY_PMI_LIBS})
endif()

if(HAVE_CRAY_UGNI)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${CRAY_UGNI_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${CRAY_UGNI_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${CRAY_UGNI_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} ${CRAY_UGNI_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${CRAY_UGNI_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${CRAY_UGNI_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} ${CRAY_UGNI_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${CRAY_UGNI_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${CRAY_UGNI_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} ${CRAY_UGNI_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${CRAY_UGNI_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${CRAY_UGNI_LIBS})
endif()

if(HAVE_NETCDF)
  set(ADIOSLIB_INT_CPPFLAGS "${ADIOSLIB_INT_CPPFLAGS} ${NETCDF_CPPFLAGS}")
  set(ADIOSLIB_INT_CFLAGS "${ADIOSLIB_INT_CFLAGS} ${NETCDF_CFLAGS}")
  set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${NETCDF_LIBS})
endif()

if(HAVE_HDF5)
  set(ADIOSLIB_INT_CPPFLAGS "${ADIOSLIB_INT_CPPFLAGS} ${HDF5_FLAGS}")
#  set(ADIOSLIB_INT_CFLAGS "${ADIOSLIB_INT_CFLAGS} ${HDF5_FLAGS}")
  set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${HDF5_LIBS})
endif()

if(HAVE_DMALLOC)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${MACRODEFFLAG}DMALLOC ${DMALLOC_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${DMALLOC_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${DMALLOC_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} ${DMALLOC_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${DMALLOC_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${DMALLOC_LIBS})
  set(ADIOSLIB_INT_CPPFLAGS "${ADIOSLIB_INT_CPPFLAGS} ${DMALLOC_CPPFLAGS}")
  set(ADIOSLIB_INT_CFLAGS "${ADIOSLIB_INT_CFLAGS} ${DMALLOC_CFLAGS}")
  set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${DMALLOC_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} ${DMALLOC_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${DMALLOC_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${DMALLOC_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} ${DMALLOC_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${DMALLOC_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${DMALLOC_LIBS})
endif()

if(HAVE_LUSTRE)
#  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${LUSTRE_CPPFLAGS}")
#  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${LUSTRE_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${LUSTRE_LIBS})
#  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} ${LUSTRE_CPPFLAGS}")
#  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${LUSTRE_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${LUSTRE_LIBS})
endif()

if(HAVE_FGR)
    set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${FGR_CPPFLAGS}")
    set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${FGR_CFLAGS}")
    set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${FGR_LIBS})
    set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} ${FGR_CPPFLAGS}")
    set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${FGR_CFLAGS}")
    set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${FGR_LIBS})
endif()

if(HAVE_GLIB)
    set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${GLIB_CPPFLAGS}")
    set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${GLIB_CFLAGS}")
    set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${GLIB_LIBS})
    set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} ${GLIB_CPPFLAGS}")
    set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${GLIB_CFLAGS}")
    set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${GLIB_LIBS})
endif()

if(HAVE_ZLIB)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} -DZLIB ${ZLIB_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${ZLIB_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${ZLIB_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} -DZLIB ${ZLIB_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${ZLIB_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${ZLIB_LIBS})
  set(ADIOSLIB_INT_CPPFLAGS "${ADIOSLIB_INT_CPPFLAGS} -DZLIB ${ZLIB_CPPFLAGS}")
  set(ADIOSLIB_INT_CFLAGS "${ADIOSLIB_INT_CFLAGS} ${ZLIB_CFLAGS}")
  set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${ZLIB_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} -DZLIB ${ZLIB_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${ZLIB_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${ZLIB_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} -DZLIB ${ZLIB_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${ZLIB_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${ZLIB_LIBS})
endif()

if(HAVE_LZ4)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} -DLZ4 ${LZ4_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${LZ4_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${LZ4_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} -DLZ4 ${LZ4_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${LZ4_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${LZ4_LIBS})
  set(ADIOSLIB_INT_CPPFLAGS "${ADIOSLIB_INT_CPPFLAGS} -DLZ4 ${LZ4_CPPFLAGS}")
  set(ADIOSLIB_INT_CFLAGS "${ADIOSLIB_INT_CFLAGS} ${LZ4_CFLAGS}")
  set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${LZ4_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} -DLZ4 ${LZ4_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${LZ4_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${LZ4_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} -DLZ4 ${LZ4_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${LZ4_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${LZ4_LIBS})
endif()

if(HAVE_BLOSC)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} -DBLOSC ${BLOSC_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${BLOSC_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${BLOSC_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} -DBLOSC ${BLOSC_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${BLOSC_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${BLOSC_LIBS})
  set(ADIOSLIB_INT_CPPFLAGS "${ADIOSLIB_INT_CPPFLAGS} -DBLOSC ${BLOSC_CPPFLAGS}")
  set(ADIOSLIB_INT_CFLAGS "${ADIOSLIB_INT_CFLAGS} ${BLOSC_CFLAGS}")
  set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${BLOSC_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} -DBLOSC ${BLOSC_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${BLOSC_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${BLOSC_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} -DBLOSC ${BLOSC_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${BLOSC_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${BLOSC_LIBS})
endif()

if(HAVE_BZIP2)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} -DBZIP2 ${BZIP2_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${BZIP2_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${BZIP2_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} -DBZIP2 ${BZIP2_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${BZIP2_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${BZIP2_LIBS})
  set(ADIOSLIB_INT_CPPFLAGS "${ADIOSLIB_INT_CPPFLAGS} -DBZIP2 ${BZIP2_CPPFLAGS}")
  set(ADIOSLIB_INT_CFLAGS "${ADIOSLIB_INT_CFLAGS} ${BZIP2_CFLAGS}")
  set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${BZIP2_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} -DBZIP2 ${BZIP2_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${BZIP2_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${BZIP2_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} -DBZIP2 ${BZIP2_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${BZIP2_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${BZIP2_LIBS})
endif()

if(HAVE_SZIP)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} -DSZIP ${SZIP_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${SZIP_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${SZIP_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} -DSZIP ${SZIP_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${SZIP_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${SZIP_LIBS})
  set(ADIOSLIB_INT_CPPFLAGS "${ADIOSLIB_INT_CPPFLAGS} -DSZIP ${SZIP_CPPFLAGS}")
  set(ADIOSLIB_INT_CFLAGS "${ADIOSLIB_INT_CFLAGS} ${SZIP_CFLAGS}")
  set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${SZIP_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} -DSZIP ${SZIP_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${SZIP_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${SZIP_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS="${ADIOSREADLIB_SEQ_CPPFLAGS} -DSZIP ${SZIP_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS="${ADIOSREADLIB_SEQ_CFLAGS} ${SZIP_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${SZIP_LIBS})
endif()

if(HAVE_ISOBAR)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} -DISOBAR ${ISOBAR_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${ISOBAR_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${ISOBAR_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} -DISOBAR ${ISOBAR_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${ISOBAR_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${ISOBAR_LIBS})
  set(ADIOSLIB_INT_CPPFLAGS "${ADIOSLIB_INT_CPPFLAGS} -DISOBAR ${ISOBAR_CPPFLAGS}")
  set(ADIOSLIB_INT_CFLAGS "${ADIOSLIB_INT_CFLAGS} ${ISOBAR_CFLAGS}")
  set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${ISOBAR_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} -DISOBAR ${ISOBAR_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${ISOBAR_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${ISOBAR_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} -DISOBAR ${ISOBAR_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${ISOBAR_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${ISOBAR_LIBS})
endif()

if(HAVE_APLOD)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} -DAPLOD ${APLOD_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${APLOD_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${APLOD_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} -DAPLOD ${APLOD_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${APLOD_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${APLOD_LIBS})
  set(ADIOSLIB_INT_CPPFLAGS "${ADIOSLIB_INT_CPPFLAGS} -DAPLOD ${APLOD_CPPFLAGS}")
  set(ADIOSLIB_INT_CFLAGS "${ADIOSLIB_INT_CFLAGS} ${APLOD_CFLAGS}")
  set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${APLOD_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} -DAPLOD ${APLOD_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${APLOD_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${APLOD_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} -DAPLOD ${APLOD_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${APLOD_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${APLOD_LIBS})
endif()

if(HAVE_ALACRITY)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} -DALACRITY ${ALACRITY_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${ALACRITY_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${ALACRITY_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} -DALACRITY ${ALACRITY_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${ALACRITY_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${ALACRITY_LIBS})
  set(ADIOSLIB_INT_CPPFLAGS "${ADIOSLIB_INT_CPPFLAGS} -DALACRITY ${ALACRITY_CPPFLAGS}")
  set(ADIOSLIB_INT_CFLAGS "${ADIOSLIB_INT_CFLAGS} ${ALACRITY_CFLAGS}")
  set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${ALACRITY_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} -DALACRITY ${ALACRITY_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${ALACRITY_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${ALACRITY_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} -DALACRITY ${ALACRITY_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${ALACRITY_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${ALACRITY_LIBS})
endif()

if(HAVE_ZFP)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${ZFP_CPPFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${ZFP_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} ${ZFP_CPPFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${ZFP_LIBS})
  set(ADIOSLIB_INT_CPPFLAGS "${ADIOSLIB_INT_CPPFLAGS} ${ZFP_CPPFLAGS}")
  set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${ZFP_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} ${ZFP_CPPFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${ZFP_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} ${ZFP_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${ZFP_LIBS})
endif()

if(HAVE_SZ)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} ${SZ_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${SZ_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${SZ_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} ${SZ_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${SZ_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${SZ_LIBS})
  set(ADIOSLIB_INT_CPPFLAGS "${ADIOSLIB_INT_CPPFLAGS} ${SZ_CPPFLAGS}")
  set(ADIOSLIB_INT_CFLAGS "${ADIOSLIB_INT_CFLAGS} ${SZ_CFLAGS}")
  set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${SZ_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} ${SZ_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${SZ_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${SZ_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS="${ADIOSREADLIB_SEQ_CPPFLAGS} ${SZ_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS="${ADIOSREADLIB_SEQ_CFLAGS} ${SZ_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${SZ_LIBS})
endif()

if(HAVE_FASTBIT)
  set(ADIOSLIB_CPPFLAGS "${ADIOSLIB_CPPFLAGS} -DFASTBIT ${FASTBIT_CPPFLAGS}")
  set(ADIOSLIB_CFLAGS "${ADIOSLIB_CFLAGS} ${FASTBIT_CFLAGS}")
  set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${FASTBIT_LIBS})
  set(ADIOSLIB_SEQ_CPPFLAGS "${ADIOSLIB_SEQ_CPPFLAGS} -DFASTBIT ${FASTBIT_CPPFLAGS}")
  set(ADIOSLIB_SEQ_CFLAGS "${ADIOSLIB_SEQ_CFLAGS} ${FASTBIT_CFLAGS}")
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${FASTBIT_LIBS})
  set(ADIOSLIB_INT_CPPFLAGS "${ADIOSLIB_INT_CPPFLAGS} -DFASTBIT ${FASTBIT_CPPFLAGS}")
  set(ADIOSLIB_INT_CFLAGS "${ADIOSLIB_INT_CFLAGS} ${FASTBIT_CFLAGS}")
  set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${FASTBIT_LIBS})
  set(ADIOSREADLIB_CPPFLAGS "${ADIOSREADLIB_CPPFLAGS} -DFASTBIT ${FASTBIT_CPPFLAGS}")
  set(ADIOSREADLIB_CFLAGS "${ADIOSREADLIB_CFLAGS} ${FASTBIT_CFLAGS}")
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${FASTBIT_LIBS})
  set(ADIOSREADLIB_SEQ_CPPFLAGS "${ADIOSREADLIB_SEQ_CPPFLAGS} -DFASTBIT ${FASTBIT_CPPFLAGS}")
  set(ADIOSREADLIB_SEQ_CFLAGS "${ADIOSREADLIB_SEQ_CFLAGS} ${FASTBIT_CFLAGS}")
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${FASTBIT_LIBS})
endif()


set(ADIOSLIB_LDADD ${ADIOSLIB_LDADD} ${M_LIBS})
set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${M_LIBS})
set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${M_LIBS})
set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${M_LIBS})
set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${M_LIBS})
############################### srart of top CMakeLists.txt ###############################
#install(PROGRAMS adios_config DESTINATION ${bindir})

#if(HAVE_NSSI)
#install(PROGRAMS scripts/create.nssi.config.sh DESTINATION ${bindir})
#install(PROGRAMS scripts/kill.nssi.staging.sh DESTINATION ${bindir})
#install(PROGRAMS scripts/start.nssi.staging.sh DESTINATION  ${bindir})
#endif(HAVE_NSSI)



#add_definitions(-DO_LARGEFILE=0)

get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES)
message(STATUS "${_LANGUAGES_}")

#####################start processing adios_config.flags.in #####################
set(ADIOS_DIR "${CMAKE_INSTALL_PREFIX}")

string(REGEX REPLACE ";" " " ADIOSLIB_LDADD_M "${ADIOSLIB_LDADD}")
string(REGEX REPLACE ";" " " ADIOSREADLIB_LDADD_M "${ADIOSREADLIB_LDADD}")
string(REGEX REPLACE ";" " " ADIOSREADLIB_SEQ_LDADD_M "${ADIOSREADLIB_SEQ_LDADD}")
string(REGEX REPLACE ";" " " ADIOSLIB_SEQ_LDADD_M "${ADIOSLIB_SEQ_LDADD}")
string(REGEX REPLACE ";" " " ADIOSLIB_INT_LDADD_M "${ADIOSLIB_INT_LDADD}")

CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/adios_config.flags.cmake ${CMAKE_CURRENT_BINARY_DIR}/adios_config.flags @ONLY)
#####################end of processing adios_config.flags.in #####################
#####################start processing adios_config.flags.in #####################
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/adios_config.makesrc.in ${CMAKE_CURRENT_BINARY_DIR}/adios_config @ONLY)
#####################end of processing adios_config.flags.in #####################
install(FILES ${CMAKE_BINARY_DIR}/adios_config.flags DESTINATION ${sysconfdir})
install(PROGRAMS ${CMAKE_BINARY_DIR}/adios_config DESTINATION ${bindir})
install(FILES ${PROJECT_SOURCE_DIR}/scripts/FindADIOS.cmake DESTINATION ${sysconfdir})
#install(FILES ${PROJECT_SOURCE_DIR}/adios_git_status DESTINATION ${sysconfdir})


################ Add EXTRA_LIBS to LIBS now, e.g. internal mxml library not needed for linking ###########

if (NOT BUILD_MXML)
  set(ADIOSLIB_LDADD     ${ADIOSLIB_LDADD}     ${MXML_LIBS})
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${MXML_LIBS})
  set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${MXML_LIBS})
endif()

if (NOT BUILD_ZFP)
  set(ADIOSLIB_LDADD     ${ADIOSLIB_LDADD}     ${ZFP_LIBS})
  set(ADIOSLIB_SEQ_LDADD ${ADIOSLIB_SEQ_LDADD} ${ZFP_LIBS})
  set(ADIOSLIB_INT_LDADD ${ADIOSLIB_INT_LDADD} ${ZFP_LIBS})
  set(ADIOSREADLIB_LDADD ${ADIOSREADLIB_LDADD} ${ZFP_LIBS})
  set(ADIOSREADLIB_SEQ_LDADD ${ADIOSREADLIB_SEQ_LDADD} ${ZFP_LIBS})
endif()

add_subdirectory(src)
add_subdirectory(utils)
add_subdirectory(tests)
add_subdirectory(examples)
############################### end of top CMakeLists.txt ###############################

message("*********************************")
message("${PACKAGE} configured as follows:")
message("*********************************")
message("")
if(BUILD_WRITE)
  message("  - Build both the Write and Read libraries")
else()
  message("  - Build only the Read libraries")
endif()
if(BUILD_FORTRAN)
  message("  - Build both the C and Fortran libraries")
else()
  message("  - Build only the C libraries (no Fortran)")
endif()
message("")
message("  - General Compile FLAGS")
message("      - CC  = $ENV{CC}")
message("      - CXX = $ENV{CXX}")
message("      - FC  = $ENV{FC}")
message("      - CPPFLAGS = ${CPPFLAGS}")
message("      - CFLAGS   = ${CFLAGS}")
message("      - CXXFLAGS = ${CXXFLAGS}")
message("      - FCFLAGS  = ${FCFLAGS}")
message("      - LIBS     = ${LIBS}")
message("      - MPILIBS  = ${MPILIBS}")
message("")

if(ADIOS_TIMERS)
 message("  - ADIOS Timers Enabled")
else()
  message("  - ADIOS Timers Disabled")
endif()

if(ADIOS_TIMER_EVENTS)
 message("  - ADIOS Timer Events Enabled")
else()
  message("  - ADIOS Timer Events Disabled")
endif()

if(BUILD_MXML)
  message("  - MXML -- Build with ADIOS")
else(BUILD_MXML)
  if(HAVE_MXML)
    message("  - MXML")
    message("      - MXML INCLUDE DIR = ${MXML_INCLUDE_DIR}")
    message("      - MXML_LIBS = ${MXML_LIBS}")
    message("")
  else(HAVE_MXML)
    message("  - No MXML")
  endif(HAVE_MXML)
endif(BUILD_MXML)

if(HAVE_LUSTRE)
  message("  - LUSTRE")
  message("      - LUSTRE_CFLAGS = ${LUSTRE_CFLAGS}")
  message("      - LUSTRE_CPPFLAGS = ${LUSTRE_CPPFLAGS}")
  message("      - LUSTRE_LIBS = ${LUSTRE_LIBS}")
  message("")
else()
  message("  - No LUSTRE")
endif()

if(HAVE_FGR)
    message("  - FGR")
    message("      - FGR_CFLAGS = ${FGR_CFLAGS}")
    message("      - FGR_CPPFLAGS = ${FGR_CPPFLAGS}")
    message("      - FGR_LIBS = ${FGR_LIBS}")
else()
  message("  - No FGR")
endif()

if(HAVE_GLIB)
  message("  - GLIB")
  message("      - GLIB_CFLAGS = ${GLIB_CFLAGS}")
  message("      - GLIB_CPPFLAGS = ${GLIB_CPPFLAGS}")
  message("      - GLIB_LIBS = ${GLIB_LIBS}")
else()
  message("  - No GLIB")
endif()

message("  - Networking library for staging methods:")
if(HAVE_PORTALS)
  message("    - PORTALS")
  message("      - PORTALS_CFLAGS = ${PORTALS_CFLAGS}")
  message("      - PORTALS_CPPFLAGS = ${PORTALS_CPPFLAGS}")
  message("      - PORTALS_LIBS = ${PORTALS_LIBS}")
  message("")
endif()

if(HAVE_INFINIBAND)
  message("    - INFINIBAND")
  message("      - INFINIBAND_CFLAGS = ${INFINIBAND_CFLAGS}")
  message("      - INFINIBAND_CPPFLAGS = ${INFINIBAND_CPPFLAGS}")
  message("      - INFINIBAND_LIBS = ${INFINIBAND_LIBS}")
  message("")
endif()

if(HAVE_CRAY_PMI AND HAVE_CRAY_UGNI)
  message("    - CRAY uGNI with PMI")
  message("      - CFLAGS = ${CRAY_PMI_CFLAGS} ${CRAY_UGNI_CFLAGS}")
  message("      - CPPFLAGS = ${CRAY_PMI_CPPFLAGS} ${CRAY_UGNI_CPPFLAGS}")
  message("      - LIBS = ${CRAY_PMI_LIBS} ${CRAY_UGNI_LIBS}")
  message("")
endif()

if(HAVE_DCMF)
  message("    - IBM DCMF")
  message("      - DCMF_CFLAGS = ${DCMF_CFLAGS}")
  message("      - DCMF_CPPFLAGS = ${DCMF_CPPFLAGS}")
  message("      - DCMF_LIBS = ${DCMF_LIBS}")
  message("")
endif()

if(HAVE_DATASPACES)
  message("  - DATASPACES transport method")
  message("      - DATASPACES_CFLAGS = ${DATASPACES_CFLAGS}")
  message("      - DATASPACES_CPPFLAGS = ${DATASPACES_CPPFLAGS}")
  message("      - DATASPACES_LIBS = ${DATASPACES_LIBS}")
  message("")
else()
  message("  - No DATASPACES to build DATASPACES transport method")
endif()

if(HAVE_DIMES)
  message("  - DIMES transport method")
  message("      - DIMES_CFLAGS = ${DIMES_CFLAGS}")
  message("      - DIMES_CPPFLAGS = ${DIMES_CPPFLAGS}")
  message("      - DIMES_LIBS = ${DIMES_LIBS}")
  message("")
else()
  message("  - No DIMES to build DIMES transport method")
endif()

if(HAVE_PHDF5)
  message("  - PHDF5")
  message("      - PHDF5_CFLAGS = ${PHDF5_CFLAGS}")
  message("      - PHDF5_CPPFLAGS = ${PHDF5_FLAGS}")
  message("      - PHDF5_LIBS = ${PHDF5_LIBS}")
  message("")
else()
  message("  - No PHDF5 to build PHDF5 transport method")
endif()

if(HAVE_HDF5)
  message("  - HDF5")
  message("      - HDF5_CFLAGS = ${HDF5_CFLAGS}")
  message("      - HDF5_FLAGS = ${HDF5_FLAGS}")
  message("      - HDF5_LIBS = ${HDF5_LIBS}")
  message("")
else()
  message("  - No HDF5")
endif()

if(HAVE_NC4PAR)
  message("  - NetCDF 4 Parallel")
  message("      - NC4PAR_CFLAGS = ${NC4PAR_CFLAGS}")
  message("      - NC4PAR_CPPFLAGS = ${NC4PAR_CPPFLAGS}")
  message("      - NC4PAR_LIBS = ${NC4PAR_LIBS}")
  message("")
else()
  message("  - No NETCDF 4 Parallel to build NC4 transport method")
endif()

if(HAVE_NETCDF)
  message("  - NetCDF")
  message("      - NETCDF_CFLAGS = ${NETCDF_CFLAGS}")
  message("      - NETCDF_CPPFLAGS = ${NETCDF_CPPFLAGS}")
  message("      - NETCDF_LIBS = ${NETCDF_LIBS}")
  message("")
else()
  message("  - No NetCDF")
endif()

if(HAVE_FLEXPATH)
  message("  - FLEXPATH")
  message("      - FP_CFLAGS = ${FP_CFLAGS}")
  message("      - FP_CPPFLAGS = ${FP_CPPFLAGS}")
  message("      - FP_LIBS = ${FP_LIBS}")
  message("")
else()
  message("  - No FLEXPATH to build FLEXPATH transport method")
endif()

if(HAVE_ICEE)
  message("  - ICEE")
  message("      - FP_CFLAGS = ${FP_CFLAGS}")
  message("      - FP_CPPFLAGS = ${FP_CPPFLAGS}")
  message("      - FP_LIBS = ${FP_LIBS}")
  message("")
else()
  message("  - No ICEE to build ICEE transport method")
endif()

if(HAVE_ZLIB)
  message("  - ZLIB")
  message("      - ZLIB_CFLAGS = ${ZLIB_CFLAGS}")
  message("      - ZLIB_CPPFLAGS = ${ZLIB_CPPFLAGS}")
  message("      - ZLIB_LIBS = ${ZLIB_LIBS}")
  message("")
else()
  message("  - No ZLIB to build ZLIB transform method")
endif()

if(HAVE_LZ4)
  message("  - LZ4")
  message("      - LZ4_CFLAGS = ${LZ4_CFLAGS}")
  message("      - LZ4_CPPFLAGS = ${LZ4_CPPFLAGS}")
  message("      - LZ4_LIBS = ${LZ4_LIBS}")
  message("")
else()
  message("  - No LZ4 to build LZ4 transform method")
endif()

if(HAVE_BLOSC)
  message("  - BLOSC")
  message("      - BLOSC_CFLAGS = ${BLOSC_CFLAGS}")
  message("      - BLOSC_CPPFLAGS = ${BLOSC_CPPFLAGS}")
  message("      - BLOSC_LIBS = ${BLOSC_LIBS}")
  message("")
else()
  message("  - No BLOSC to build BLOSC transform method")
endif()

if(HAVE_BZIP2)
  message("  - BZIP2")
  message("      - BZIP2_CFLAGS = ${BZIP2_CFLAGS}")
  message("      - BZIP2_CPPFLAGS = ${BZIP2_CPPFLAGS}")
  message("      - BZIP2_LIBS = ${BZIP2_LIBS}")
  message("")
else()
  message("  - No BZIP2 to build BZIP2 transform method")
endif()

if(HAVE_SZIP)
  message("  - SZIP")
  message("      - SZIP_CFLAGS = ${SZIP_CFLAGS}")
  message("      - SZIP_CPPFLAGS = ${SZIP_CPPFLAGS}")
  message("      - SZIP_LIBS = ${SZIP_LIBS}")
  message("")
else()
  message("  - No SZIP to build SZIP transform method")
endif()

if(HAVE_ISOBAR)
  message("  - ISOBAR")
  message("      - ISOBAR_CFLAGS = ${ISOBAR_CFLAGS}")
  message("      - ISOBAR_CPPFLAGS = ${ISOBAR_CPPFLAGS}")
  message("      - ISOBAR_LIBS = ${ISOBAR_LIBS}")
  message("")
else()
  message("  - No ISOBAR to build ISOBAR transform method")
endif()

if(HAVE_APLOD)
  message("  - APLOD")
  message("      - APLOD_CFLAGS = ${APLOD_CFLAGS}")
  message("      - APLOD_CPPFLAGS = ${APLOD_CPPFLAGS}")
  message("      - APLOD_LIBS = ${APLOD_LIBS}")
message("")
else()
  message("  - No APLOD to build APLOD transform method")
endif()

if(HAVE_FASTBIT)
  message("  - FASTBIT")
  message("      - FASTBIT_CFLAGS = ${FASTBIT_CFLAGS}")
  message("      - FASTBIT_CPPFLAGS = ${FASTBIT_CPPFLAGS}")
  message("      - FASTBIT_LIBS = ${FASTBIT_LIBS}")
  message("")
else()
  message("  - No FASTBIT to build FASTBIT query method")
endif()

if(HAVE_ALACRITY)
  message("  - ALACRITY")
  message("      - ALACRITY_CFLAGS = ${ALACRITY_CFLAGS}")
  message("      - ALACRITY_CPPFLAGS = ${ALACRITY_CPPFLAGS}")
  message("      - ALACRITY_LIBS = ${ALACRITY_LIBS}")
  message("")
else()
  message("  - No ALACRITY to build ALACRITY transform & query method")
endif()

if(BUILD_ZFP)
  message("  - ZFP is built with ADIOS")
elseif (HAVE_ZFP)
    message("  - ZFP")
    message("      - ZFP_CPPFLAGS = ${ZFP_CPPFLAGS}")
    message("      - ZFP_LIBS = ${ZFP_LIBS}")
    message("")
else()
    message("  - No ZFP to build ZFP transform method")
endif()

if(HAVE_SZ)
  message("  - SZ")
  message("      - SZ_CFLAGS = ${SZ_CFLAGS}")
  message("      - SZ_CPPFLAGS = ${SZ_CPPFLAGS}")
  message("      - SZ_LIBS = ${SZ_LIBS}")
  message("")
else()
  message("  - No SZ to build SZ transform method")
endif()

if(HAVE_BGQ)
  message("  - BGQ METHOD is enabled")
else()
  message("  - BGQ METHOD is disabled")
endif()

message("")
message("  - Install path = ${prefix}")
message("")
