ThirdPartyPETSc.cmake 5.09 KB
Newer Older
Dave Moxey's avatar
Dave Moxey committed
1 2 3 4 5 6 7 8
########################################################################
#
# ThirdParty configuration for Nektar++
#
# PETSc
#
########################################################################

Dave Moxey's avatar
Dave Moxey committed
9 10 11
OPTION(NEKTAR_USE_PETSC
    "Enable PETSc parallel matrix solver support." OFF)

12
IF (NEKTAR_USE_PETSC)
Dave Moxey's avatar
Dave Moxey committed
13 14 15 16 17 18 19 20 21 22 23 24
    SET(PETSC_FIND_QUIETLY ON)
    INCLUDE(FindPETSc)

    IF (PETSC_FOUND)
        SET(BUILD_PETSC OFF)
    ELSE()
        SET(BUILD_PETSC ON)
    ENDIF()

    CMAKE_DEPENDENT_OPTION(THIRDPARTY_BUILD_PETSC
        "Build PETSc if needed" ${BUILD_PETSC}
        "NEKTAR_USE_PETSC" OFF)
25 26 27 28

    IF (THIRDPARTY_BUILD_PETSC)
        INCLUDE(ExternalProject)

Kilian Lackhove's avatar
Kilian Lackhove committed
29
        FIND_PACKAGE(PythonInterp 2 REQUIRED)
30

Dave Moxey's avatar
Dave Moxey committed
31
        SET(PETSC_C_COMPILER   "${CMAKE_C_COMPILER}")
32
        SET(PETSC_CXX_COMPILER "${CMAKE_CXX_COMPILER}")
Kilian Lackhove's avatar
Kilian Lackhove committed
33
        SET(PETSC_Fortran_COMPILER "${CMAKE_Fortran_COMPILER}")
34 35 36

        IF (NEKTAR_USE_MPI)
            IF (NOT MPI_BUILTIN)
Dave Moxey's avatar
Dave Moxey committed
37
                SET(PETSC_C_COMPILER   "${MPI_C_COMPILER}")
38
                SET(PETSC_CXX_COMPILER "${MPI_CXX_COMPILER}")
Kilian Lackhove's avatar
Kilian Lackhove committed
39
                SET(PETSC_Fortran_COMPILER "${MPI_Fortran_COMPILER}")
40 41 42 43 44
            ENDIF (NOT MPI_BUILTIN)
        ELSE (NEKTAR_USE_MPI)
            SET(PETSC_NO_MPI "--with-mpi=0")
        ENDIF (NEKTAR_USE_MPI)

45 46 47 48
        IF(CMAKE_Fortran_COMPILER)
            IF(NEKTAR_USE_MPI AND NOT MPI_Fortran_COMPILER)
                MESSAGE(ERROR "MPI_Fortran_COMPILER not set")
            ENDIF()
Kilian Lackhove's avatar
Kilian Lackhove committed
49 50
            # we use a MUMPS build in ordering here, in the future it might make
            # sense to hook it up with metis/scotch since this MIGHT be faster
51
            SET(PETSC_MUMPS --download-scalapack --download-mumps)
52
            SET(PETSC_DEPS "")
Kilian Lackhove's avatar
Kilian Lackhove committed
53 54 55 56 57 58 59

            IF( NEKTAR_USE_BLAS_LAPACK )
                IF( NEKTAR_USE_MKL AND MKL_FOUND )
                    SET(PETSC_MUMPS ${PETSC_MUMPS} --with-blas-lapack-dir=${MKL_LIB_DIR})
                ELSEIF( NEKTAR_USE_WIN32_LAPACK )
                    SET(PETSC_MUMPS ${PETSC_MUMPS} --with-blas-lapack-dir=${LAPACK_DIR})
                ELSEIF( NEKTAR_USE_SYSTEM_BLAS_LAPACK )
60 61 62 63
                    SET(PETSC_MUMPS ${PETSC_MUMPS} --with-blas-lapack-dir=${NATIVE_LAPACK_LIB_DIR})
                    IF(THIRDPARTY_BUILD_BLAS_LAPACK)
                        SET(PETSC_DEPS ${PETSC_DEPS} lapack-3.7.0)
                    ENDIF()
Kilian Lackhove's avatar
Kilian Lackhove committed
64 65 66 67 68 69 70 71 72
                ELSE()
                    MESSAGE(STATUS "No suitable blas/lapack found, downloading")
                    SET(PETSC_MUMPS ${PETSC_MUMPS} --download-fblaslapack)
                ENDIF()
            ELSE()
                MESSAGE(STATUS "No suitable blas/lapack found, downloading")
                SET(PETSC_MUMPS ${PETSC_MUMPS} --download-fblaslapack)
            ENDIF()

73 74 75 76 77
        ELSE()
            MESSAGE(WARNING "No Fortran support. Building PETSc without MUMPS support")
            SET(PETSC_Fortran_COMPILER "0")
        ENDIF()

78
        EXTERNALPROJECT_ADD(
79
            petsc-3.7.2
80
            DEPENDS ${PETSC_DEPS}
81
            PREFIX ${TPSRC}
82
            STAMP_DIR ${TPBUILD}/stamp
83
            DOWNLOAD_DIR ${TPSRC}
84 85
            SOURCE_DIR ${TPBUILD}/petsc-3.7.2
            TMP_DIR ${TPBUILD}/petsc-3.7.2-tmp
86
            INSTALL_DIR ${TPDIST}
87
            BINARY_DIR ${TPBUILD}/petsc-3.7.2
88
            URL http://www.nektar.info/thirdparty/petsc-lite-3.7.2.tar.gz
89
            URL_MD5 "26c2ff8eaaa9e49aea063f839f5daa7e"
90
            CONFIGURE_COMMAND
Kilian Lackhove's avatar
Kilian Lackhove committed
91
                OMPI_FC=${CMAKE_Fortran_COMPILER}
92 93
                OMPI_CC=${CMAKE_C_COMPILER}
                OMPI_CXX=${CMAKE_CXX_COMPILER}
94
                ${PYTHON_EXECUTABLE} ./configure
Kilian Lackhove's avatar
Kilian Lackhove committed
95
                ./configure
Kilian Lackhove's avatar
Kilian Lackhove committed
96
                --with-fc=${PETSC_Fortran_COMPILER}
97 98
                --with-cc=${PETSC_C_COMPILER}
                --with-cxx=${PETSC_CXX_COMPILER}
99
                --with-shared-libraries=1
100
                --with-pic=1
101
                --with-x=0
102
                --with-ssl=0
103
                --prefix=${TPDIST}
104
                --with-petsc-arch=c-opt
105
                ${PETSC_MUMPS}
106
                ${PETSC_NO_MPI}
Dave Moxey's avatar
Dave Moxey committed
107
            BUILD_COMMAND MAKEFLAGS= make)
108

109
        SET(PETSC_LIBRARIES petsc CACHE FILEPATH
Dave Moxey's avatar
Dave Moxey committed
110 111 112 113 114
            "PETSc library" FORCE)
        SET(PETSC_INCLUDES ${TPDIST}/include CACHE FILEPATH
            "PETSc includes" FORCE)

        LINK_DIRECTORIES(${TPDIST}/lib)
115
        MESSAGE(STATUS "Build PETSc: ${TPDIST}/${LIB_DIR}/lib${PETSC_LIBRARIES}.so")
Dave Moxey's avatar
Dave Moxey committed
116
        SET(PETSC_CONFIG_INCLUDE_DIR ${TPINC})
117 118 119 120 121 122 123
    ELSE (THIRDPARTY_BUILD_PETSC)
        INCLUDE(FindPETSc)
        IF (NOT PETSC_FOUND)
            MESSAGE(FATAL_ERROR "Could not find PETSc")
        ELSE (NOT PETSC_FOUND)
            MESSAGE(STATUS "Found PETSc: ${PETSC_LIBRARIES}")
        ENDIF (NOT PETSC_FOUND)
Dave Moxey's avatar
Dave Moxey committed
124
        SET(PETSC_CONFIG_INCLUDE_DIR ${PETSC_INCLUDES})
125
        INCLUDE_DIRECTORIES(${PETSC_INCLUDES})
126
        ADD_CUSTOM_TARGET(petsc-3.7.2 ALL)
127
    ENDIF (THIRDPARTY_BUILD_PETSC)
Dave Moxey's avatar
Dave Moxey committed
128

Dave Moxey's avatar
Dave Moxey committed
129 130
    ADD_DEFINITIONS(-DNEKTAR_USING_PETSC)
    INCLUDE_DIRECTORIES(SYSTEM ${PETSC_INCLUDES})
Douglas Serson's avatar
Douglas Serson committed
131
    IF (NOT NEKTAR_USE_MPI)
132
        INCLUDE_DIRECTORIES(SYSTEM ${PETSC_INCLUDES}/petsc/mpiuni)
Douglas Serson's avatar
Douglas Serson committed
133
    ENDIF (NOT NEKTAR_USE_MPI)
Chris Cantwell's avatar
Chris Cantwell committed
134 135

    MARK_AS_ADVANCED(PETSC_CURRENT PETSC_DIR PETSC_LIBRARIES PETSC_INCLUDES)
Dave Moxey's avatar
Dave Moxey committed
136
ENDIF( NEKTAR_USE_PETSC )