-
Notifications
You must be signed in to change notification settings - Fork 7
/
FindPETSc.cmake
166 lines (153 loc) · 6.29 KB
/
FindPETSc.cmake
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#################################################################
# Try to find PETSc #
# #
# Once done this will define: #
# PETSC_FOUND - system has PETSc #
# PETSC_DIR - PETSc directory #
# PETSC_ARCH - PETSc architecture #
# PETSC_INC - PETSc include directory #
# PETSC_LIB - PETSc library (static or dynamic) #
# PETSC_VARIABLES - Content of PETSc 'petscvariables' file #
# #
# PETSC_MUMPS - Was PETSc compiled with MUMPS? #
# PETSC_MUMPS_INC - PETSc MUMPS include file #
# PETSC_MUMPS_LIB - PETSc MUMPS libraries #
# #
# PETSC_SCALAPACK - Was PETSc compiled with ScaLAPACK? #
# PETSC_SCALAPACK_LIB - PETSc ScaLAPACK libraries #
# #
# PETSC_PARMETIS - Was PETSc compiled with ParMETIS? #
# PETSC_PARMETIS_LIB - PETSc ParMETIS libraries #
# #
# PETSC_METIS - Was PETSc compiled with Metis? #
# PETSC_METIS_LIB - PETSc METIS libraries #
# #
# PETSC_MPIUNI - Was PETSc compiled with MPIUNI? #
# PETSC_MPIUNI_INC - MPIUNI include file #
# #
# Usage: #
# find_package(PETSc) #
# #
# Setting these changes the behavior of the search #
# PETSC_DIR - PETSc directory #
# PETSC_ARCH - PETSc architecture #
#################################################################
## Try to set PETSC_DIR and PETSC_ARCH ##
#########################################
if(NOT DEFINED PETSC_DIR)
set(PETSC_DIR $ENV{PETSC_DIR})
endif()
if(NOT DEFINED PETSC_ARCH)
set(PETSC_ARCH $ENV{PETSC_ARCH})
endif()
## Includes ##
##############
if(EXISTS "${PETSC_DIR}/include" AND
EXISTS "${PETSC_DIR}/${PETSC_ARCH}/include")
set(PETSC_INC "${PETSC_DIR}/include" "${PETSC_DIR}/${PETSC_ARCH}/include")
else()
message(SEND_ERROR "PETSc includes not found")
endif()
## Library ##
#############
if(EXISTS "${PETSC_DIR}/${PETSC_ARCH}/lib/libpetsc.so")
set(PETSC_LIB "${PETSC_DIR}/${PETSC_ARCH}/lib/libpetsc.so")
elseif(EXISTS "${PETSC_DIR}/${PETSC_ARCH}/lib/libpetsc.a")
set(PETSC_LIB "${PETSC_DIR}/${PETSC_ARCH}/lib/libpetsc.a")
elseif(EXISTS "${PETSC_DIR}/${PETSC_ARCH}/lib/libpetsc.dylib")
set(PETSC_LIB "${PETSC_DIR}/${PETSC_ARCH}/lib/libpetsc.dylib")
else()
message(SEND_ERROR "PETSc library not found")
endif()
## PETSc variables ##
#####################
if(EXISTS ${PETSC_DIR}/${PETSC_ARCH}/conf/petscvariables)
file(STRINGS ${PETSC_DIR}/${PETSC_ARCH}/conf/petscvariables
PETSC_VARIABLES NEWLINE_CONSUME)
elseif(EXISTS ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/petscvariables)
file(STRINGS ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/petscvariables
PETSC_VARIABLES NEWLINE_CONSUME)
else()
message(SEND_ERROR "PETSc variables not found")
endif()
## MUMPS ##
###########
if(EXISTS ${PETSC_DIR}/${PETSC_ARCH}/lib/libmumps_common.a)
set(PETSC_MUMPS TRUE)
set(PETSC_MUMPS_INC ${PETSC_INC})
set(PETSC_MUMPS_LIB
${PETSC_DIR}/${PETSC_ARCH}/lib/libcmumps.a
${PETSC_DIR}/${PETSC_ARCH}/lib/libdmumps.a
${PETSC_DIR}/${PETSC_ARCH}/lib/libsmumps.a
${PETSC_DIR}/${PETSC_ARCH}/lib/libzmumps.a
${PETSC_DIR}/${PETSC_ARCH}/lib/libmumps_common.a
${PETSC_DIR}/${PETSC_ARCH}/lib/libpord.a)
if(EXISTS ${PETSC_DIR}/${PETSC_ARCH}/lib/libmpiseq.a)
set(PETSC_MUMPS_SEQ ${PETSC_DIR}/${PETSC_ARCH}/lib/libmpiseq.a)
else()
set(PETSC_MUMPS_SEQ "")
endif()
else()
set(PETSC_MUMPS FALSE)
set(PETSC_MUMPS_INC "")
set(PETSC_MUMPS_LIB "")
set(PETSC_MUMPS_SEQ "")
endif()
## ScaLAPACK ##
###############
if(EXISTS ${PETSC_DIR}/${PETSC_ARCH}/lib/libscalapack.a)
set(PETSC_SCALAPACK TRUE)
set(PETSC_SCALAPACK_LIB ${PETSC_DIR}/${PETSC_ARCH}/lib/libscalapack.a)
else()
set(PETSC_SCALAPACK FALSE)
set(PETSC_SCALAPACK_LIB "")
endif()
## ParMETIS ##
##############
if(EXISTS ${PETSC_DIR}/${PETSC_ARCH}/lib/libparmetis.so)
set(PETSC_PARMETIS TRUE)
set(PETSC_PARMETIS_LIB ${PETSC_DIR}/${PETSC_ARCH}/lib/libparmetis.so)
elseif(EXISTS ${PETSC_DIR}/${PETSC_ARCH}/lib/libparmetis.dylib)
set(PETSC_PARMETIS TRUE)
set(PETSC_PARMETIS_LIB ${PETSC_DIR}/${PETSC_ARCH}/lib/libparmetis.dylib)
else()
set(PETSC_PARMETIS FALSE)
set(PETSC_PARMETIS_LIB "")
endif()
## METIS ##
############
if(EXISTS ${PETSC_DIR}/${PETSC_ARCH}/lib/libmetis.so)
set(PETSC_METIS TRUE)
set(PETSC_METIS_LIB ${PETSC_DIR}/${PETSC_ARCH}/lib/libmetis.so)
elseif(EXISTS ${PETSC_DIR}/${PETSC_ARCH}/lib/libmetis.dylib)
set(PETSC_METIS TRUE)
set(PETSC_METIS_LIB ${PETSC_DIR}/${PETSC_ARCH}/lib/libmetis.dylib)
else()
set(PETSC_METIS FALSE)
set(PETSC_METIS_LIB "")
endif()
## MPIUNI ##
############
string(REGEX MATCH "MPI_IS_MPIUNI = [^\n\r]*" PETSC_MPIUNI ${PETSC_VARIABLES})
if(PETSC_MPIUNI)
string(REPLACE "MPI_IS_MPIUNI = " "" PETSC_MPIUNI ${PETSC_MPIUNI})
string(STRIP ${PETSC_MPIUNI} PETSC_MPIUNI)
string(COMPARE EQUAL ${PETSC_MPIUNI} "1" PETSC_MPIUNI)
string(REGEX MATCH "MPI_INCLUDE = -I[^\n\r]*"
PETSC_MPIUNI_INC ${PETSC_VARIABLES})
if(${PETSC_MPIUNI_INC})
string(REPLACE "MPI_INCLUDE = -I" "" PETSC_MPIUNI_INC ${PETSC_MPIUNI_INC})
string(STRIP ${PETSC_MPIUNI_INC} PETSC_MPIUNI_INC)
else()
set(PETSC_MPIUNI_INC "${PETSC_DIR}/include/petsc/mpiuni") ## Default path?
endif()
else()
set(PETSC_MPIUNI FALSE)
set(PETSC_MPIUNI_INC "")
endif()
## CMake check and done ##
##########################
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PETSc
"PETSc could not be found: be sure to set PETSC_DIR and PETSC_ARCH in your environment variables"
PETSC_LIB PETSC_INC PETSC_DIR PETSC_ARCH)