| 1 |
# - Try to find ParMETIS |
| 2 |
# Once done this will define |
| 3 |
# |
| 4 |
# PARMETIS_FOUND - system has ParMETIS |
| 5 |
# PARMETIS_INCLUDE_DIRS - include directories for ParMETIS |
| 6 |
# PARMETIS_LIBRARIES - libraries for ParMETIS |
| 7 |
# PARMETIS_VERSION - version for ParMETIS |
| 8 |
|
| 9 |
#============================================================================= |
| 10 |
# Copyright (C) 2010 Garth N. Wells, Anders Logg and Johannes Ring |
| 11 |
# All rights reserved. |
| 12 |
# |
| 13 |
# Redistribution and use in source and binary forms, with or without |
| 14 |
# modification, are permitted provided that the following conditions |
| 15 |
# are met: |
| 16 |
# |
| 17 |
# 1. Redistributions of source code must retain the above copyright |
| 18 |
# notice, this list of conditions and the following disclaimer. |
| 19 |
# 2. Redistributions in binary form must reproduce the above copyright |
| 20 |
# notice, this list of conditions and the following disclaimer in |
| 21 |
# the documentation and/or other materials provided with the |
| 22 |
# distribution. |
| 23 |
# |
| 24 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 25 |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 26 |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 27 |
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 28 |
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 29 |
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 30 |
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 31 |
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 32 |
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 33 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 34 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 35 |
# POSSIBILITY OF SUCH DAMAGE. |
| 36 |
#============================================================================= |
| 37 |
|
| 38 |
if (MPI_CXX_FOUND) |
| 39 |
find_path(PARMETIS_INCLUDE_DIRS parmetis.h |
| 40 |
HINTS ${PARMETIS_DIR}/include $ENV{PARMETIS_DIR}/include ${PETSC_INCLUDE_DIRS} |
| 41 |
DOC "Directory where the ParMETIS header files are located" |
| 42 |
) |
| 43 |
|
| 44 |
find_library(PARMETIS_LIBRARY parmetis |
| 45 |
HINTS ${PARMETIS_DIR}/lib $ENV{PARMETIS_DIR}/lib ${PETSC_LIBRARY_DIRS} |
| 46 |
NO_DEFAULT_PATH |
| 47 |
DOC "Directory where the ParMETIS library is located" |
| 48 |
) |
| 49 |
find_library(PARMETIS_LIBRARY parmetis |
| 50 |
DOC "Directory where the ParMETIS library is located" |
| 51 |
) |
| 52 |
|
| 53 |
find_library(METIS_LIBRARY metis |
| 54 |
HINTS ${PARMETIS_DIR}/lib $ENV{PARMETIS_DIR}/lib ${PETSC_LIBRARY_DIRS} |
| 55 |
NO_DEFAULT_PATH |
| 56 |
DOC "Directory where the METIS library is located" |
| 57 |
) |
| 58 |
find_library(METIS_LIBRARY metis |
| 59 |
DOC "Directory where the METIS library is located" |
| 60 |
) |
| 61 |
|
| 62 |
set(PARMETIS_LIBRARIES ${PARMETIS_LIBRARY}) |
| 63 |
if (METIS_LIBRARY) |
| 64 |
set(PARMETIS_LIBRARIES ${PARMETIS_LIBRARIES} ${METIS_LIBRARY}) |
| 65 |
endif() |
| 66 |
|
| 67 |
# Try compiling and running test program |
| 68 |
if (DOLFIN_SKIP_BUILD_TESTS) |
| 69 |
set(PARMETIS_TEST_RUNS TRUE) |
| 70 |
set(PARMETIS_VERSION "UNKNOWN") |
| 71 |
set(PARMETIS_VERSION_OK TRUE) |
| 72 |
elseif (PARMETIS_INCLUDE_DIRS AND PARMETIS_LIBRARY) |
| 73 |
|
| 74 |
# Set flags for building test program |
| 75 |
set(CMAKE_REQUIRED_INCLUDES ${PARMETIS_INCLUDE_DIRS} ${MPI_CXX_INCLUDE_PATH}) |
| 76 |
set(CMAKE_REQUIRED_LIBRARIES ${PARMETIS_LIBRARIES} ${MPI_CXX_LIBRARIES}) |
| 77 |
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} ${MPI_CXX_COMPILE_FLAGS}) |
| 78 |
|
| 79 |
# Check ParMETIS version |
| 80 |
set(PARMETIS_CONFIG_TEST_VERSION_CPP |
| 81 |
"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/parmetis_config_test_version.cpp") |
| 82 |
file(WRITE ${PARMETIS_CONFIG_TEST_VERSION_CPP} " |
| 83 |
#define MPICH_IGNORE_CXX_SEEK 1 |
| 84 |
#include <iostream> |
| 85 |
#include \"parmetis.h\" |
| 86 |
|
| 87 |
int main() { |
| 88 |
#ifdef PARMETIS_SUBMINOR_VERSION |
| 89 |
std::cout << PARMETIS_MAJOR_VERSION << \".\" |
| 90 |
<< PARMETIS_MINOR_VERSION << \".\" |
| 91 |
<< PARMETIS_SUBMINOR_VERSION; |
| 92 |
#else |
| 93 |
std::cout << PARMETIS_MAJOR_VERSION << \".\" |
| 94 |
<< PARMETIS_MINOR_VERSION; |
| 95 |
#endif |
| 96 |
return 0; |
| 97 |
} |
| 98 |
") |
| 99 |
|
| 100 |
try_run( |
| 101 |
PARMETIS_CONFIG_TEST_VERSION_EXITCODE |
| 102 |
PARMETIS_CONFIG_TEST_VERSION_COMPILED |
| 103 |
${CMAKE_CURRENT_BINARY_DIR} |
| 104 |
${PARMETIS_CONFIG_TEST_VERSION_CPP} |
| 105 |
CMAKE_FLAGS |
| 106 |
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}" |
| 107 |
"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}" |
| 108 |
COMPILE_OUTPUT_VARIABLE PARMETIS_CONFIG_TEST_VERSION_COMPILE_OUTPUT |
| 109 |
RUN_OUTPUT_VARIABLE PARMETIS_CONFIG_TEST_VERSION_OUTPUT |
| 110 |
) |
| 111 |
|
| 112 |
if (PARMETIS_CONFIG_TEST_VERSION_EXITCODE EQUAL 0) |
| 113 |
set(PARMETIS_VERSION ${PARMETIS_CONFIG_TEST_VERSION_OUTPUT} CACHE TYPE STRING) |
| 114 |
mark_as_advanced(PARMETIS_VERSION) |
| 115 |
endif() |
| 116 |
|
| 117 |
if (ParMETIS_FIND_VERSION) |
| 118 |
# Check if version found is >= required version |
| 119 |
if (NOT "${PARMETIS_VERSION}" VERSION_LESS "${ParMETIS_FIND_VERSION}") |
| 120 |
set(PARMETIS_VERSION_OK TRUE) |
| 121 |
endif() |
| 122 |
else() |
| 123 |
# No specific version requested |
| 124 |
set(PARMETIS_VERSION_OK TRUE) |
| 125 |
endif() |
| 126 |
mark_as_advanced(PARMETIS_VERSION_OK) |
| 127 |
|
| 128 |
# Build and run test program |
| 129 |
include(CheckCXXSourceRuns) |
| 130 |
check_cxx_source_runs(" |
| 131 |
#define MPICH_IGNORE_CXX_SEEK 1 |
| 132 |
#include <mpi.h> |
| 133 |
#include <parmetis.h> |
| 134 |
|
| 135 |
int main() |
| 136 |
{ |
| 137 |
// FIXME: Find a simple but sensible test for ParMETIS |
| 138 |
|
| 139 |
return 0; |
| 140 |
} |
| 141 |
" PARMETIS_TEST_RUNS) |
| 142 |
|
| 143 |
endif() |
| 144 |
endif() |
| 145 |
|
| 146 |
# Standard package handling |
| 147 |
find_package_handle_standard_args(ParMETIS |
| 148 |
"ParMETIS could not be found/configured." |
| 149 |
PARMETIS_LIBRARIES |
| 150 |
PARMETIS_TEST_RUNS |
| 151 |
PARMETIS_INCLUDE_DIRS |
| 152 |
PARMETIS_VERSION |
| 153 |
PARMETIS_VERSION_OK) |