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

8
9
10
    if (WIN32)
        set(SuiteSparse_USE_LAPACK_BLAS ON)
    endif (WIN32)
11
12

    if (SuiteSparse_DIR)
13
       file(TO_CMAKE_PATH ${SuiteSparse_DIR} SuiteSparse_DIR)
14
15
    endif (SuiteSparse_DIR)

16
17
18
    # try to use a cmake-package of suitesparse
    find_package(SuiteSparse QUIET HINTS ${AMDIS_SuiteSparse_DIR})
    if (SuiteSparse_FOUND)
19
        message(STATUS "Found SuiteSparse CMake-library")
20
        include(${USE_SuiteSparse})
21
        if (LINK_EXECUTABLE OR APPLE)
22
          target_link_libraries(${_TARGET_} ${_SCOPE_} ${SuiteSparse_LIBRARIES})
23
        endif (LINK_EXECUTABLE OR APPLE)
24
        target_include_directories(${_TARGET_} ${_SCOPE_} ${SuiteSparse_INCLUDE_DIR} ${SuiteSparse_METIS_INCLUDE_DIR})
25
26
27
        set(FOUND_SUITESPARSE_LIBS ${SuiteSparse_LIBRARIES})
    else (SuiteSparse_FOUND)
        # find umfpack manually by searching for umfpack.h header file
28
        find_library(UMFPACK_LIBRARY umfpack
29
30
31
          HINTS ${AMDIS_UMFPACK_ROOT_DIR}
          PATHS $ENV{EBROOTSUITESPARSE}
          PATH_SUFFIXES lib/ lib64/
32
	        DOC "Library file for UMFPACK")
33
        find_file(UMFPACK_H umfpack.h
34
35
          HINTS ${AMDIS_UMFPACK_ROOT_DIR}/include
          PATHS /usr/include/suitesparse /usr/include/ufsparse $ENV{EBROOTSUITESPARSE}/include
36
	        DOC "Headerfile umfpack.h for UMFPACK")
37

38
39
        if (UMFPACK_H AND UMFPACK_LIBRARY)
            get_filename_component(UMFPACK_PATH ${UMFPACK_H} PATH)
40
41
            target_include_directories(${_TARGET_} ${_SCOPE_} ${UMFPACK_PATH})

42
43
            get_filename_component(UMFPACK_LIB_PATH ${UMFPACK_LIBRARY} PATH)
            set(FOUND_SUITESPARSE_LIBS ${UMFPACK_LIBRARY})
44

45
46
47
48
49
50
            # extract root directory from umfpack lib dir
            set (UMFPACK_ROOT_DIR ${UMFPACK_LIB_PATH}/..)
            if (NOT EXISTS ${UMFPACK_ROOT_DIR}/include)
              message(WARNING "directory ${UMFPACK_ROOT_DIR} is not a valid root dir of an umfpack installation.")
            endif ()

51
            if (LINK_EXECUTABLE OR APPLE)
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

              # find all connected libraries
              find_library(AMD_LIBRARY amd HINTS ${UMFPACK_LIB_PATH})

              find_library(BLAS_LIB
                NAMES blas fblas openblas
                HINTS ${BLAS_DIR}/lib ${UMFPACK_LIB_PATH} /usr/lib/openblas-base /usr/lib/atlas-base)
              if (BLAS_LIB)
                set(BLAS_LIBRARIES ${BLAS_LIB})
              else (BLAS_LIB)
                find_package(BLAS REQUIRED)
              endif (BLAS_LIB)

              find_library(CHOLMOD_LIBRARY cholmod HINTS ${UMFPACK_LIB_PATH})
              find_library(COLAMD_LIBRARY colamd HINTS ${UMFPACK_LIB_PATH})
              find_library(SUITESPARSECONFIG_LIBRARY suitesparseconfig HINTS ${UMFPACK_LIB_PATH})
              if (AMD_LIBRARY AND BLAS_LIBRARIES)
                  list(APPEND FOUND_SUITESPARSE_LIBS ${AMD_LIBRARY} ${BLAS_LIBRARIES})
              endif (AMD_LIBRARY AND BLAS_LIBRARIES)
              if (CHOLMOD_LIBRARY)
                  list(APPEND FOUND_SUITESPARSE_LIBS ${CHOLMOD_LIBRARY})
              endif (CHOLMOD_LIBRARY)
              if (COLAMD_LIBRARY)
                  list(APPEND FOUND_SUITESPARSE_LIBS ${COLAMD_LIBRARY})
              endif (COLAMD_LIBRARY)
              if (SUITESPARSECONFIG_LIBRARY)
                  list(APPEND FOUND_SUITESPARSE_LIBS ${SUITESPARSECONFIG_LIBRARY})
              endif (SUITESPARSECONFIG_LIBRARY)

81
              target_link_libraries(${_TARGET_} ${_SCOPE_} ${FOUND_SUITESPARSE_LIBS})
82
            endif (LINK_EXECUTABLE OR APPLE)
83
        else()
84
85
86
87
88
89
            if (NOT UMFPACK_H)
              message(FATAL_ERROR "Could not find the UMFPACK header umfpack.h.")
            endif ()
            if (NOT UMFPACK_LIBRARY)
              message(FATAL_ERROR "Could not find the UMFPACK library libumfpack.so")
            endif ()
90
91
92
93
94
        endif (UMFPACK_H AND UMFPACK_LIBRARY)
    endif (SuiteSparse_FOUND)


    # Check for clock_gettime in librt
95
    if (NOT WIN32 AND (LINK_EXECUTABLE OR APPLE))
96
97
98
99
100
101
102
      include(CheckLibraryExists)
      check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
      if (HAVE_CLOCK_GETTIME)
          target_link_libraries(${_TARGET_} ${_SCOPE_} rt)
      else ()
          check_library_exists(c clock_gettime "" HAVE_CLOCK_GETTIME)
      endif (HAVE_CLOCK_GETTIME)
103
    endif (NOT WIN32 AND (LINK_EXECUTABLE OR APPLE))
104

105

106
107
    # collect informations about umfpack version and found libraries
    if (FOUND_SUITESPARSE_LIBS)
108
        find_file(_UMFPACK_H umfpack.h PATHS ${SuiteSparse_INCLUDE_DIR} ${UMFPACK_PATH} NO_DEFAULT_PATH)
109
110
111
        file(STRINGS ${_UMFPACK_H} UMFPACK_VERSION_LINE REGEX "#define UMFPACK_VERSION")
        string(REGEX MATCH "\"UMFPACK V?([^\"]+)\"" UMFPACK_VERSION_REGEX ${UMFPACK_VERSION_LINE})
        set(UMFPACK_VERSION ${CMAKE_MATCH_1})
112
113
        unset(_UMFPACK_H CACHE)

114
        message(STATUS "UMFPACK version: ${UMFPACK_VERSION}")
115
        if (LINK_EXECUTABLE OR APPLE)
116
117
118
119
          message(STATUS "Found the following SuiteSparse libraries:")
          foreach (lib ${FOUND_SUITESPARSE_LIBS})
              message(STATUS "  ${lib}")
          endforeach ()
120
        endif (LINK_EXECUTABLE OR APPLE)
121
    endif (FOUND_SUITESPARSE_LIBS)
122

123
    target_compile_definitions(${_TARGET_} ${_SCOPE_}
124
125
126
        HAVE_UMFPACK=1
        MTL_HAS_UMFPACK=1)

127
endmacro(target_enable_umfpack)