target_enable_hypre.cmake 1.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
macro(target_enable_hypre _TARGET_ _SCOPE_)
    if (${ARGC} GREATER 2)
      set(LINK_EXECUTABLE ON)
    else ()
      set(LINK_EXECUTABLE OFF)
    endif ()

    # MPI is required
    if (LINK_EXECUTABLE)
      target_enable_mpi(${_TARGET_} ${_SCOPE_} ON)
    else ()
      target_enable_mpi(${_TARGET_} ${_SCOPE_})
    endif (LINK_EXECUTABLE)


    find_file(_HYPRE_H HYPRE.h
      HINTS ${PETSC_INCLUDE_DIRS})

    if (_HYPRE_H)
Praetorius, Simon's avatar
Praetorius, Simon committed
20
      get_filename_component(HYPRE_INCLUDE_DIRECTORIES ${_HYPRE_H} PATH)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
      target_include_directories(${_TARGET_} ${_SCOPE_} ${HYPRE_INCLUDE_DIRECTORIES})
    endif (_HYPRE_H)

    if (LINK_EXECUTABLE)
      find_library(_HYPRE_LIB HYPRE
        HINTS ${PETSC_LIBRARY_DIRS})

      if(_HYPRE_LIB)
        get_filename_component(HLIB_PATH ${_HYPRE_LIB} PATH)
        file(GLOB HYPRE_OTHER ${HLIB_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}HYPRE*${CMAKE_SHARED_LIBRARY_SUFFIX})
        target_link_libraries(${_TARGET_} ${_SCOPE_} ${_HYPRE_LIB} ${HYPRE_OTHER})
      endif (_HYPRE_LIB)

      # lapack library is required
      find_library(LAPACK_LIB
        NAMES lapack flapack
        HINTS ${LAPACK_DIR}/lib ${PETSC_LIBRARY_DIRS} ${PETSC_DIR}/lib)
      if (LAPACK_LIB)
        set(LAPACK_LIBRARIES ${LAPACK_LIB})
      else (LAPACK_LIB)
        find_package(LAPACK REQUIRED)
      endif (LAPACK_LIB)
      target_link_libraries(${_TARGET_} ${_SCOPE_} ${LAPACK_LIBRARIES})
    endif (LINK_EXECUTABLE)


    if (_HYPRE_H AND (NOT LINK_EXECUTABLE OR _HYPRE_LIB))
      set(HAVE_HYPRE ON)
      target_compile_definitions(${_TARGET_} ${_SCOPE_} MTL_HAS_HYPRE)
    else ()
      set(HAVE_HYPRE OFF)
    endif ()

endmacro(target_enable_hypre)