File: FindOrFetchLinalgPP.cmake

package info (click to toggle)
btas 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,132 kB
  • sloc: cpp: 26,486; ansic: 1,545; makefile: 5
file content (105 lines) | stat: -rw-r--r-- 4,177 bytes parent folder | download
1
2
3
4
5
6
7
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
41
42
43
44
45
46
47
48
49
50
51
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# BLAS++ / LAPACK++
include(CTest) # defines BUILD_TESTING option
set(OLD_BUILD_TESTING "${BUILD_TESTING}") # Save testing state
set(BUILD_TESTING OFF CACHE BOOL "Enable Testing" FORCE) # Disable LinAlgPP Testing

if (NOT TARGET blaspp)
    find_package(blaspp QUIET CONFIG)

    if (TARGET blaspp)
        message(STATUS "Found blaspp CONFIG at ${blaspp_CONFIG}")
    else (TARGET blaspp)
        cmake_minimum_required(VERSION 3.14.0)  # for FetchContent_MakeAvailable
        include(FetchContent)
        include(${CMAKE_CURRENT_LIST_DIR}/versions.cmake)
        FetchContent_Declare(blaspp
                GIT_REPOSITORY https://github.com/icl-utk-edu/blaspp.git
                GIT_TAG ${VGCMAKEKIT_TRACKED_BLASPP_TAG}
                )

        FetchContent_MakeAvailable(blaspp)

        # set blaspp_CONFIG to the install location so that we know where to find it
        set(blaspp_CONFIG ${CMAKE_INSTALL_PREFIX}/lib/blaspp/blasppConfig.cmake)
    endif (TARGET blaspp)
endif (NOT TARGET blaspp)

if (NOT TARGET lapackpp)
    find_package(OpenMP QUIET) #XXX Open LAPACKPP issue for this...
    find_package(lapackpp QUIET CONFIG)
    if (TARGET lapackpp)
        message(STATUS "Found lapackpp CONFIG at ${lapackpp_CONFIG}")
    else (TARGET lapackpp)
        cmake_minimum_required(VERSION 3.14.0)  # for FetchContent_MakeAvailable
        include(FetchContent)
        include(${CMAKE_CURRENT_LIST_DIR}/versions.cmake)
        FetchContent_Declare(lapackpp
                GIT_REPOSITORY https://github.com/icl-utk-edu/lapackpp.git
                GIT_TAG ${VGCMAKEKIT_TRACKED_LAPACKPP_TAG}
                )

        FetchContent_MakeAvailable(lapackpp)

        # set lapackpp_CONFIG to the install location so that we know where to find it
        set(lapackpp_CONFIG ${CMAKE_INSTALL_PREFIX}/lib/lapackpp/lapackppConfig.cmake)
    endif (TARGET lapackpp)
endif (NOT TARGET lapackpp)

##################### Introspect BLAS/LAPACK libs

# Check if BLAS/LAPACK is MKL
include(CheckFunctionExists)
include(CMakePushCheckState)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_LIBRARIES "${blaspp_libraries}" m)
check_function_exists(mkl_dimatcopy BLAS_IS_MKL)
cmake_pop_check_state()

# blaspp_header library is a target that permits #include'ing library-specific headers, e.g. mkl.h
if (NOT TARGET blaspp_headers)

    add_library(blaspp_headers INTERFACE)

    if (BLAS_IS_MKL)
        foreach (_lib ${blaspp_libraries})
            if (EXISTS ${_lib} AND _lib MATCHES libmkl_)
                string(REGEX REPLACE "/lib/(intel64_lin/|intel64/|)libmkl_.*" "" _mklroot "${_lib}")
            elseif (_lib MATCHES "^-L")
                string(REGEX REPLACE "^-L" "" _mklroot "${_lib}")
                string(REGEX REPLACE "/lib(/intel64_lin|/intel64|)(/|)" "" _mklroot "${_mklroot}")
            endif ()
            if (_mklroot)
                break()
            endif (_mklroot)
        endforeach ()

        set(_mkl_include)
        if (EXISTS "${_mklroot}/include")
            set(_mkl_include "${_mklroot}/include")
        elseif (EXISTS "/usr/include/mkl") # ubuntu package
            set(_mkl_include "/usr/include/mkl")
        endif ()
        if (_mkl_include AND EXISTS "${_mkl_include}")
            target_include_directories(blaspp_headers INTERFACE "${_mkl_include}")
        endif (_mkl_include AND EXISTS "${_mkl_include}")

    endif (BLAS_IS_MKL)

    # mirror blaspp: see https://github.com/icl-utk-edu/blaspp/blob/1507102eb77070bf6f786ad54c4453402eb2fa42/CMakeLists.txt#L512
    include(GNUInstallDirs)
    if (WIN32)
        set( blaspp_install_configdir "blaspp" )
    else()
        set( blaspp_install_configdir "${CMAKE_INSTALL_LIBDIR}/cmake/blaspp" )
    endif()

    install(TARGETS blaspp_headers EXPORT blaspp_headers)
    export(EXPORT blaspp_headers FILE "${PROJECT_BINARY_DIR}/blaspp_headers-targets.cmake")
    install(EXPORT blaspp_headers
            FILE "blaspp_headers-targets.cmake"
            DESTINATION "${blaspp_install_configdir}"
            )

endif (NOT TARGET blaspp_headers)

set(BUILD_TESTING "${OLD_BUILD_TESTING}" CACHE BOOL "Enable Testing" FORCE) # Potentially re-enable testing based on saved state