parse_zoltan_makefile.cmake 1.73 KB
Newer Older
1
macro(parse_zoltan_makefile _FILE_ _TARGET_ _SCOPE_)
2
3
4
5
  
  # parse zoltan extra libs AND ld flags
  file(STRINGS ${_FILE_} ZOLTAN_EXTRA_LIBS_LINE REGEX "ZOLTAN_EXTRA_LIBS")
  file(STRINGS ${_FILE_} ZOLTAN_LDFLAGS_LINE REGEX "ZOLTAN_LDFLAGS")
6
  get_filename_component(ZOLTAN_MAKEFILE_DIR "${ZOLTAN_MAKEFILE}" PATH CACHE)
7
8
9
10
  
  string(STRIP "${ZOLTAN_EXTRA_LIBS_LINE}" ZOLTAN_EXTRA_LIBS_LINE)
  string(STRIP "${ZOLTAN_LDFLAGS_LINE}" ZOLTAN_LDFLAGS_LINE)
  if ("${ZOLTAN_EXTRA_LIBS_LINE}" MATCHES "^ZOLTAN_EXTRA_LIBS[ ]*=[ ]*([a-zA-Z0-9_/. -]+)*$")
11
    string(REGEX REPLACE " " ";" ZOLTAN_EXTRA_LIBS_LIST "${CMAKE_MATCH_1}")
12
13
14
    if ("${ZOLTAN_LDFLAGS_LINE}" MATCHES "^ZOLTAN_LDFLAGS[ ]*=[ ]*([a-zA-Z0-9_/. -]+)*$")
      string(REGEX REPLACE " " ";" ZOLTAN_LDFLAGS_LIST "${CMAKE_MATCH_1}")
      set(COMBINED_LIST ${ZOLTAN_LDFLAGS_LIST} ${ZOLTAN_EXTRA_LIBS_LIST})
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
      set(ZOLTAN_LIB_DIRS "")
      foreach(LIBS ${COMBINED_LIST})
        string(STRIP "${LIBS}" LIBS)
        string(SUBSTRING "${LIBS}" 0 2 LIB_PREFIX)
        string(SUBSTRING "${LIBS}" 2 -1 LIB_NAME)
        if ("${LIB_PREFIX}" STREQUAL "-L")
          list(APPEND ZOLTAN_LIB_DIRS ${LIB_NAME})
        elseif ("${LIB_PREFIX}" STREQUAL "-l")
          find_library(_ZOLTAN_EXTERN_LIB ${LIB_NAME} HINTS ${ZOLTAN_LIB_DIRS})
          if (NOT _ZOLTAN_EXTERN_LIB)
            message(FATAL_ERROR "Could not find library \"${LIB_NAME}\" in directories ${ZOLTAN_LIB_DIRS}!")
          else ()
            target_link_libraries(${_TARGET_} ${_SCOPE_} ${_ZOLTAN_EXTERN_LIB})
          endif ()
          unset(_ZOLTAN_EXTERN_LIB CACHE)
31
        else ()
32
          message(WARNING "Unknown link parameter \"${LIBS}\"")
33
        endif ()
34
35
      endforeach (LIBS)
    endif()
36
37
  endif()
endmacro(parse_zoltan_makefile)
38