PROJECT(VTKHDF5 C)
INCLUDE_REGULAR_EXPRESSION("^.*\\.[ch]$")

SET(LIBRARY_OUTPUT_PATH ${VTKHDF5_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
SET(EXECUTABLE_OUTPUT_PATH ${VTKHDF5_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)

IF(WIN32)
  SET(ssize_t long)
  SET(SIZEOF_SIZE_T 4)
  SET(SIZEOF_SSIZE_T 4)
  SET(HAVE_LARGE_HSIZET 1)
ENDIF(WIN32)

# Include all the necessary files for macros
INCLUDE (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFiles.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckLibraryExists.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckSymbolExists.cmake)
INCLUDE (${CMAKE_ROOT}/Modules/CheckTypeSize.cmake)

# This macro checks if the symbol exists in the library and if it
# does, it appends library to the list.
SET(LINK_LIBS "")
MACRO(CHECK_LIBRARY_EXISTS_CONCAT LIBRARY SYMBOL VARIABLE)
  CHECK_LIBRARY_EXISTS("${LIBRARY};${LINK_LIBS}" ${SYMBOL} "" 
    ${VARIABLE})
  IF(${VARIABLE})
    SET(LINK_LIBS ${LINK_LIBS} ${LIBRARY})
  ENDIF(${VARIABLE})
ENDMACRO(CHECK_LIBRARY_EXISTS_CONCAT)

CHECK_LIBRARY_EXISTS_CONCAT("m" printf HAVE_LIBM)
CHECK_LIBRARY_EXISTS_CONCAT("ws2_32" printf HAVE_LIBWS2_32)
CHECK_LIBRARY_EXISTS_CONCAT("wsock32" printf HAVE_LIBWSOCK32)

SET(USE_INCLUDES "")
# Check if header file exists and add it to the list.
MACRO(CHECK_INCLUDE_FILE_CONCAT FILE VARIABLE)
  CHECK_INCLUDE_FILES("${USE_INCLUDES};${FILE}" ${VARIABLE})
  IF(${VARIABLE})
    SET(USE_INCLUDES ${USE_INCLUDES} ${FILE})
  ENDIF(${VARIABLE})
ENDMACRO(CHECK_INCLUDE_FILE_CONCAT)

CHECK_INCLUDE_FILE_CONCAT("globus/common.h" HAVE_GLOBUS_COMMON_H)
CHECK_INCLUDE_FILE_CONCAT("io.h" HAVE_IO_H)
CHECK_INCLUDE_FILE_CONCAT("mfhdf.h" HAVE_MFHDF_H)
CHECK_INCLUDE_FILE_CONCAT("netinet/tcp.h" HAVE_NETINET_TCP_H)
CHECK_INCLUDE_FILE_CONCAT("pdb.h" HAVE_PDB_H)
CHECK_INCLUDE_FILE_CONCAT("pthread.h" HAVE_PTHREAD_H)
CHECK_INCLUDE_FILE_CONCAT("setjmp.h" HAVE_SETJMP_H)
CHECK_INCLUDE_FILE_CONCAT("srbclient.h" HAVE_SRBCLIENT_H)
CHECK_INCLUDE_FILE_CONCAT("stddef.h" HAVE_STDDEF_H)
CHECK_INCLUDE_FILE_CONCAT("stdint.h" HAVE_STDINT_H)
CHECK_INCLUDE_FILE_CONCAT("sys/filio.h" HAVE_SYS_FILIO_H)
CHECK_INCLUDE_FILE_CONCAT("sys/ioctl.h" HAVE_SYS_IOCTL_H)
CHECK_INCLUDE_FILE_CONCAT("sys/proc.h" HAVE_SYS_PROC_H)
CHECK_INCLUDE_FILE_CONCAT("sys/resource.h" HAVE_SYS_RESOURCE_H)
CHECK_INCLUDE_FILE_CONCAT("sys/socket.h" HAVE_SYS_SOCKET_H)
CHECK_INCLUDE_FILE_CONCAT("sys/stat.h" HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILE_CONCAT("sys/sysinfo.h" HAVE_SYS_SYSINFO_H)
CHECK_INCLUDE_FILE_CONCAT("sys/time.h" HAVE_SYS_TIME_H)
CHECK_INCLUDE_FILE_CONCAT("sys/timeb.h" HAVE_SYS_TIMEB_H)
CHECK_INCLUDE_FILE_CONCAT("sys/types.h" HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILE_CONCAT("unistd.h" HAVE_UNISTD_H)
CHECK_INCLUDE_FILE_CONCAT("winsock.h" HAVE_WINSOCK_H)
CHECK_INCLUDE_FILE_CONCAT("zlib.h" HAVE_ZLIB_H)

CHECK_TYPE_SIZE(char           SIZEOF_CHAR)
CHECK_TYPE_SIZE(short          SIZEOF_SHORT)
CHECK_TYPE_SIZE(int            SIZEOF_INT)
CHECK_TYPE_SIZE(long           SIZEOF_LONG)
CHECK_TYPE_SIZE(float          SIZEOF_FLOAT)
CHECK_TYPE_SIZE(double         SIZEOF_DOUBLE)
CHECK_TYPE_SIZE("long double"  SIZEOF_LONG_DOUBLE)
CHECK_TYPE_SIZE(int8_t         SIZEOF_INT8_T)
CHECK_TYPE_SIZE(uint8_t        SIZEOF_UINT8_T)
CHECK_TYPE_SIZE(int_least8_t   SIZEOF_INT_LEAST8_T)
CHECK_TYPE_SIZE(uint_least8_t  SIZEOF_UINT_LEAST8_T)
CHECK_TYPE_SIZE(int_fast8_t    SIZEOF_INT_FAST8_T)
CHECK_TYPE_SIZE(uint_fast8_t   SIZEOF_UINT_FAST8_T)
CHECK_TYPE_SIZE(int16_t        SIZEOF_INT16_T)
CHECK_TYPE_SIZE(uint16_t       SIZEOF_UINT16_T)
CHECK_TYPE_SIZE(int_least16_t  SIZEOF_INT_LEAST16_T)
CHECK_TYPE_SIZE(uint_least16_t SIZEOF_UINT_LEAST16_T)
CHECK_TYPE_SIZE(int_fast16_t   SIZEOF_INT_FAST16_T)
CHECK_TYPE_SIZE(uint_fast16_t  SIZEOF_UINT_FAST16_T)
CHECK_TYPE_SIZE(int32_t        SIZEOF_INT32_T)
CHECK_TYPE_SIZE(uint32_t       SIZEOF_UINT32_T)
CHECK_TYPE_SIZE(int_least32_t  SIZEOF_INT_LEAST32_T)
CHECK_TYPE_SIZE(uint_least32_t SIZEOF_UINT_LEAST32_T)
CHECK_TYPE_SIZE(int_fast32_t   SIZEOF_INT_FAST32_T)
CHECK_TYPE_SIZE(uint_fast32_t  SIZEOF_UINT_FAST32_T)
CHECK_TYPE_SIZE(int64_t        SIZEOF_INT64_T)
CHECK_TYPE_SIZE(uint64_t       SIZEOF_UINT64_T)
CHECK_TYPE_SIZE(jdshkjfhdks    SIZEOF_JDSHKJFHDKS)
CHECK_TYPE_SIZE(int_least64_t  SIZEOF_INT_LEAST64_T)
CHECK_TYPE_SIZE(uint_least64_t SIZEOF_UINT_LEAST64_T)
CHECK_TYPE_SIZE(int_fast64_t   SIZEOF_INT_FAST64_T)
CHECK_TYPE_SIZE(uint_fast64_t  SIZEOF_UINT_FAST64_T)
CHECK_TYPE_SIZE(size_t         SIZEOF_SIZE_T)
CHECK_TYPE_SIZE(ssize_t        SIZEOF_SSIZE_T)
CHECK_TYPE_SIZE(off_t          SIZEOF_OFF_T)
CHECK_TYPE_SIZE(__int64        SIZEOF___INT64)
CHECK_TYPE_SIZE("long long"    SIZEOF_LONG_LONG)

# For other tests to use the same libraries
SET(CMAKE_REQUIRED_LIBRARIES ${LINK_LIBS})

# Check for some functions that are used
CHECK_FUNCTION_EXISTS(strdup            HAVE_STRDUP)
CHECK_FUNCTION_EXISTS(snprintf          HAVE_SNPRINTF)
CHECK_FUNCTION_EXISTS(system            HAVE_SYSTEM)
CHECK_FUNCTION_EXISTS(vsnprintf         HAVE_VSNPRINTF)
CHECK_FUNCTION_EXISTS(waitpid           HAVE_WAITPID)
CHECK_FUNCTION_EXISTS(signal            HAVE_SIGNAL)
CHECK_FUNCTION_EXISTS(ioctl             HAVE_IOCTL)
CHECK_FUNCTION_EXISTS(sigaction         HAVE_SIGACTION)
CHECK_FUNCTION_EXISTS(getpwuid          HAVE_GETPWUID)
CHECK_FUNCTION_EXISTS(getrusage         HAVE_GETRUSAGE)
CHECK_FUNCTION_EXISTS(gettimeofday      HAVE_GETTIMEOFDAY)
CHECK_FUNCTION_EXISTS(longjmp           HAVE_LONGJMP)
CHECK_FUNCTION_EXISTS(fork              HAVE_FORK)
CHECK_FUNCTION_EXISTS(difftime          HAVE_DIFFTIME)
CHECK_FUNCTION_EXISTS(gethostname       HAVE_GETHOSTNAME)
CHECK_FUNCTION_EXISTS(sigaction         HAVE_SIGACTION)

CHECK_SYMBOL_EXISTS(TIOCGWINSZ "sys/ioctl.h" HAVE_TIOCGWINSZ)
CHECK_SYMBOL_EXISTS(TIOCGETD   "sys/ioctl.h" HAVE_TIOCGETD)

# For other other specific tests, use this macro.
MACRO(OTHER_INTERNAL_TEST OTHER_TEST)
  IF("${OTHER_TEST}" MATCHES "^${OTHER_TEST}$")
    SET(MACRO_CHECK_FUNCTION_DEFINITIONS 
      "-D${OTHER_TEST} ${CMAKE_REQUIRED_FLAGS}")
    SET(OTHER_TEST_ADD_LIBRARIES)
    IF(CMAKE_REQUIRED_LIBRARIES)
      SET(OTHER_TEST_ADD_LIBRARIES
        "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
    ENDIF(CMAKE_REQUIRED_LIBRARIES)
    IF(HAVE_SYS_TIME_H)
      SET(MACRO_CHECK_FUNCTION_DEFINITIONS 
        "${MACRO_CHECK_FUNCTION_DEFINITIONS} -DHAVE_SYS_TIME_H")
    ENDIF(HAVE_SYS_TIME_H)

    MESSAGE(STATUS "Performing Other Test ${OTHER_TEST}")
    TRY_COMPILE(${OTHER_TEST}
      ${CMAKE_BINARY_DIR}
      ${VTKHDF5_SOURCE_DIR}/CMake/HDF5Tests.c
      CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
      "${OTHER_TEST_ADD_LIBRARIES}"
      OUTPUT_VARIABLE OUTPUT)
    IF(${OTHER_TEST})
      SET(${OTHER_TEST} 1 CACHE INTERNAL "Other test ${FUNCTION}")
      MESSAGE(STATUS "Performing Other Test ${OTHER_TEST} - Success")
    ELSE(${OTHER_TEST})
      MESSAGE(STATUS "Performing Other Test ${OTHER_TEST} - Failed")
      SET(${OTHER_TEST} "" CACHE INTERNAL "Other test ${FUNCTION}")
      WRITE_FILE(${CMAKE_BINARY_DIR}/CMakeError.log 
        "Performing Other Test ${OTHER_TEST} failed with the following output:\n"
        "${OUTPUT}\n" APPEND)
    ENDIF(${OTHER_TEST})
  ENDIF("${OTHER_TEST}" MATCHES "^${OTHER_TEST}$")
ENDMACRO(OTHER_INTERNAL_TEST) 

# Do curl specific tests
FOREACH(CURL_TEST 
    TIME_WITH_SYS_TIME
    STDC_HEADERS
    HAVE_TM_ZONE
    HAVE_ATTRIBUTE
    HAVE_FUNCTION
    HAVE_TM_GMTOFF
    HAVE_TIMEZONE
    HAVE_STRUCT_TIMEZONE
    HAVE_STAT_ST_BLOCKS
    HAVE_ATTRIBUTE
    HAVE_FUNCTION
    )
  OTHER_INTERNAL_TEST(${CURL_TEST})
ENDFOREACH(CURL_TEST)



MESSAGE(STATUS "Performing Other Test ${OTHER_TEST}")
IF(PRINTF_LL_WIDTH MATCHES "^PRINTF_LL_WIDTH$")
  SET(PRINT_LL_FOUND 0)
  MESSAGE(STATUS "Checking for apropriate format for 64 bit long:")
  FOREACH(HDF5_PRINTF_LL l64 l L q ll)
    SET(CURRENT_TEST_DEFINITIONS "-DPRINTF_LL_WIDTH=${HDF5_PRINTF_LL}")
    IF(SIZEOF_LONG_LONG)
      SET(CURRENT_TEST_DEFINITIONS "${CURRENT_TEST_DEFINITIONS} -DHAVE_LONG_LONG")
    ENDIF(SIZEOF_LONG_LONG)
    TRY_RUN(HDF5_PRINTF_LL_TEST_RUN HDF5_PRINTF_LL_TEST_COMPILE
      ${VTKHDF5_BINARY_DIR}/CMake
      ${VTKHDF5_SOURCE_DIR}/CMake/HDF5Tests.c
      CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CURRENT_TEST_DEFINITIONS}
      OUTPUT_VARIABLE OUTPUT)
    IF(HDF5_PRINTF_LL_TEST_COMPILE)
      IF(HDF5_PRINTF_LL_TEST_RUN MATCHES 0)
        SET(PRINTF_LL_WIDTH "\"${HDF5_PRINTF_LL}\"" CACHE INTERNAL
          "Width for printf for type `long long' or `__int64', us. `ll")
        SET(PRINT_LL_FOUND 1)
      ELSE(HDF5_PRINTF_LL_TEST_RUN MATCHES 0)
        #MESSAGE("Width with ${HDF5_PRINTF_LL} failed with result: ${HDF5_PRINTF_LL_TEST_RUN}")
      ENDIF(HDF5_PRINTF_LL_TEST_RUN MATCHES 0)
    ELSE(HDF5_PRINTF_LL_TEST_COMPILE)
      WRITE_FILE(${CMAKE_BINARY_DIR}/CMakeError.log
        "Test PRINTF_LL_WIDTH for ${HDF5_PRINTF_LL} failed with the following output:\n"
        "${OUTPUT}\n" APPEND)
    ENDIF(HDF5_PRINTF_LL_TEST_COMPILE)
  ENDFOREACH(HDF5_PRINTF_LL)
  IF(PRINT_LL_FOUND)
    MESSAGE(STATUS "Checking for apropriate format for 64 bit long: found ${PRINTF_LL_WIDTH}")
  ELSE(PRINT_LL_FOUND)
    MESSAGE(STATUS "Checking for apropriate format for 64 bit long: not found")
    SET(PRINTF_LL_WIDTH "\"unknown\"" CACHE INTERNAL
      "Width for printf for type `long long' or `__int64', us. `ll")
  ENDIF(PRINT_LL_FOUND)
ENDIF(PRINTF_LL_WIDTH MATCHES "^PRINTF_LL_WIDTH$")


SET(common_SRCS
  H5.c          H5FDmulti.c   H5HG.c       H5Oname.c     H5T.c
  H5A.c         H5FDsec2.c    H5HL.c       H5Onull.c     H5TB.c
  H5AC.c        H5FDsrb.c     H5I.c        H5Osdspace.c  H5TS.c
  H5B.c         H5FDstdio.c   H5MF.c       H5Oshared.c   H5Tbit.c
  H5D.c         H5FDstream.c  H5MM.c       H5Ostab.c     H5Tconv.c
  H5E.c         H5FL.c        H5O.c        H5P.c         H5Tvlen.c
  H5F.c         H5Farray.c    H5Oattr.c    H5R.c         H5V.c
  H5FD.c        H5Fcontig.c   H5Ocomp.c    H5S.c         H5Z.c
  H5FDcore.c    H5Fistore.c   H5Ocont.c    H5Sall.c      H5Zdeflate.c
  H5FDdpss.c    H5Fseq.c      H5Odtype.c   H5Shyper.c    
  H5FDfamily.c  H5G.c         H5Oefl.c     H5Smpio.c
  H5FDgass.c    H5Gent.c      H5Ofill.c    H5Snone.c
  H5FDlog.c     H5Gnode.c     H5Olayout.c  H5Spoint.c
  H5FDmpio.c    H5Gstab.c     H5Omtime.c   H5Sselect.c
  H5Vprivate.c
  )

INCLUDE_DIRECTORIES(${VTKHDF5_SOURCE_DIR}
  ${VTKHDF5_BINARY_DIR})

SET(H5_const    ${const})
SET(H5_HAVE_TM_ZONE     ${HAVE_TM_ZONE})
SET(H5_HAVE_TZNAME      ${HAVE_TZNAME})
SET(H5_inline   ${inline})
SET(H5_off_t    ${off_t})
SET(H5_size_t   ${size_t})
SET(H5_STDC_HEADERS     ${STDC_HEADERS})
SET(H5_TIME_WITH_SYS_TIME       ${TIME_WITH_SYS_TIME})
SET(H5_TM_IN_SYS_TIME   ${TM_IN_SYS_TIME})
SET(H5_WORDS_BIGENDIAN  ${WORDS_BIGENDIAN})
SET(H5_HAVE_ATTRIBUTE   ${HAVE_ATTRIBUTE})
SET(H5_HAVE_FUNCTION    ${HAVE_FUNCTION})
SET(H5_HAVE_PARALLEL    ${HAVE_PARALLEL})
SET(H5_HAVE_THREADSAFE  ${HAVE_THREADSAFE})
SET(H5_HAVE_LARGE_HSIZET        ${HAVE_LARGE_HSIZET})
SET(H5_WANT_H5_V1_2_COMPAT      ${WANT_H5_V1_2_COMPAT})
SET(H5_PRINTF_LL_WIDTH  ${PRINTF_LL_WIDTH})
SET(H5_HAVE_TM_GMTOFF   ${HAVE_TM_GMTOFF})
SET(H5_HAVE___TM_GMTOFF         ${HAVE___TM_GMTOFF})
SET(H5_HAVE_TIMEZONE    ${HAVE_TIMEZONE})
SET(H5_HAVE_STRUCT_TIMEZONE     ${HAVE_STRUCT_TIMEZONE})
SET(H5_HAVE_STAT_ST_BLOCKS      ${HAVE_STAT_ST_BLOCKS})
SET(H5_HAVE_STRUCT_TEXT_INFO    ${HAVE_STRUCT_TEXT_INFO})
SET(H5_HAVE_STRUCT_VIDEOCONFIG  ${HAVE_STRUCT_VIDEOCONFIG})
SET(H5_HAVE_TIOCGETD    ${HAVE_TIOCGETD})
SET(H5_HAVE_TIOCGWINSZ  ${HAVE_TIOCGWINSZ})
SET(H5_HAVE_GASS        ${HAVE_GASS})
SET(H5_HAVE_SRB         ${HAVE_SRB})
SET(H5_HAVE_GRIDSTORAGE         ${HAVE_GRIDSTORAGE})
SET(H5_HAVE_STREAM      ${HAVE_STREAM})
SET(H5_HAVE_SOCKLEN_T   ${HAVE_SOCKLEN_T})
SET(H5_SIZEOF___INT64   ${SIZEOF___INT64})
SET(H5_SIZEOF_CHAR      ${SIZEOF_CHAR})
SET(H5_SIZEOF_DOUBLE    ${SIZEOF_DOUBLE})
SET(H5_SIZEOF_FLOAT     ${SIZEOF_FLOAT})
SET(H5_SIZEOF_INT       ${SIZEOF_INT})
SET(H5_SIZEOF_INT16_T   ${SIZEOF_INT16_T})
SET(H5_SIZEOF_INT32_T   ${SIZEOF_INT32_T})
SET(H5_SIZEOF_INT64_T   ${SIZEOF_INT64_T})
SET(H5_SIZEOF_INT8_T    ${SIZEOF_INT8_T})
SET(H5_SIZEOF_INT_FAST16_T      ${SIZEOF_INT_FAST16_T})
SET(H5_SIZEOF_INT_FAST32_T      ${SIZEOF_INT_FAST32_T})
SET(H5_SIZEOF_INT_FAST64_T      ${SIZEOF_INT_FAST64_T})
SET(H5_SIZEOF_INT_FAST8_T       ${SIZEOF_INT_FAST8_T})
SET(H5_SIZEOF_INT_LEAST16_T     ${SIZEOF_INT_LEAST16_T})
SET(H5_SIZEOF_INT_LEAST32_T     ${SIZEOF_INT_LEAST32_T})
SET(H5_SIZEOF_INT_LEAST64_T     ${SIZEOF_INT_LEAST64_T})
SET(H5_SIZEOF_INT_LEAST8_T      ${SIZEOF_INT_LEAST8_T})
SET(H5_SIZEOF_LONG      ${SIZEOF_LONG})
SET(H5_SIZEOF_LONG_DOUBLE       ${SIZEOF_LONG_DOUBLE})
SET(H5_SIZEOF_LONG_LONG         ${SIZEOF_LONG_LONG})
SET(H5_SIZEOF_OFF_T     ${SIZEOF_OFF_T})
SET(H5_SIZEOF_SHORT     ${SIZEOF_SHORT})
SET(H5_SIZEOF_SIZE_T    ${SIZEOF_SIZE_T})
SET(H5_SIZEOF_SSIZE_T   ${SIZEOF_SSIZE_T})
SET(H5_SIZEOF_UINT16_T  ${SIZEOF_UINT16_T})
SET(H5_SIZEOF_UINT32_T  ${SIZEOF_UINT32_T})
SET(H5_SIZEOF_UINT64_T  ${SIZEOF_UINT64_T})
SET(H5_SIZEOF_UINT8_T   ${SIZEOF_UINT8_T})
SET(H5_SIZEOF_UINT_FAST16_T     ${SIZEOF_UINT_FAST16_T})
SET(H5_SIZEOF_UINT_FAST32_T     ${SIZEOF_UINT_FAST32_T})
SET(H5_SIZEOF_UINT_FAST64_T     ${SIZEOF_UINT_FAST64_T})
SET(H5_SIZEOF_UINT_FAST8_T      ${SIZEOF_UINT_FAST8_T})
SET(H5_SIZEOF_UINT_LEAST16_T    ${SIZEOF_UINT_LEAST16_T})
SET(H5_SIZEOF_UINT_LEAST32_T    ${SIZEOF_UINT_LEAST32_T})
SET(H5_SIZEOF_UINT_LEAST64_T    ${SIZEOF_UINT_LEAST64_T})
SET(H5_SIZEOF_UINT_LEAST8_T     ${SIZEOF_UINT_LEAST8_T})
SET(H5_HAVE_BSDGETTIMEOFDAY     ${HAVE_BSDGETTIMEOFDAY})
SET(H5_HAVE_GETCONSOLESCREENBUFFERINFO  ${HAVE_GETCONSOLESCREENBUFFERINFO})
SET(H5_HAVE__GETVIDEOCONFIG     ${HAVE__GETVIDEOCONFIG})
SET(H5_HAVE__SCRSIZE    ${HAVE__SCRSIZE})
SET(H5_HAVE_COMPRESS2   ${HAVE_COMPRESS2})
SET(H5_HAVE_DIFFTIME    ${HAVE_DIFFTIME})
SET(H5_HAVE_FORK        ${HAVE_FORK})
SET(H5_HAVE_FSEEK64     ${HAVE_FSEEK64})
SET(H5_HAVE_GETDENTS64  ${HAVE_GETDENTS64})
SET(H5_HAVE_GETHOSTNAME         ${HAVE_GETHOSTNAME})
SET(H5_HAVE_GETPWUID    ${HAVE_GETPWUID})
SET(H5_HAVE_GETRUSAGE   ${HAVE_GETRUSAGE})
SET(H5_HAVE_GETTEXTINFO         ${HAVE_GETTEXTINFO})
SET(H5_HAVE_GETTIMEOFDAY        ${HAVE_GETTIMEOFDAY})
SET(H5_HAVE_IOCTL       ${HAVE_IOCTL})
SET(H5_HAVE_LONGJMP     ${HAVE_LONGJMP})
SET(H5_HAVE_LSEEK64     ${HAVE_LSEEK64})
SET(H5_HAVE_SETSYSINFO  ${HAVE_SETSYSINFO})
SET(H5_HAVE_SIGACTION   ${HAVE_SIGACTION})
SET(H5_HAVE_SIGNAL      ${HAVE_SIGNAL})
SET(H5_HAVE_SNPRINTF    ${HAVE_SNPRINTF})
SET(H5_HAVE_STRDUP      ${HAVE_STRDUP})
SET(H5_HAVE_SYSTEM      ${HAVE_SYSTEM})
SET(H5_HAVE_VSNPRINTF   ${HAVE_VSNPRINTF})
SET(H5_HAVE_WAITPID     ${HAVE_WAITPID})
SET(H5_HAVE_GLOBUS_COMMON_H     ${HAVE_GLOBUS_COMMON_H})
SET(H5_HAVE_GRID_STORAGE_FILE_H         ${HAVE_GRID_STORAGE_FILE_H})
SET(H5_HAVE_IO_H        ${HAVE_IO_H})
SET(H5_HAVE_MFHDF_H     ${HAVE_MFHDF_H})
SET(H5_HAVE_NETINET_TCP_H       ${HAVE_NETINET_TCP_H})
SET(H5_HAVE_PDB_H       ${HAVE_PDB_H})
SET(H5_HAVE_PTHREAD_H   ${HAVE_PTHREAD_H})
SET(H5_HAVE_SETJMP_H    ${HAVE_SETJMP_H})
SET(H5_HAVE_SRBCLIENT_H         ${HAVE_SRBCLIENT_H})
SET(H5_HAVE_STDDEF_H    ${HAVE_STDDEF_H})
SET(H5_HAVE_STDINT_H    ${HAVE_STDINT_H})
SET(H5_HAVE_SYS_FILIO_H         ${HAVE_SYS_FILIO_H})
SET(H5_HAVE_SYS_IOCTL_H         ${HAVE_SYS_IOCTL_H})
SET(H5_HAVE_SYS_PROC_H  ${HAVE_SYS_PROC_H})
SET(H5_HAVE_SYS_RESOURCE_H      ${HAVE_SYS_RESOURCE_H})
SET(H5_HAVE_SYS_SOCKET_H        ${HAVE_SYS_SOCKET_H})
SET(H5_HAVE_SYS_STAT_H  ${HAVE_SYS_STAT_H})
SET(H5_HAVE_SYS_SYSINFO_H       ${HAVE_SYS_SYSINFO_H})
SET(H5_HAVE_SYS_TIME_H  ${HAVE_SYS_TIME_H})
SET(H5_HAVE_SYS_TIMEB_H         ${HAVE_SYS_TIMEB_H})
SET(H5_HAVE_SYS_TYPES_H         ${HAVE_SYS_TYPES_H})
SET(H5_HAVE_UNISTD_H    ${HAVE_UNISTD_H})
SET(H5_HAVE_WINSOCK_H   ${HAVE_WINSOCK_H})
SET(H5_HAVE_ZLIB_H      ${HAVE_ZLIB_H})
SET(H5_HAVE_LIBSRBCLIENT        ${HAVE_LIBSRBCLIENT})
SET(H5_HAVE_LIBCRYPTO   ${HAVE_LIBCRYPTO})
SET(H5_HAVE_LIBDF       ${HAVE_LIBDF})
SET(H5_HAVE_LIBELF      ${HAVE_LIBELF})
SET(H5_HAVE_LIBGLOBUS_COMMON    ${HAVE_LIBGLOBUS_COMMON})
SET(H5_HAVE_LIBGLOBUS_GAA       ${HAVE_LIBGLOBUS_GAA})
SET(H5_HAVE_LIBGLOBUS_GASS_CACHE        ${HAVE_LIBGLOBUS_GASS_CACHE})
SET(H5_HAVE_LIBGLOBUS_GASS_FILE         ${HAVE_LIBGLOBUS_GASS_FILE})
SET(H5_HAVE_LIBGLOBUS_GASS_TRANSFER     ${HAVE_LIBGLOBUS_GASS_TRANSFER})
SET(H5_HAVE_LIBGLOBUS_GASS_TRANSFER_ASSIST      ${HAVE_LIBGLOBUS_GASS_TRANSFER_ASSIST})
SET(H5_HAVE_LIBGLOBUS_GSS       ${HAVE_LIBGLOBUS_GSS})
SET(H5_HAVE_LIBGLOBUS_GSS_ASSIST        ${HAVE_LIBGLOBUS_GSS_ASSIST})
SET(H5_HAVE_LIBGLOBUS_IO        ${HAVE_LIBGLOBUS_IO})
SET(H5_HAVE_LIBGRID_STORAGE_CLIENT      ${HAVE_LIBGRID_STORAGE_CLIENT})
SET(H5_HAVE_LIBGRID_STORAGE_FILE        ${HAVE_LIBGRID_STORAGE_FILE})
SET(H5_HAVE_LIBJPEG     ${HAVE_LIBJPEG})
SET(H5_HAVE_LIBM        ${HAVE_LIBM})
SET(H5_HAVE_LIBMFHDF    ${HAVE_LIBMFHDF})
SET(H5_HAVE_LIBMPI      ${HAVE_LIBMPI})
SET(H5_HAVE_LIBMPICH    ${HAVE_LIBMPICH})
SET(H5_HAVE_LIBMPIO     ${HAVE_LIBMPIO})
SET(H5_HAVE_LIBNSL      ${HAVE_LIBNSL})
SET(H5_HAVE_LIBPDB      ${HAVE_LIBPDB})
SET(H5_HAVE_LIBPTHREAD  ${HAVE_LIBPTHREAD})
SET(H5_HAVE_LIBSILO     ${HAVE_LIBSILO})
SET(H5_HAVE_LIBSOCKET   ${HAVE_LIBSOCKET})
SET(H5_HAVE_LIBSSL      ${HAVE_LIBSSL})
SET(H5_HAVE_LIBZ        ${HAVE_LIBZ})
SET(H5_HAVE_FUNCTION    ${HAVE_FUNCTION})
SET(H5_HAVE_ATTRIBUTE   ${HAVE_ATTRIBUTE})

# This variable is used in H5pubconf to detect shared libraries.
IF(BUILD_SHARED_LIBS)
  SET(VTKHDF5_BUILD_SHARED_LIBS 1)
ELSE(BUILD_SHARED_LIBS)
  SET(VTKHDF5_BUILD_SHARED_LIBS 0)
ENDIF(BUILD_SHARED_LIBS)

IF(WIN32)
  #SET(CONFIG_FILE_EXT h.cmake)
  SET(CONFIG_FILE_EXT WIN32.h)
ELSE(WIN32)
  SET(CONFIG_FILE_EXT h.cmake)
ENDIF(WIN32)
CONFIGURE_FILE(${VTKHDF5_SOURCE_DIR}/H5config.${CONFIG_FILE_EXT}.in
  ${VTKHDF5_BINARY_DIR}/H5config.h)

CONFIGURE_FILE(${VTKHDF5_SOURCE_DIR}/H5pubconf.${CONFIG_FILE_EXT}.in
  ${VTKHDF5_BINARY_DIR}/H5pubconf.h)

SET(common_SRCS ${common_SRCS} ${VTKHDF5_BINARY_DIR}/H5Tinit.c)
SET_SOURCE_FILES_PROPERTIES (${VTKHDF5_BINARY_DIR}/H5Tinit.c GENERATED)

IF(XDMF_ZLIB_INCLUDE_DIRS)
  INCLUDE_DIRECTORIES(${XDMF_ZLIB_INCLUDE_DIRS})
ENDIF(XDMF_ZLIB_INCLUDE_DIRS)

ADD_LIBRARY(vtkhdf5 ${common_SRCS})
TARGET_LINK_LIBRARIES(vtkhdf5 ${LINK_LIBS} ${XDMF_ZLIB_LIBRARIES})

SET(EXE_EXT "")
IF(WIN32)
  SET(EXE_EXT ".exe")
ENDIF(WIN32)

SET(MAKE_SYSTEM)
IF(CMAKE_BUILD_TOOL MATCHES "make")
  SET(MAKE_SYSTEM 1)
ENDIF(CMAKE_BUILD_TOOL MATCHES "make")

SET(CFG_INIT "/${CMAKE_CFG_INTDIR}")
IF(MAKE_SYSTEM OR UNIX)
  SET(CFG_INIT "")
ENDIF(MAKE_SYSTEM OR UNIX)
SET(CMD ${EXECUTABLE_OUTPUT_PATH}${CFG_INIT}/H5detect${EXE_EXT})

ADD_EXECUTABLE(H5detect H5detect.c)
TARGET_LINK_LIBRARIES(H5detect ${LINK_LIBS})
ADD_CUSTOM_COMMAND(
  SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/H5detect.c
  COMMAND ${CMD}
  ARGS > ${VTKHDF5_BINARY_DIR}/H5Tinit.c
  TARGET vtkhdf5
  DEPENDS ${CMD}
  OUTPUTS ${VTKHDF5_BINARY_DIR}/H5Tinit.c)

ADD_DEPENDENCIES(vtkhdf5 H5detect)
