2014-05-16 02:06:14 -05:00
|
|
|
# - Try to find Petsc lib
|
2014-05-16 01:43:04 -05:00
|
|
|
#
|
|
|
|
# This module supports requiring a minimum version, e.g. you can do
|
2014-05-16 02:06:14 -05:00
|
|
|
# find_package(Petsc)
|
2014-05-16 01:43:04 -05:00
|
|
|
#
|
|
|
|
# Once done this will define
|
|
|
|
#
|
2014-05-16 02:06:14 -05:00
|
|
|
# PETSC_FOUND - system has Petsc lib with correct version
|
|
|
|
# PETSC_INCLUDE_DIRS - the Petsc include directory
|
|
|
|
# PETSC_LIBRARIES - the Petsc library.
|
2014-05-16 01:43:04 -05:00
|
|
|
|
|
|
|
# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
|
|
|
|
# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
|
|
|
|
# Copyright (c) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
|
|
|
|
# Redistribution and use is allowed according to the terms of the 2-clause BSD license.
|
|
|
|
|
|
|
|
# find out the size of a pointer. this is required to only search for
|
|
|
|
# libraries in the directories relevant for the architecture
|
|
|
|
if (CMAKE_SIZEOF_VOID_P)
|
|
|
|
math (EXPR _BITS "8 * ${CMAKE_SIZEOF_VOID_P}")
|
|
|
|
endif (CMAKE_SIZEOF_VOID_P)
|
|
|
|
|
2014-09-19 04:40:20 -05:00
|
|
|
# if PETSC_ROOT is set, then this is the only place searched for petsc headers
|
|
|
|
# and includes
|
|
|
|
set(_no_default_path "")
|
|
|
|
if(PETSC_ROOT)
|
|
|
|
set (_no_default_path "NO_DEFAULT_PATH")
|
|
|
|
endif()
|
|
|
|
|
2014-05-16 01:43:04 -05:00
|
|
|
# look for a system-wide BLAS library
|
|
|
|
set(PETSC_BLAS_LIBRARY "")
|
2014-09-19 05:32:50 -05:00
|
|
|
find_package(BLAS QUIET)
|
|
|
|
list(APPEND PETSC_BLAS_LIBRARY "${BLAS_LIBRARIES}")
|
|
|
|
|
|
|
|
# if BLAS wasn't found, look for it in PETSC_ROOT. Won't search if
|
|
|
|
# PETSC_BLAS_LIBRARY is set.
|
|
|
|
find_library(PETSC_BLAS_LIBRARY
|
|
|
|
NAME "blas"
|
|
|
|
PATH ${PETSC_ROOT}
|
|
|
|
PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}"
|
|
|
|
${_no_default_path}
|
|
|
|
)
|
|
|
|
|
2014-05-16 01:43:04 -05:00
|
|
|
# print message if there was still no blas found!
|
|
|
|
if(NOT BLAS_FOUND AND NOT PETSC_BLAS_LIBRARY)
|
|
|
|
message(STATUS "BLAS not found but required for PETSC")
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
list(APPEND CMAKE_REQUIRED_LIBRARIES "${PETSC_BLAS_LIBRARY}")
|
|
|
|
|
|
|
|
set(PETSC_LAPACK_LIBRARY "")
|
2014-09-19 05:32:50 -05:00
|
|
|
find_package(LAPACK QUIET)
|
|
|
|
list(APPEND PETSC_LAPACK_LIBRARY "${LAPACK_LIBRARIES}")
|
|
|
|
|
|
|
|
# if LAPACK wasn't found, look for it in PETSC_ROOT
|
|
|
|
find_library(PETSC_LAPACK_LIBRARY
|
|
|
|
NAME "lapack"
|
|
|
|
PATH ${PETSC_ROOT}
|
|
|
|
PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}"
|
|
|
|
${_no_default_path}
|
|
|
|
)
|
|
|
|
|
2014-05-16 01:43:04 -05:00
|
|
|
# print message if there was still no blas found!
|
|
|
|
if(NOT LAPACK_FOUND AND NOT PETSC_LAPACK_LIBRARY)
|
|
|
|
message(STATUS "LAPACK not found but required for PETSC")
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
list(APPEND CMAKE_REQUIRED_LIBRARIES "${PETSC_LAPACK_LIBRARY}")
|
|
|
|
|
|
|
|
find_package(X11 QUIET)
|
|
|
|
if (X11_FOUND)
|
|
|
|
list(APPEND PETSC_X11_LIBRARY "${X11_LIBRARIES}")
|
|
|
|
endif()
|
|
|
|
list(APPEND CMAKE_REQUIRED_LIBRARIES "${PETSC_X11_LIBRARY}")
|
2014-09-19 05:32:50 -05:00
|
|
|
|
2014-05-16 01:43:04 -05:00
|
|
|
# only probe if we haven't a path in our cache
|
|
|
|
if (Petsc_ROOT)
|
|
|
|
set (PETSC_ROOT "${Petsc_ROOT}")
|
|
|
|
endif (Petsc_ROOT)
|
2014-09-19 04:40:20 -05:00
|
|
|
|
2014-09-19 05:32:50 -05:00
|
|
|
find_path (PETSC_NORMAL_INCLUDE_DIR
|
|
|
|
NAMES "petsc.h"
|
|
|
|
PATHS ${PETSC_ROOT}
|
|
|
|
PATH_SUFFIXES "petsc-3.4.4" "include" "petsc"
|
|
|
|
${_no_default_path}
|
|
|
|
)
|
2014-09-17 06:33:41 -05:00
|
|
|
|
|
|
|
# if parallel computing is explicitly enabled - reuse the paths and links from
|
|
|
|
# OpmMainLib + OpmFind
|
|
|
|
# this needs to be called explicitly as FindPetsc runs before OpmMainLib starts
|
|
|
|
# looking for MPI (for some reason). Ideally this isn't necessary
|
|
|
|
if(USE_MPI)
|
|
|
|
find_package(MPI)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
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"
|
|
|
|
PATHS ${PETSC_ROOT}/include
|
|
|
|
PATH_SUFFIXES "mpiuni"
|
2014-09-19 04:40:20 -05:00
|
|
|
${_no_default_path}
|
2014-09-17 06:33:41 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
if(PETSC_MPI_INCLUDE_DIRS)
|
|
|
|
set(PETSC_MPI_FOUND 1)
|
|
|
|
endif(PETSC_MPI_INCLUDE_DIRS)
|
|
|
|
|
|
|
|
endif(NOT PETSC_MPI_INCLUDE_DIRS)
|
|
|
|
|
|
|
|
# couldn't find any usable mpi implementation - abort
|
|
|
|
if(NOT PETSC_MPI_FOUND)
|
2014-09-19 04:40:20 -05:00
|
|
|
message(STATUS "Could not find any suitable MPI implementation.")
|
2014-09-17 06:33:41 -05:00
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
2014-05-16 01:43:04 -05:00
|
|
|
# look for actual Petsc library
|
2014-09-19 05:32:50 -05:00
|
|
|
find_library(PETSC_LIBRARY
|
2014-05-16 01:43:04 -05:00
|
|
|
NAMES "petsc-3.4.3" "petsc-3.4.4" "petsc"
|
|
|
|
PATHS ${PETSC_ROOT}
|
|
|
|
PATH_SUFFIXES "lib" "lib${_BITS}" "lib/${CMAKE_LIBRARY_ARCHITECTURE}"
|
2014-09-19 04:40:20 -05:00
|
|
|
${_no_default_path}
|
2014-05-16 01:43:04 -05:00
|
|
|
)
|
2014-09-19 05:32:50 -05:00
|
|
|
|
2014-05-16 01:43:04 -05:00
|
|
|
if(NOT PETSC_LIBRARY)
|
2014-09-16 06:37:06 -05:00
|
|
|
message(STATUS "Could not find the PETSc library")
|
2014-05-16 01:43:04 -05:00
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
2014-09-17 06:33:41 -05:00
|
|
|
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})
|
2014-05-16 01:43:04 -05:00
|
|
|
endif()
|
|
|
|
|
|
|
|
include(FindPackageHandleStandardArgs)
|
|
|
|
find_package_handle_standard_args(Petsc DEFAULT_MSG PETSC_INCLUDE_DIR PETSC_LIBRARY)
|
|
|
|
mark_as_advanced(PETSC_INCLUDE_DIR PETSC_LIBRARY)
|
|
|
|
|
|
|
|
# if both headers and library are found, store results
|
|
|
|
if(PETSC_FOUND)
|
2014-09-19 05:32:50 -05:00
|
|
|
set(PETSC_INCLUDE_DIRS ${PETSC_INCLUDE_DIR})
|
|
|
|
set(PETSC_LIBRARIES ${PETSC_LIBRARY})
|
2014-05-16 01:43:04 -05:00
|
|
|
|
|
|
|
list(APPEND PETSC_LIBRARIES ${PETSC_BLAS_LIBRARY})
|
|
|
|
list(APPEND PETSC_LIBRARIES ${PETSC_LAPACK_LIBRARY})
|
|
|
|
list(APPEND PETSC_LIBRARIES ${PETSC_X11_LIBRARY})
|
|
|
|
endif()
|