ThirdPartyPETSc.cmake 4.03 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}")
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}")
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 53 54 55 56
        ELSE()
            MESSAGE(WARNING "No Fortran support. Building PETSc without MUMPS support")
            SET(PETSC_Fortran_COMPILER "0")
        ENDIF()

57
        EXTERNALPROJECT_ADD(
58
            petsc-3.7.2
59
            PREFIX ${TPSRC}
60
            STAMP_DIR ${TPBUILD}/stamp
61
            DOWNLOAD_DIR ${TPSRC}
62 63
            SOURCE_DIR ${TPBUILD}/petsc-3.7.2
            TMP_DIR ${TPBUILD}/petsc-3.7.2-tmp
64
            INSTALL_DIR ${TPDIST}
65
            BINARY_DIR ${TPBUILD}/petsc-3.7.2
66
            URL http://www.nektar.info/thirdparty/petsc-lite-3.7.2.tar.gz
67
            URL_MD5 "26c2ff8eaaa9e49aea063f839f5daa7e"
68
            CONFIGURE_COMMAND
69
                OMPI_FC=${CMAKE_Fortran_COMPILER}
70 71
                OMPI_CC=${CMAKE_C_COMPILER}
                OMPI_CXX=${CMAKE_CXX_COMPILER}
72
                ${PYTHON_EXECUTABLE} ./configure
Kilian Lackhove's avatar
Kilian Lackhove committed
73
                ./configure
74
                --with-fc=${PETSC_Fortran_COMPILER}
75 76
                --with-cc=${PETSC_C_COMPILER}
                --with-cxx=${PETSC_CXX_COMPILER}
77
                --with-shared-libraries=1
78
                --with-pic=1
79
                --with-x=0
80
                --with-ssl=0
81
                --prefix=${TPDIST}
82
                --with-petsc-arch=c-opt
83
                ${PETSC_MUMPS}
84
                ${PETSC_NO_MPI}
85
            BUILD_COMMAND MAKEFLAGS= make)
86

87
        SET(PETSC_LIBRARIES petsc CACHE FILEPATH
Dave Moxey's avatar
Dave Moxey committed
88 89 90 91 92
            "PETSc library" FORCE)
        SET(PETSC_INCLUDES ${TPDIST}/include CACHE FILEPATH
            "PETSc includes" FORCE)

        LINK_DIRECTORIES(${TPDIST}/lib)
93
        MESSAGE(STATUS "Build PETSc: ${TPDIST}/${LIB_DIR}/lib${PETSC_LIBRARIES}.so")
Dave Moxey's avatar
Dave Moxey committed
94
        SET(PETSC_CONFIG_INCLUDE_DIR ${TPINC})
95 96 97 98 99 100 101
    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
102
        SET(PETSC_CONFIG_INCLUDE_DIR ${PETSC_INCLUDES})
103
        INCLUDE_DIRECTORIES(${PETSC_INCLUDES})
104
        ADD_CUSTOM_TARGET(petsc-3.7.2 ALL)
105
    ENDIF (THIRDPARTY_BUILD_PETSC)
Dave Moxey's avatar
Dave Moxey committed
106

Dave Moxey's avatar
Dave Moxey committed
107 108
    ADD_DEFINITIONS(-DNEKTAR_USING_PETSC)
    INCLUDE_DIRECTORIES(SYSTEM ${PETSC_INCLUDES})
Douglas Serson's avatar
Douglas Serson committed
109
    IF (NOT NEKTAR_USE_MPI)
110
        INCLUDE_DIRECTORIES(SYSTEM ${PETSC_INCLUDES}/petsc/mpiuni)
Douglas Serson's avatar
Douglas Serson committed
111
    ENDIF (NOT NEKTAR_USE_MPI)
Chris Cantwell's avatar
Chris Cantwell committed
112 113

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