ThirdPartyHDF5.cmake 2.65 KB
Newer Older
Rupert Nash's avatar
Rupert Nash committed
1 2 3 4 5 6 7 8 9 10 11 12
########################################################################
#
# ThirdParty configuration for Nektar++
#
# HDF5
#
########################################################################

OPTION(NEKTAR_USE_HDF5
    "Enable HDF5 I/O support." OFF)

IF (NEKTAR_USE_HDF5)
13
    IF (NOT NEKTAR_USE_MPI)
14 15
        MESSAGE(FATAL_ERROR "HDF5 requires Nektar++ to be configured with "
                "NEKTAR_USE_MPI for MPI support.")
16 17
    ENDIF()

18
    # Try to find parallel system HDF5 first.
19 20 21
    SET(HDF5_PREFER_PARALLEL ON)
    FIND_PACKAGE(HDF5 QUIET)

22 23 24 25 26
    IF (HDF5_FOUND AND NOT HDF5_IS_PARALLEL)
        MESSAGE(STATUS "Non-parallel system HDF5 detected: will build instead.")
        SET(BUILD_HDF5 ON)
    ELSEIF(HDF5_FOUND)
        SET(BUILD_HDF5 OFF)
27
    ELSE()
28 29 30 31 32 33 34 35
        SET(BUILD_HDF5 ON)
    ENDIF()

    CMAKE_DEPENDENT_OPTION(THIRDPARTY_BUILD_HDF5
        "Build HDF5 from ThirdParty" ${BUILD_HDF5}
        "NEKTAR_USE_HDF5" OFF)

    IF(THIRDPARTY_BUILD_HDF5)
36
        IF (CMAKE_VERSION VERSION_LESS 3.1.0)
37 38 39 40 41 42 43
            MESSAGE(FATAL_ERROR "HDF5 compilation requires CMake 3.1.0 or later.")
        ENDIF()

        INCLUDE(ExternalProject)
        EXTERNALPROJECT_ADD(
            hdf5-1.8.16
            PREFIX ${TPSRC}
Dave Moxey's avatar
Dave Moxey committed
44
            URL ${TPURL}/hdf5-1.8.16.tar.bz2
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
            URL_MD5 79c1593573ebddf734eee8d43ecfe483
            STAMP_DIR ${TPBUILD}/stamp
            DOWNLOAD_DIR ${TPSRC}
            SOURCE_DIR ${TPSRC}/hdf5-1.8.16
            BINARY_DIR ${TPBUILD}/hdf5-1.8.16
            TMP_DIR ${TPBUILD}/hdf5-1.8.16-tmp
            INSTALL_DIR ${TPDIST}
            CONFIGURE_COMMAND ${CMAKE_COMMAND}
                -G ${CMAKE_GENERATOR}
                -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
                -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
                -DCMAKE_INSTALL_PREFIX:PATH=${TPDIST}
                -DHDF5_ENABLE_PARALLEL=ON
                -DHDF5_BUILD_CPP_LIB=OFF
                -DBUILD_TESTING=OFF
                -DHDF5_BUILD_TOOLS=OFF
                ${TPSRC}/hdf5-1.8.16
            )

        SET(HDF5_LIBRARIES hdf5-shared CACHE FILEPATH
            "HDF5 libraries" FORCE)
66
        SET(HDF5_INCLUDE_DIRS ${TPDIST}/include CACHE FILEPATH
67 68 69 70 71 72 73
            "HDF5 include directory" FORCE)

        LINK_DIRECTORIES(${TPDIST}/lib)

        MESSAGE(STATUS "Build HDF5: ${HDF5_LIBRARIES}")

        SET(HDF5_CONFIG_INCLUDE_DIR ${TPINC})
74
    ELSE()
75
        MESSAGE(STATUS "Found HDF5: ${HDF5_LIBRARIES}")
76 77
        SET(HDF5_CONFIG_INCLUDE_DIR ${HDF5_INCLUDE_DIRS})
        ADD_CUSTOM_TARGET(hdf5-1.8.16 ALL)
78
    ENDIF()
79 80 81

    MARK_AS_ADVANCED(HDF5_LIBRARIES)
    MARK_AS_ADVANCED(HDF5_INCLUDE_DIRS)
82
    INCLUDE_DIRECTORIES(${HDF5_INCLUDE_DIRS})
Dave Moxey's avatar
Dave Moxey committed
83
ENDIF()