ThirdPartyPETSc.cmake 1.88 KB
Newer Older
Dave Moxey's avatar
Dave Moxey committed
1 2 3 4
OPTION(NEKTAR_USE_PETSC
    "Enable PETSc parallel matrix solver support." OFF)

CMAKE_DEPENDENT_OPTION(THIRDPARTY_BUILD_PETSC
5
    "Build PETSc if needed" OFF
Dave Moxey's avatar
Dave Moxey committed
6 7
    "NEKTAR_USE_PETSC" OFF)

8
IF (NEKTAR_USE_PETSC)
9
    ADD_DEFINITIONS(-DNEKTAR_USING_PETSC)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

    IF (THIRDPARTY_BUILD_PETSC)
        INCLUDE(ExternalProject)

        SET(PETSC_C_COMPILER "${CMAKE_C_COMPILER}")
        SET(PETSC_CXX_COMPILER "${CMAKE_CXX_COMPILER}")

        IF (NEKTAR_USE_MPI)
            IF (NOT MPI_BUILTIN)
                SET(PETSC_C_COMPILER "${MPI_C_COMPILER}")
                SET(PETSC_CXX_COMPILER "${MPI_CXX_COMPILER}")
            ENDIF (NOT MPI_BUILTIN)
        ELSE (NEKTAR_USE_MPI)
            SET(PETSC_NO_MPI "--with-mpi=0")
        ENDIF (NEKTAR_USE_MPI)

        EXTERNALPROJECT_ADD(
            petsc-3.5.1
            PREFIX ${TPSRC}
            BINARY_DIR ${TPSRC}/src/petsc-3.5.1
            URL http://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-lite-3.5.1.tar.gz
            URL_MD5 "539b3bdb627407b7e4e9e830fd5ccf43"
            DOWNLOAD_DIR ${TPSRC}
            CONFIGURE_COMMAND ./configure
                --with-cc=${PETSC_C_COMPILER}
                --with-cxx=${PETSC_CXX_COMPILER}
                --prefix=${TPSRC}/dist
                --with-petsc-arch=c-opt
                --with-fc=0
                ${PETSC_NO_MPI}
                )

        INCLUDE_DIRECTORIES(${TPSRC}/dist/include)
        SET(PETSC_LIBRARIES "${TPSRC}/dist/lib/libpetsc.a")
        MESSAGE(STATUS "Will build PETSc")
    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)
        INCLUDE_DIRECTORIES(${PETSC_INCLUDES})
    ENDIF (THIRDPARTY_BUILD_PETSC)
Dave Moxey's avatar
Dave Moxey committed
54 55 56
ENDIF( NEKTAR_USE_PETSC )

INCLUDE_DIRECTORIES(${PETSC_INCLUDES})