| 1 |
# - Try to find SLEPC |
| 2 |
# Once done this will define |
| 3 |
# |
| 4 |
# SLEPC_FOUND - system has SLEPc |
| 5 |
# SLEPC_INCLUDE_DIRS - include directories for SLEPc |
| 6 |
# SLEPC_LIBRARY_DIRS - library directories for SLEPc |
| 7 |
# SLEPC_LIBARIES - libraries for SLEPc |
| 8 |
# SLEPC_STATIC_LIBARIES - ibraries for SLEPc (static linking, undefined if not required) |
| 9 |
# SLEPC_VERSION - version of SLEPc |
| 10 |
# SLEPC_VERSION_MAJOR - First number in SLEPC_VERSION |
| 11 |
# SLEPC_VERSION_MINOR - Second number in SLEPC_VERSION |
| 12 |
# SLEPC_VERSION_SUBMINOR - Third number in SLEPC_VERSION |
| 13 |
|
| 14 |
|
| 15 |
#============================================================================= |
| 16 |
# Copyright (C) 2010-2016 Garth N. Wells, Anders Logg and Johannes Ring |
| 17 |
# All rights reserved. |
| 18 |
# |
| 19 |
# Redistribution and use in source and binary forms, with or without |
| 20 |
# modification, are permitted provided that the following conditions |
| 21 |
# are met: |
| 22 |
# |
| 23 |
# 1. Redistributions of source code must retain the above copyright |
| 24 |
# notice, this list of conditions and the following disclaimer. |
| 25 |
# 2. Redistributions in binary form must reproduce the above copyright |
| 26 |
# notice, this list of conditions and the following disclaimer in |
| 27 |
# the documentation and/or other materials provided with the |
| 28 |
# distribution. |
| 29 |
# |
| 30 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 31 |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 32 |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 33 |
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 34 |
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 35 |
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 36 |
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 37 |
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 38 |
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 39 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 40 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 41 |
# POSSIBILITY OF SUCH DAMAGE. |
| 42 |
#============================================================================= |
| 43 |
|
| 44 |
# Load CMake pkg-config module |
| 45 |
find_package(PkgConfig REQUIRED) |
| 46 |
|
| 47 |
# Find SLEPc pkg-config file |
| 48 |
set(ENV{PKG_CONFIG_PATH} "$ENV{SLEPC_DIR}/$ENV{PETSC_ARCH}/lib/pkgconfig:$ENV{SLEPC_DIR}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}") |
| 49 |
set(ENV{PKG_CONFIG_PATH} "$ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/lib/pkgconfig:$ENV{PETSC_DIR}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}") |
| 50 |
set(ENV{PKG_CONFIG_PATH} "$ENV{PETSC_DIR}/$ENV{PETSC_ARCH}:$ENV{PETSC_DIR}:$ENV{PKG_CONFIG_PATH}") |
| 51 |
pkg_search_module(SLEPC crayslepc_real slepc SLEPc) |
| 52 |
|
| 53 |
# Extract major, minor, etc from version string |
| 54 |
if (SLEPC_VERSION) |
| 55 |
string(REPLACE "." ";" VERSION_LIST ${SLEPC_VERSION}) |
| 56 |
list(GET VERSION_LIST 0 SLEPC_VERSION_MAJOR) |
| 57 |
list(GET VERSION_LIST 1 SLEPC_VERSION_MINOR) |
| 58 |
list(GET VERSION_LIST 2 SLEPC_VERSION_SUBMINOR) |
| 59 |
endif() |
| 60 |
|
| 61 |
# Configure SLEPc IMPORT (this involves creating an 'imported' target |
| 62 |
# and attaching 'properties') |
| 63 |
if (SLEPC_FOUND AND NOT TARGET SLEPC::slepc) |
| 64 |
add_library(SLEPC::slepc INTERFACE IMPORTED) |
| 65 |
|
| 66 |
# Add include paths |
| 67 |
set_property(TARGET SLEPC::slepc PROPERTY |
| 68 |
INTERFACE_INCLUDE_DIRECTORIES ${SLEPC_INCLUDE_DIRS}) |
| 69 |
|
| 70 |
# Add libraries |
| 71 |
unset(_libs) |
| 72 |
foreach (lib ${SLEPC_LIBRARIES}) |
| 73 |
find_library(LIB_${lib} NAMES ${lib} PATHS ${SLEPC_LIBRARY_DIRS} NO_DEFAULT_PATH) |
| 74 |
list(APPEND _libs ${LIB_${lib}}) |
| 75 |
endforeach() |
| 76 |
set_property(TARGET SLEPC::slepc PROPERTY INTERFACE_LINK_LIBRARIES "${_libs}") |
| 77 |
endif() |
| 78 |
|
| 79 |
if (SLEPC_FOUND AND NOT TARGET SLEPC::slepc_static) |
| 80 |
add_library(SLEPC::slepc_static INTERFACE IMPORTED) |
| 81 |
|
| 82 |
# Add libraries (static) |
| 83 |
unset(_libs) |
| 84 |
foreach (lib ${SLEPC_STATIC_LIBRARIES}) |
| 85 |
find_library(LIB_${lib} ${lib} HINTS ${SLEPC_STATIC_LIBRARY_DIRS}) |
| 86 |
list(APPEND _libs ${LIB_${lib}}) |
| 87 |
endforeach() |
| 88 |
set_property(TARGET SLEPC::slepc_static PROPERTY INTERFACE_LINK_LIBRARIES "${_libs}") |
| 89 |
|
| 90 |
endif() |
| 91 |
|
| 92 |
|
| 93 |
# Compile and run test |
| 94 |
if (DOLFIN_SKIP_BUILD_TESTS) |
| 95 |
|
| 96 |
# Assume SLEPc works |
| 97 |
set(SLEPC_TEST_RUNS TRUE) |
| 98 |
|
| 99 |
elseif (SLEPC_FOUND) |
| 100 |
|
| 101 |
# Create SLEPc test program |
| 102 |
set(SLEPC_TEST_LIB_CPP |
| 103 |
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/slepc_test_lib.cpp") |
| 104 |
file(WRITE ${SLEPC_TEST_LIB_CPP} " |
| 105 |
#include \"petsc.h\" |
| 106 |
#include \"slepceps.h\" |
| 107 |
int main() |
| 108 |
{ |
| 109 |
PetscErrorCode ierr; |
| 110 |
int argc = 0; |
| 111 |
char** argv = NULL; |
| 112 |
ierr = SlepcInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL); |
| 113 |
EPS eps; |
| 114 |
ierr = EPSCreate(PETSC_COMM_SELF, &eps); CHKERRQ(ierr); |
| 115 |
//ierr = EPSSetFromOptions(eps); CHKERRQ(ierr); |
| 116 |
ierr = EPSDestroy(&eps); CHKERRQ(ierr); |
| 117 |
ierr = SlepcFinalize(); CHKERRQ(ierr); |
| 118 |
return 0; |
| 119 |
} |
| 120 |
") |
| 121 |
|
| 122 |
# Add MPI variables if MPI has been found |
| 123 |
if (MPI_C_FOUND) |
| 124 |
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${MPI_C_INCLUDE_PATH}) |
| 125 |
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${MPI_C_LIBRARIES}) |
| 126 |
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${MPI_C_COMPILE_FLAGS}") |
| 127 |
endif() |
| 128 |
|
| 129 |
# Try to run test program (shared linking) |
| 130 |
try_run( |
| 131 |
SLEPC_TEST_LIB_EXITCODE |
| 132 |
SLEPC_TEST_LIB_COMPILED |
| 133 |
${CMAKE_CURRENT_BINARY_DIR} |
| 134 |
${SLEPC_TEST_LIB_CPP} |
| 135 |
CMAKE_FLAGS |
| 136 |
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}" |
| 137 |
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} PETSC::petsc SLEPC::slepc |
| 138 |
COMPILE_OUTPUT_VARIABLE SLEPC_TEST_LIB_COMPILE_OUTPUT |
| 139 |
RUN_OUTPUT_VARIABLE SLEPC_TEST_LIB_OUTPUT |
| 140 |
) |
| 141 |
|
| 142 |
if (SLEPC_TEST_LIB_COMPILED AND SLEPC_TEST_LIB_EXITCODE EQUAL 0) |
| 143 |
|
| 144 |
message(STATUS "Test SLEPC_TEST_RUNS with shared library linking - Success") |
| 145 |
set(SLEPC_TEST_RUNS TRUE) |
| 146 |
|
| 147 |
# Static libraries not required, so unset |
| 148 |
set_property(TARGET SLEPC::slepc_static PROPERTY INTERFACE_LINK_LIBRARIES) |
| 149 |
|
| 150 |
else() |
| 151 |
|
| 152 |
message(STATUS "Test SLEPC_TEST_RUNS with shared library linking - Failed") |
| 153 |
|
| 154 |
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log |
| 155 |
"Failed to run SLEPc test with shared library linking:\n" |
| 156 |
"CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}\n" |
| 157 |
"CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}\n" |
| 158 |
"CMAKE_REQUIRED_FLAGS: ${CMAKE_REQUIRED_FLAGS}\n" |
| 159 |
"SLEPC_TEST_LIB_EXITCODE: ${SLEPC_TEST_LIB_EXITCODE}\n" |
| 160 |
"SLEPC_TEST_LIB_COMPILED: ${SLEPC_TEST_LIB_COMPILED}\n" |
| 161 |
"SLEPC_TEST_LIB_COMPILE_OUTPUT: ${SLEPC_TEST_LIB_COMPILE_OUTPUT}\n" |
| 162 |
"SLEPC_TEST_LIB_OUTPUT: ${SLEPC_TEST_LIB_OUTPUT}\n\n") |
| 163 |
|
| 164 |
# Add MPI variables if MPI has been found |
| 165 |
if (MPI_C_FOUND) |
| 166 |
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${MPI_C_INCLUDE_PATH}) |
| 167 |
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${MPI_C_LIBRARIES}) |
| 168 |
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${MPI_C_COMPILE_FLAGS}") |
| 169 |
endif() |
| 170 |
|
| 171 |
# Try to run test program (static linking) |
| 172 |
try_run( |
| 173 |
SLEPC_TEST_STATIC_LIBS_EXITCODE |
| 174 |
SLEPC_TEST_STATIC_LIBS_COMPILED |
| 175 |
${CMAKE_CURRENT_BINARY_DIR} |
| 176 |
${SLEPC_TEST_LIB_CPP} |
| 177 |
CMAKE_FLAGS |
| 178 |
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}" |
| 179 |
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} SLEPC::slepc SLEPC::slepc_static |
| 180 |
COMPILE_OUTPUT_VARIABLE SLEPC_TEST_STATIC_LIBS_COMPILE_OUTPUT |
| 181 |
RUN_OUTPUT_VARIABLE SLEPC_TEST_STATIC_LIBS_OUTPUT |
| 182 |
) |
| 183 |
|
| 184 |
if (SLEPC_TEST_STATIC_LIBS_COMPILED AND SLEPC_TEST_STATIC_LIBS_EXITCODE EQUAL 0) |
| 185 |
message(STATUS "Test SLEPC_TEST__RUNS with static linking - Success") |
| 186 |
set(SLEPC_TEST_RUNS TRUE) |
| 187 |
else() |
| 188 |
message(STATUS "Test SLEPC_TETS_RUNS with static linking - Failed") |
| 189 |
|
| 190 |
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log |
| 191 |
"Failed to run SLEPc test with static library linking:\n" |
| 192 |
"CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}\n" |
| 193 |
"CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}\n" |
| 194 |
"CMAKE_REQUIRED_FLAGS: ${CMAKE_REQUIRED_FLAGS}\n" |
| 195 |
"SLEPC_TEST_STATIC_LIB_EXITCODE: ${SLEPC_TEST_STATIC_LIB_EXITCODE}\n" |
| 196 |
"SLEPC_TEST_STATIC_LIB_COMPILED: ${PETSC_TEST_STATIC_LIB_COMPILED}\n" |
| 197 |
"SLEPC_TEST_STATIC_LIBS_COMPILE_OUTPUT: ${SLEPC_TEST_STATIC_LIBS_COMPILE_OUTPUT}\n" |
| 198 |
"SLEPC_TEST_STATIC_LIBS_OUTPUT: ${SLEPC_TEST_STATIC_LIBS_OUTPUT}\n\n") |
| 199 |
|
| 200 |
set(SLEPC_TEST_RUNS FALSE) |
| 201 |
endif() |
| 202 |
endif() |
| 203 |
endif() |
| 204 |
|
| 205 |
# Standard package handling |
| 206 |
include(FindPackageHandleStandardArgs) |
| 207 |
if (SLEPC_FOUND) |
| 208 |
find_package_handle_standard_args(SLEPc |
| 209 |
REQUIRED_VARS SLEPC_FOUND SLEPC_TEST_RUNS |
| 210 |
VERSION_VAR SLEPC_VERSION |
| 211 |
FAIL_MESSAGE "SLEPc could not be configured.") |
| 212 |
else() |
| 213 |
find_package_handle_standard_args(SLEPc |
| 214 |
REQUIRED_VARS SLEPC_FOUND |
| 215 |
FAIL_MESSAGE "SLEPc could not be found. Be sure to set SLEPC_DIR.") |
| 216 |
endif() |