| 1 |
# - Try to find petsc4py |
| 2 |
# Once done this will define |
| 3 |
# |
| 4 |
# PETSC4PY_FOUND - system has petsc4py |
| 5 |
# PETSC4PY_INCLUDE_DIRS - include directories for petsc4py |
| 6 |
# PETSC4PY_VERSION - version of petsc4py |
| 7 |
# PETSC4PY_VERSION_MAJOR - first number in PETSC4PY_VERSION |
| 8 |
# PETSC4PY_VERSION_MINOR - second number in PETSC4PY_VERSION |
| 9 |
|
| 10 |
# Based on FindNumPy.cmake |
| 11 |
|
| 12 |
#============================================================================= |
| 13 |
# Copyright (C) 2013 Lawrence Mitchell |
| 14 |
# All rights reserved. |
| 15 |
# |
| 16 |
# Redistribution and use in source and binary forms, with or without |
| 17 |
# modification, are permitted provided that the following conditions |
| 18 |
# are met: |
| 19 |
# |
| 20 |
# 1. Redistributions of source code must retain the above copyright |
| 21 |
# notice, this list of conditions and the following disclaimer. |
| 22 |
# 2. Redistributions in binary form must reproduce the above copyright |
| 23 |
# notice, this list of conditions and the following disclaimer in |
| 24 |
# the documentation and/or other materials provided with the |
| 25 |
# distribution. |
| 26 |
# |
| 27 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 28 |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 29 |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 30 |
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 31 |
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 32 |
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 33 |
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 34 |
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 35 |
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 36 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 37 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 38 |
# POSSIBILITY OF SUCH DAMAGE. |
| 39 |
#============================================================================= |
| 40 |
|
| 41 |
message(STATUS "Checking for package 'PETSc4Py'") |
| 42 |
|
| 43 |
if(PETSC4PY_INCLUDE_DIRS) |
| 44 |
# In cache already |
| 45 |
set(PETSC4PY_FIND_QUIETLY TRUE) |
| 46 |
endif(PETSC4PY_INCLUDE_DIRS) |
| 47 |
|
| 48 |
execute_process( |
| 49 |
COMMAND ${PYTHON_EXECUTABLE} -c "import petsc4py; print(petsc4py.get_include())" |
| 50 |
OUTPUT_VARIABLE PETSC4PY_INCLUDE_DIRS |
| 51 |
RESULT_VARIABLE PETSC4PY_NOT_FOUND |
| 52 |
ERROR_QUIET |
| 53 |
OUTPUT_STRIP_TRAILING_WHITESPACE |
| 54 |
) |
| 55 |
|
| 56 |
if(PETSC4PY_INCLUDE_DIRS) |
| 57 |
set(PETSC4PY_FOUND TRUE) |
| 58 |
set(PETSC4PY_INCLUDE_DIRS ${PETSC4PY_INCLUDE_DIRS} CACHE STRING "petsc4py include path") |
| 59 |
else(PETSC4PY_INCLUDE_DIRS) |
| 60 |
set(PETSC4PY_FOUND FALSE) |
| 61 |
endif(PETSC4PY_INCLUDE_DIRS) |
| 62 |
|
| 63 |
if(PETSC4PY_FOUND) |
| 64 |
execute_process( |
| 65 |
COMMAND ${PYTHON_EXECUTABLE} -c "import petsc4py; print(petsc4py.__version__)" |
| 66 |
OUTPUT_VARIABLE PETSC4PY_VERSION |
| 67 |
RESULT_VARIABLE PETSC4PY_NOT_FOUND |
| 68 |
OUTPUT_STRIP_TRAILING_WHITESPACE |
| 69 |
) |
| 70 |
string(REPLACE "." ";" PETSC4PY_VERSION_LIST ${PETSC4PY_VERSION}) |
| 71 |
list(GET PETSC4PY_VERSION_LIST 0 PETSC4PY_VERSION_MAJOR) |
| 72 |
list(GET PETSC4PY_VERSION_LIST 1 PETSC4PY_VERSION_MINOR) |
| 73 |
if(NOT PETSC4PY_FIND_QUIETLY) |
| 74 |
message(STATUS "petsc4py version ${PETSC4PY_VERSION} found") |
| 75 |
endif(NOT PETSC4PY_FIND_QUIETLY) |
| 76 |
else(PETSC4PY_FOUND) |
| 77 |
if(PETSC4PY_FIND_REQUIRED) |
| 78 |
message(FATAL_ERROR "petsc4py missing") |
| 79 |
endif(PETSC4PY_FIND_REQUIRED) |
| 80 |
endif(PETSC4PY_FOUND) |
| 81 |
|
| 82 |
mark_as_advanced(PETSC4PY_INCLUDE_DIRS, PETSC4PY_VERSION, PETSC4PY_VERSION_MAJOR, PETSC4PY_VERSION_MINOR) |
| 83 |
|
| 84 |
if (PETSc4py_FIND_VERSION) |
| 85 |
# Check if version found is >= required version |
| 86 |
if (NOT "${PETSC4PY_VERSION}" VERSION_LESS "${PETSc4py_FIND_VERSION}") |
| 87 |
set(PETSC4PY_VERSION_OK TRUE) |
| 88 |
endif() |
| 89 |
else() |
| 90 |
# No specific version requested |
| 91 |
set(PETSC4PY_VERSION_OK TRUE) |
| 92 |
endif() |
| 93 |
mark_as_advanced(PETSC4PY_VERSION_OK) |
| 94 |
|
| 95 |
# Standard package handling |
| 96 |
include(FindPackageHandleStandardArgs) |
| 97 |
find_package_handle_standard_args(PETSc4py |
| 98 |
"PETSc4py could not be found. Be sure to set PYTHONPATH appropriately." |
| 99 |
PETSC4PY_INCLUDE_DIRS PETSC4PY_VERSION PETSC4PY_VERSION_OK) |
| 100 |
|
| 101 |
# Check petsc4py.i for PETSC_INT |
| 102 |
if(PETSC4PY_INCLUDE_DIRS) |
| 103 |
file(STRINGS "${PETSC4PY_INCLUDE_DIRS}/petsc4py/petsc4py.i" PETSC4PY_INT) |
| 104 |
string(REGEX MATCH "SWIG_TYPECHECK_INT[0-9]+" PETSC4PY_INT "${PETSC4PY_INT}") |
| 105 |
string(REPLACE "SWIG_TYPECHECK_INT" "" PETSC4PY_INT "${PETSC4PY_INT}") |
| 106 |
math(EXPR PETSC_INT "${PETSC_INT_SIZE}*8") |
| 107 |
if(NOT PETSC_INT STREQUAL PETSC4PY_INT) |
| 108 |
message(STATUS "PETSC_INT = ${PETSC4PY_INT} ${PETSC_INT}") |
| 109 |
message(STATUS " - does not match") |
| 110 |
set(PETSC4PY_FOUND FALSE) |
| 111 |
endif() |
| 112 |
endif() |