FindHYPRE.cmake 1.75 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# FindHYPRE.cmake
#
# Finds the HYPRE library
#
# This will define the following variables
#
#    HYPRE_FOUND
#    HYPRE_INCLUDE_DIR
#    HYPRE_LIBRARIES
#
# and the following imported targets
#
#     HYPRE::HYPRE
#
# Author: Simon Praetorius <simon.praetorius@tu-dresden.de>


find_path(HYPRE_INCLUDE_DIR HYPRE.h
  PATHS
Praetorius, Simon's avatar
Praetorius, Simon committed
20 21
    /opt/software
    ${HYPRE_DIR} ENV HYPRE_DIR
22 23
    ENV EBROOTHYPRE
  PATH_SUFFIXES
Praetorius, Simon's avatar
Praetorius, Simon committed
24
    hypre)
25 26 27

find_library(HYPRE_LIBRARY HYPRE
  PATHS
Praetorius, Simon's avatar
Praetorius, Simon committed
28 29
    /opt/software
    ${HYPRE_DIR} ENV HYPRE_DIR
30 31
    ENV EBROOTHYPRE
  PATH_SUFFIXES
Praetorius, Simon's avatar
Praetorius, Simon committed
32
    hypre)
33 34 35 36 37

if (HYPRE_LIBRARY)
  set(HYPRE_LIBRARIES ${HYPRE_LIBRARY})
  get_filename_component(HYPRE_LIBRARY_DIR ${HYPRE_LIBRARY} DIRECTORY)

Praetorius, Simon's avatar
Praetorius, Simon committed
38 39 40 41 42 43 44 45
  file(GLOB HYPRE_LIB_NAMES LIST_DIRECTORIES false RELATIVE ${HYPRE_LIBRARY_DIR} "${HYPRE_LIBRARY_DIR}/*HYPRE_*.*")
  foreach(_lib_name_long ${HYPRE_LIB_NAMES})
    string(REGEX REPLACE "^(lib)?HYPRE_([a-zA-Z_]+)([0-9.-]*)[.][a-zA-Z]+$" "\\2" _lib_name "${_lib_name_long}")
    set(LIB_VAR "_lib_${_lib_name}")
    find_library(${LIB_VAR} "HYPRE_${_lib_name}" HINTS ${HYPRE_LIBRARY_DIR} NO_DEFAULT_PATH)
    if (${LIB_VAR})
      list(APPEND HYPRE_LIBRARIES ${${LIB_VAR}})
    endif ()
46 47 48
  endforeach()
endif (HYPRE_LIBRARY)

Praetorius, Simon's avatar
Praetorius, Simon committed
49 50
mark_as_advanced(HYPRE_FOUND HYPRE_INCLUDE_DIR HYPRE_LIBRARIES)

51 52
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(HYPRE
Praetorius, Simon's avatar
Praetorius, Simon committed
53 54
  REQUIRED_VARS
    HYPRE_INCLUDE_DIR HYPRE_LIBRARIES
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
)

# text for feature summary
set_package_properties("HYPRE" PROPERTIES
  DESCRIPTION "high performance preconditioners")


if(HYPRE_FOUND AND NOT TARGET HYPRE::HYPRE)
  add_library(HYPRE::HYPRE INTERFACE IMPORTED)

  set_target_properties(HYPRE::HYPRE PROPERTIES
    INTERFACE_INCLUDE_DIRECTORIES "${HYPRE_INCLUDE_DIR}"
    INTERFACE_LINK_LIBRARIES "${HYPRE_LIBRARIES}"
  )
endif()