|
| 1 | +# Copyright (C) 2025 Scientific Computation Research Center |
| 2 | +# |
| 3 | +# This work is open source software, licensed under the terms of the |
| 4 | +# BSD license as described in the LICENSE file in the top-level directory. |
| 5 | +# |
| 6 | +#[====================================[ |
| 7 | +FindMETIS.cmake |
| 8 | +
|
| 9 | +Hints: |
| 10 | +- `METIS_PREFIX`: The prefix for the METIS installation. |
| 11 | +
|
| 12 | +Once done this will define: |
| 13 | +- `METIS_FOUND`: True if METIS is found. |
| 14 | +- `METIS::METIS`: The IMPORTED library if found. |
| 15 | +- `METIS_LIBRARIES`: METIS libraries required for linking. |
| 16 | +- `METIS_INCLUDE_DIRS`: Directories containing METIS headers. |
| 17 | +]====================================] |
| 18 | + |
| 19 | +cmake_policy(PUSH) |
| 20 | + |
| 21 | +set(METIS_PREFIX "${Trilinos_PREFIX}" CACHE STRING "METIS install directory") |
| 22 | +find_path(METIS_INCLUDE_DIR metis.h HINTS "${METIS_PREFIX}/include") |
| 23 | +set(METIS_INCLUDE_DIRS ${METIS_INCLUDE_DIR}) |
| 24 | +file(STRINGS "${METIS_INCLUDE_DIR}/metis.h" _METIS_VERSION_STRS |
| 25 | + REGEX "#define METIS_VER_(MAJOR|(SUB)?MINOR)" |
| 26 | +) |
| 27 | +set(METIS_VERSION_STR "") |
| 28 | +foreach(ver_comp IN LISTS _METIS_VERSION_STRS) |
| 29 | + if(METIS_VERSION_STR) |
| 30 | + string(APPEND METIS_VERSION_STR .) |
| 31 | + endif() |
| 32 | + string(REGEX REPLACE |
| 33 | + "^#define METIS_VER_(MAJOR|(SUB)?MINOR)[ \t]+" "" |
| 34 | + comp_num "${ver_comp}" |
| 35 | + ) |
| 36 | + string(APPEND METIS_VERSION_STR "${comp_num}") |
| 37 | +endforeach() |
| 38 | +find_library(METIS_LIBRARY metis HINTS "${METIS_PREFIX}/lib") |
| 39 | +# Add imported library. |
| 40 | +add_library(METIS::METIS UNKNOWN IMPORTED) |
| 41 | +set_target_properties(METIS::METIS PROPERTIES |
| 42 | + INTERFACE_INCLUDE_DIRECTORIES "${METIS_INCLUDE_DIR}" |
| 43 | + IMPORTED_LINK_INTERFACE_LANGUAGE "C;CXX" |
| 44 | + IMPORTED_LOCATION "${METIS_LIBRARY}" |
| 45 | +) |
| 46 | +# Sometimes GKLib is an external dependency; usually it is in METIS itself. |
| 47 | +find_library(GK_LIBRARY GKlib HINTS "${METIS_PREFIX}/lib") |
| 48 | +if(EXISTS "${GK_LIBRARY}") |
| 49 | + set_target_property(METIS::METIS PROPERTIES |
| 50 | + INTERFACE_LINK_LIBRARIES "${GK_LIBRARY}" |
| 51 | + ) |
| 52 | + set(METIS_LIBRARIES "${METIS_LIBRARY}" "${GK_LIBRARY}") |
| 53 | +else() |
| 54 | + set(METIS_LIBRARIES "${METIS_LIBRARY}") |
| 55 | +endif() |
| 56 | +include(FindPackageHandleStandardArgs) |
| 57 | +find_package_handle_standard_args(METIS |
| 58 | + REQUIRED_VARS METIS_INCLUDE_DIR METIS_LIBRARY |
| 59 | + VERSION_VAR METIS_VERSION_STR |
| 60 | +) |
| 61 | +mark_as_advanced(METIS_INCLUDE_DIR METIS_LIBRARY) |
| 62 | +cmake_policy(POP) |
0 commit comments