Merge pull request #777 from jorgekva/petsc-support-build

Cleans up PETSc detection
This commit is contained in:
Atgeirr Flø Rasmussen 2015-04-08 14:03:56 +02:00
commit f236d19b70
2 changed files with 42 additions and 46 deletions

View File

@ -43,10 +43,9 @@ find_library(PETSC_BLAS_LIBRARY
# print message if there was still no blas found! # print message if there was still no blas found!
if(NOT BLAS_FOUND AND NOT PETSC_BLAS_LIBRARY) if(NOT BLAS_FOUND AND NOT PETSC_BLAS_LIBRARY)
message(STATUS "BLAS not found but required for PETSC") message(STATUS "BLAS not found but required for PETSc")
return() return()
endif() endif()
list(APPEND CMAKE_REQUIRED_LIBRARIES "${PETSC_BLAS_LIBRARY}")
set(PETSC_LAPACK_LIBRARY "") set(PETSC_LAPACK_LIBRARY "")
find_package(LAPACK QUIET) find_package(LAPACK QUIET)
@ -62,62 +61,60 @@ find_library(PETSC_LAPACK_LIBRARY
# print message if there was still no blas found! # print message if there was still no blas found!
if(NOT LAPACK_FOUND AND NOT PETSC_LAPACK_LIBRARY) if(NOT LAPACK_FOUND AND NOT PETSC_LAPACK_LIBRARY)
message(STATUS "LAPACK not found but required for PETSC") message(STATUS "LAPACK not found but required for PETSc")
return() return()
endif() endif()
list(APPEND CMAKE_REQUIRED_LIBRARIES "${PETSC_LAPACK_LIBRARY}")
find_package(X11 QUIET) find_package(X11 QUIET)
if (X11_FOUND) if (X11_FOUND)
list(APPEND PETSC_X11_LIBRARY "${X11_LIBRARIES}") list(APPEND PETSC_X11_LIBRARY "${X11_LIBRARIES}")
endif() endif()
list(APPEND CMAKE_REQUIRED_LIBRARIES "${PETSC_X11_LIBRARY}")
# only probe if we haven't a path in our cache # these variables must exist. Since not finding MPI, both the header and the
if (Petsc_ROOT) # object file , may not be an error, we want the option of concatenating the
set (PETSC_ROOT "${Petsc_ROOT}") # empty variable onto the PETSC_LIBRARIES/INCLUDE_DIRS lists
endif (Petsc_ROOT) set(PETSC_MPI_LIBRARY "")
set(PETSC_MPI_INCLUDE_DIRS "")
find_path (PETSC_NORMAL_INCLUDE_DIR find_package(MPI)
NAMES "petsc.h" if(MPI_FOUND)
PATHS ${PETSC_ROOT} list(APPEND PETSC_MPI_LIBRARY "${MPI_LIBRARIES}")
PATH_SUFFIXES "petsc-3.4.4" "include" "petsc" set(PETSC_MPI_INCLUDE_DIRS ${MPI_INCLUDE_PATH})
${_no_default_path}
)
# if parallel computing is explicitly enabled - reuse the paths and links from else(MPI_FOUND)
# OpmMainLib + OpmFind # if a system MPI wasn't found, look for PETSc's serial implementation. This
# this needs to be called explicitly as FindPetsc runs before OpmMainLib starts # won't be available if PETSc was compiled with --with-mpi=0, so not finding
# looking for MPI (for some reason). Ideally this isn't necessary # this won't be an error. This only needs to find the header, as the MPI
if(USE_MPI) # implementation should be already be compiled into PETSc.
find_package(MPI) message(STATUS "Could not find a system provided MPI. Searching for PETSc provided mpiuni fallback implementation.")
endif() find_path(PETSC_MPI_INCLUDE_DIRS
set(PETSC_MPI_FOUND ${MPI_FOUND})
set(PETSC_MPI_INCLUDE_DIRS ${MPI_INCLUDE_PATH})
set(PETSC_MPI_LIBRARIES ${MPI_LIBRARIES})
# fallback - use the petsc provided implementation of serial MPI.
if (NOT PETSC_MPI_INCLUDE_DIRS)
message(STATUS "Building without MPI support - looking for PETSc provided serial implementation")
find_path (PETSC_MPI_INCLUDE_DIRS
NAMES "mpi.h" NAMES "mpi.h"
PATHS ${PETSC_ROOT}/include PATHS ${PETSC_ROOT}/include
PATH_SUFFIXES "mpiuni" PATH_SUFFIXES "mpiuni"
${_no_default_path} ${_no_default_path}
) )
endif(MPI_FOUND)
if(PETSC_MPI_INCLUDE_DIRS) if(NOT PETSC_MPI_INCLUDE_DIRS)
set(PETSC_MPI_FOUND 1) message(WARNING "Could not find any MPI implementation. If PETSc is compiled with --with-mpi=0 this is ok. Otherwise you will get linker errors or (possibly subtle) runtime errors. Continuing.")
endif(PETSC_MPI_INCLUDE_DIRS) if(NOT USE_MPI)
message("To build with MPI support, pass -DUSE_MPI=ON to CMake.")
endif(NOT USE_MPI)
endif(NOT PETSC_MPI_INCLUDE_DIRS) endif(NOT PETSC_MPI_INCLUDE_DIRS)
# couldn't find any usable mpi implementation - abort # only probe if we haven't a path in our cache
if(NOT PETSC_MPI_FOUND) if (Petsc_ROOT)
message(STATUS "Could not find any suitable MPI implementation.") set (PETSC_ROOT "${Petsc_ROOT}")
return() endif (Petsc_ROOT)
endif()
find_path (PETSC_NORMAL_INCLUDE_DIR
NAMES "petsc.h"
PATHS ${PETSC_ROOT}
PATH_SUFFIXES "include" "petsc"
${_no_default_path}
)
list(APPEND PETSC_INCLUDE_DIR ${PETSC_NORMAL_INCLUDE_DIR})
# look for actual Petsc library # look for actual Petsc library
find_library(PETSC_LIBRARY find_library(PETSC_LIBRARY
@ -132,11 +129,6 @@ if(NOT PETSC_LIBRARY)
return() return()
endif() endif()
list(APPEND CMAKE_REQUIRED_LIBRARIES "${PETSC_LIBRARY}" "${PETSC_MPI_LIBRARIES}")
if (PETSC_MPI_INCLUDE_DIRS AND PETSC_NORMAL_INCLUDE_DIR)
list (APPEND PETSC_INCLUDE_DIR ${PETSC_MPI_INCLUDE_DIRS} ${PETSC_NORMAL_INCLUDE_DIR})
endif()
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Petsc DEFAULT_MSG PETSC_INCLUDE_DIR PETSC_LIBRARY) find_package_handle_standard_args(Petsc DEFAULT_MSG PETSC_INCLUDE_DIR PETSC_LIBRARY)
@ -145,9 +137,12 @@ mark_as_advanced(PETSC_INCLUDE_DIR PETSC_LIBRARY)
# if both headers and library are found, store results # if both headers and library are found, store results
if(PETSC_FOUND) if(PETSC_FOUND)
set(PETSC_INCLUDE_DIRS ${PETSC_INCLUDE_DIR}) set(PETSC_INCLUDE_DIRS ${PETSC_INCLUDE_DIR})
list(APPEND PETSC_INCLUDE_DIRS ${PETSC_MPI_INCLUDE_DIRS})
set(PETSC_LIBRARIES ${PETSC_LIBRARY}) set(PETSC_LIBRARIES ${PETSC_LIBRARY})
list(APPEND PETSC_LIBRARIES ${PETSC_BLAS_LIBRARY}) list(APPEND PETSC_LIBRARIES ${PETSC_BLAS_LIBRARY})
list(APPEND PETSC_LIBRARIES ${PETSC_LAPACK_LIBRARY}) list(APPEND PETSC_LIBRARIES ${PETSC_LAPACK_LIBRARY})
list(APPEND PETSC_LIBRARIES ${PETSC_X11_LIBRARY}) list(APPEND PETSC_LIBRARIES ${PETSC_X11_LIBRARY})
list(APPEND PETSC_LIBRARIES ${PETSC_MPI_LIBRARY})
endif() endif()

View File

@ -26,13 +26,14 @@ set (opm-core_DEPS
"SuiteSparse COMPONENTS umfpack" "SuiteSparse COMPONENTS umfpack"
# solver # solver
"SuperLU" "SuperLU"
"Petsc"
# xml processing (for config parsing) # xml processing (for config parsing)
"TinyXML" "TinyXML"
# Ensembles-based Reservoir Tools (ERT) # Ensembles-based Reservoir Tools (ERT)
"ERT REQUIRED" "ERT REQUIRED"
# Look for MPI support # Look for MPI support
"MPI" "MPI"
# PETSc numerical backend
"PETSc"
# DUNE dependency # DUNE dependency
"dune-common" "dune-common"
"dune-istl" "dune-istl"