forked from jlblancoc/suitesparse-metis-for-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUseSuiteSparseForInstall.cmake.in
104 lines (87 loc) · 5.25 KB
/
UseSuiteSparseForInstall.cmake.in
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
## Generated by CMAKE from UseSuiteSparseForInstall.cmake.in file !!
##
## UseSuiteSparse.cmake is included by the SuiteSparseConfig.cmake from the install dir.
## It allow to find SuiteSparse for another project.
## When find_package(SuiteSparse) is used in another project,
## SuiteSparseConfig.cmake is found from the SuiteSparse_DIR (the install dir).
##
## This file do some things for you (and according metis is build or not):
## * he set the link_directories (with SuiteSparse_LIB_DIRS) where we can find all libraries
## * he set the include_directories (with SuiteSparse_INCLUDE_DIRS) where we can find all headers files
##
## This file provide :
## * The name of the SuiteSparse targets as IMPORTED (so you can use directly the name of the target for target_link_libraries(...))
## * SuiteSparse_LIBRARIES : an "all in one" help cmake variable, which contain all libraries for use SuiteSparse for target_link_libraries(...)
## On windows:
## * SuiteSparse_LAPACK_BLAS_LIBRARIES: which contain the libblas and liblapack libraries
## * SuiteSparse_LAPACK_BLAS_DLL : which contain all requiered binaries for use libblas and liblapack
##
## OPT (win): Given the cmake flag : set(SuiteSparse_USE_LAPACK_BLAS ON)
## before using the Find_package(SuiteSparse) instruction,
## will set (for windows only) the link for liblapack and libblas
##
## Created by jesnault (jerome.esnault@inria.fr) 2014-01-21
## Updated by jesnault (jerome.esnault@inria.fr) 2014-01-21
## get the root path (install dir)
get_filename_component(SuiteSparse_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
## libs
set(SuiteSparse_LIBRARIES "")
set(SuiteSparse_LIB_DIR "${SuiteSparse_DIR}/lib@LIB_POSTFIX@")
if(WIN32 AND SuiteSparse_USE_LAPACK_BLAS)
set(SuiteSparse_LAPACK_BLAS_LIB_DIR "${SuiteSparse_DIR}/@SuiteSparse_LAPACK_BLAS_LIB_DIR@")
file(GLOB SuiteSparse_LAPACK_BLAS_LIBRARIES "${SuiteSparse_LAPACK_BLAS_LIB_DIR}/*.lib")
file(GLOB SuiteSparse_LAPACK_BLAS_DLL "${SuiteSparse_LAPACK_BLAS_LIB_DIR}/*.dll")
if(SuiteSparse_LAPACK_BLAS_LIBRARIES AND SuiteSparse_LAPACK_BLAS_DLL)
add_library(blas SHARED IMPORTED)
set_property(TARGET blas PROPERTY IMPORTED_LOCATION "${SuiteSparse_LAPACK_BLAS_LIB_DIR}/libblas.dll")
set_property(TARGET blas PROPERTY IMPORTED_IMPLIB "${SuiteSparse_LAPACK_BLAS_LIB_DIR}/libblas.lib")
add_library(lapack SHARED IMPORTED)
set_property(TARGET lapack PROPERTY IMPORTED_LOCATION "${SuiteSparse_LAPACK_BLAS_LIB_DIR}/liblapack.dll")
set_property(TARGET lapack PROPERTY IMPORTED_IMPLIB "${SuiteSparse_LAPACK_BLAS_LIB_DIR}/liblapack.lib")
list(APPEND SuiteSparse_LIBRARIES blas lapack)
endif()
else()
set(SuiteSparse_LAPACK_BLAS_LIB_DIR "")
endif()
set(SuiteSparse_LIB_DIRS "${SuiteSparse_LIB_DIR}" "${SuiteSparse_LAPACK_BLAS_LIB_DIR}")
link_directories(${SuiteSparse_LIB_DIRS})
set(SuiteSparse_CMAKE_CONFIG "${SuiteSparse_DIR}/cmake/SuiteSparse-config@LIB_POSTFIX@.cmake")
if(EXISTS "${SuiteSparse_CMAKE_CONFIG}")
## From SuiteSparse project => the install EXPORT cmd => cmake provide all imported target
include(${SuiteSparse_CMAKE_CONFIG})
## libs (get from the export cmake file) => in order to fill the SuiteSparse_LIBRARIES
file(READ "${SuiteSparse_CMAKE_CONFIG}" SuiteSparseConfigContent)
STRING(REGEX REPLACE "\r?\n" ";" SuiteSparseConfigContent "${SuiteSparseConfigContent}")
foreach(line ${SuiteSparseConfigContent})
string(REGEX MATCH "ADD_LIBRARY\\(.* SHARED IMPORTED" sharedMatchedUC ${line})
string(REGEX MATCH "add_library\\(.* SHARED IMPORTED" sharedMatched ${line})
if( sharedMatchedUC )
string(REGEX REPLACE "ADD_LIBRARY\\((.*) SHARED IMPORTED" "\\1" libName ${sharedMatchedUC})
list(APPEND SuiteSparse_LIBRARIES ${libName}) # the final cmake variable other project can use
elseif( sharedMatched )
string(REGEX REPLACE "add_library\\((.*) SHARED IMPORTED" "\\1" libName ${sharedMatched})
list(APPEND SuiteSparse_LIBRARIES ${libName}) # the final cmake variable other project can use
endif()
string(REGEX MATCH "ADD_LIBRARY\\(.* STATIC IMPORTED" staticMatchedUC ${line})
string(REGEX MATCH "add_library\\(.* STATIC IMPORTED" staticMatched ${line})
if( staticMatchedUC )
string(REGEX REPLACE "ADD_LIBRARY\\((.*) STATIC IMPORTED" "\\1" libName ${staticMatchedUC})
list(APPEND SuiteSparse_LIBRARIES ${libName}) # the final cmake variable other project can use
elseif( staticMatched )
string(REGEX REPLACE "add_library\\((.*) STATIC IMPORTED" "\\1" libName ${staticMatched})
list(APPEND SuiteSparse_LIBRARIES ${libName}) # the final cmake variable other project can use
endif()
endforeach()
else()
message(WARNING "${SuiteSparse_CMAKE_CONFIG} not found...\n Can't fill SuiteSparse_LIBRARIES...\n set SuiteSparse_DIR cmake variable to the dir we can find this file.")
endif()
## include (get from the install of the public headers)
if("@BUILD_METIS@" STREQUAL "ON") # BUILD_METIS?
set(SuiteSparse_METIS_INCLUDE_DIR "${SuiteSparse_DIR}/include")
ADD_DEFINITIONS(-DNPARTITION)
else()
set(SuiteSparse_METIS_INCLUDE_DIR "")
endif()
set(SuiteSparse_INCLUDE_DIR "${SuiteSparse_DIR}/include/suitesparse")
set(SuiteSparse_INCLUDE_DIRS "${SuiteSparse_INCLUDE_DIR}" "${SuiteSparse_METIS_INCLUDE_DIR}")
include_directories(${SuiteSparse_INCLUDE_DIRS})