ThirdPartyHDF5.cmake 2.63 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)
Dave Moxey's avatar
Dave Moxey committed
14
        MESSAGE(FATAL_ERROR "HDF5 requires Nektar++ to be configured with NEKTAR_USE_MPI for MPI support.")
15
16
    ENDIF()

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

21
22
23
24
25
    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)
26
    ELSE()
27
28
29
30
31
32
33
34
        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)
35
        IF (NOT CMAKE_VERSION VERSION_GREATER 3.1.0 AND NOT CMAKE_VERSION VERSION_EQUAL 3.1.0)
36
37
38
39
40
41
42
            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
43
            URL ${TPURL}/hdf5-1.8.16.tar.bz2
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
            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)
65
        SET(HDF5_INCLUDE_DIRS ${TPDIST}/include CACHE FILEPATH
66
67
68
69
70
71
72
            "HDF5 include directory" FORCE)

        LINK_DIRECTORIES(${TPDIST}/lib)

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

        SET(HDF5_CONFIG_INCLUDE_DIR ${TPINC})
73
74
75
    ELSE()
        SET(HDF5_CONFIG_INCLUDE_DIR ${HDF5_INCLUDE_DIRS})
        ADD_CUSTOM_TARGET(hdf5-1.8.16 ALL)
76
    ENDIF()
77
78
79
80

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