target_enable_zoltan.cmake 2.49 KB
Newer Older
1
include(parse_zoltan_makefile)
2 3
macro(target_enable_zoltan _TARGET_ _SCOPE_)
    if (${ARGC} GREATER 2)
4 5 6 7
      set(LINK_EXECUTABLE ON)
    else ()
      set(LINK_EXECUTABLE OFF)
    endif ()
8

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
    find_package(Zoltan QUIET)
    if (Zoltan_FOUND)
      find_file(ZOLTAN_HEADER_FILE "zoltan.h" PATHS ${Zoltan_INCLUDE_DIRS})
      target_include_directories(${_TARGET_} ${_SCOPE_} ${Zoltan_INCLUDE_DIRS})

      if (LINK_EXECUTABLE)
        foreach (LIB_NAME ${Zoltan_LIBRARIES})
          find_library(_ZOLTAN_LIB ${LIB_NAME} HINTS ${Zoltan_LIBRARY_DIRS})
          if (NOT _ZOLTAN_LIB)
            message(FATAL_ERROR "Could not find library \"${LIB_NAME}\" in directories ${Zoltan_LIBRARY_DIRS}!")
          else ()
            target_link_libraries(${_TARGET_} ${_SCOPE_} ${_ZOLTAN_LIB})
          endif ()
          unset(_ZOLTAN_LIB CACHE)
        endforeach(LIB_NAME)
      endif (LINK_EXECUTABLE)
    else (Zoltan_FOUND)
      find_file(ZOLTAN_HEADER_FILE "zoltan.h" HINTS ${ZOLTAN_DIR}/include ${PETSC_INCLUDE_DIRS})
      if (ZOLTAN_HEADER_FILE)
        get_filename_component(Zoltan_INCLUDE_DIR "${ZOLTAN_HEADER_FILE}" PATH CACHE)
        target_include_directories(${_TARGET_} ${_SCOPE_} ${Zoltan_INCLUDE_DIR})
      else()
        message(FATAL_ERROR "Could not find Zoltan include file 'zoltan.h'!")
      endif(ZOLTAN_HEADER_FILE)

      if (LINK_EXECUTABLE)
        find_library(ZOLTAN_LIB zoltan
          HINTS ${Zoltan_INCLUDE_DIR}/../lib DOC "Full path to the zoltan library")
        if (NOT ZOLTAN_LIB)
          message(FATAL_ERROR "Could not find zoltan library!")
        endif (NOT ZOLTAN_LIB)
        target_link_libraries(${_TARGET_} ${_SCOPE_} ${ZOLTAN_LIB})
41

42 43 44 45 46 47 48
        find_file(ZOLTAN_CONFIG_FILE "Makefile.export.zoltan" HINTS ${Zoltan_INCLUDE_DIR})
        if (ZOLTAN_CONFIG_FILE)
          parse_zoltan_makefile(${ZOLTAN_CONFIG_FILE} ${_TARGET_} ${_SCOPE_})
        else ()
          message(WARNING "Zoltan configuration file Makefile.export.zoltan not found!")
        endif ()
      endif (LINK_EXECUTABLE)
49

50 51 52 53 54 55 56 57 58 59
      target_compile_definitions(${_TARGET_} ${_SCOPE_} HAVE_ZOLTAN=1)
    endif (Zoltan_FOUND)

    if (ZOLTAN_HEADER_FILE)
      file(STRINGS ${ZOLTAN_HEADER_FILE} ZOLTAN_VERSION_LINE REGEX "#define ZOLTAN_VERSION_NUMBER")
      string(REGEX MATCH "([0-9]+[.][0-9]+)" ZOLTAN_VERSION_REGEX ${ZOLTAN_VERSION_LINE})
      set(ZOLTAN_VERSION ${CMAKE_MATCH_1})
      unset(ZOLTAN_HEADER_FILE CACHE)
      message(STATUS "Zoltan version: ${ZOLTAN_VERSION}")
    endif (ZOLTAN_HEADER_FILE)
60
endmacro(target_enable_zoltan)