forked from SciFortran/SciFortran
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
298 lines (223 loc) · 8.08 KB
/
CMakeLists.txt
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
##################################################
# SCIFOR PROJECT
##################################################
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)
PROJECT(scifor Fortran)
MESSAGE(STATUS "OS: ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}")
SET(BUILD_TYPE "RELEASE" CACHE STRING "Build type")
STRING(TOUPPER "${BUILD_TYPE}" BUILD_TYPE)
MESSAGE(STATUS "BUILD_TYPE=${BUILD_TYPE}")
SET(CMAKE_BUILD_TYPE ${BUILD_TYPE} CACHE INTERNAL "Build type" FORCE)
# Add our local CMAKE modules to the module path
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
INCLUDE(${CMAKE_MODULE_PATH}/ColorsMsg.cmake)
# Set some options the user may choose
OPTION(USE_MPI "Use the MPI library for parallelization" ON)
OPTION(VERBOSE "Build a verbose Makefile" OFF)
OPTION(WITH_BLAS_LAPACK "Build using internal Blas/Lapack" OFF)
OPTION(WITH_SCALAPACK "Build ScaLapack support" ON)
IF(VERBOSE)
SET(CMAKE_VERBOSE_MAKEFILE ON)
ELSE(VERBOSE)
SET(CMAKE_VERBOSE_MAKEFILE OFF)
ENDIF(VERBOSE)
############################################################
# Look for MPI if needed
############################################################
INCLUDE(${CMAKE_MODULE_PATH}/MpiConfig.cmake)
############################################################
# Check for Blas/Lapack/ScaLapack from different sources
############################################################
# Try to find MKL: IF found use it ELSE try finding Blas/Lapack
# in the OS, ELSE using internal Blas/Lapack
IF(NOT WITH_BLAS_LAPACK)
FIND_PACKAGE(MKL QUIET)
IF(MKL_FOUND)
MESSAGE(STATUS "MKL found at: ${MKL_ROOT_DIR}")
SET(BLA_LIBRARIES ${MKL_LIBRARIES})
ELSE()
FIND_PACKAGE(BLAS QUIET)
FIND_PACKAGE(LAPACK QUIET)
IF(BLAS_FOUND AND LAPACK_FOUND)
MESSAGE(STATUS "BLAS found as: ${BLAS_LIBRARIES}")
MESSAGE(STATUS "LAPACK found as: ${LAPACK_LIBRARIES}")
SET(BLA_LIBRARIES ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
ELSE()
SET(WITH_BLAS_LAPACK "ON")
ENDIF()
ENDIF()
ENDIF()
SET(SCALAPACK_FOUND FALSE)
IF(WITH_SCALAPACK)
IF(MKL_SCALAPACK_FOUND)
MESSAGE(STATUS "MKL supports Scalapack+Blacs")
SET(SCALAPACK_FOUND TRUE)
ELSE()
FIND_PACKAGE(SCALAPACK QUIET) #TRY TO FIND SCALAPACK IN THE SYSTEM
IF(SCALAPACK_FOUND)
MESSAGE(STATUS "Scalapack found: ${SCALAPACK_LIBRARIES}")
ENDIF()
ENDIF()
ENDIF()
############################################################
# Configure Fortran Compiler Main options
############################################################
INCLUDE(${CMAKE_MODULE_PATH}/FortranCompilerConfig.cmake)
IF((WITH_SCALAPACK) AND (SCALAPACK_FOUND))
ADD_DEFINITIONS(-D_SCALAPACK)
ENDIF()
############################################################
# Check for .git and extract the current SHA1 revision.
############################################################
INCLUDE(${CMAKE_MODULE_PATH}/GitConfig.cmake)
############################################################
# Define the actual files and folders that make up the build
############################################################
INCLUDE(${CMAKE_MODULE_PATH}/MainConfig.cmake)
############################################################
############################################################
############################################################
# DEFINE HERE THE DETAILS OF THE LIBRARY CONFIGURATION
# Define some directories
SET(LIB_SRC ${CMAKE_SOURCE_DIR}/src)
SET(LIB_ETC ${CMAKE_SOURCE_DIR}/etc)
SET(LIB_ENV ${CMAKE_SOURCE_DIR}/etc/environment_modules)
SET(LIB_BIN ${CMAKE_SOURCE_DIR}/bin)
SET(LIB_TMP_INC ${CMAKE_BINARY_DIR}/include)
SET(LIB_TMP_ETC ${CMAKE_BINARY_DIR}/etc)
SET(LIB_TMP_BIN ${CMAKE_BINARY_DIR}/bin)
SET(LIB_TMP_VER ${CMAKE_BINARY_DIR}/version)
SET(LIB_TARGET_LIB ${CMAKE_INSTALL_PREFIX}/lib)
SET(LIB_TARGET_INC ${CMAKE_INSTALL_PREFIX}/include)
SET(LIB_TARGET_ETC ${CMAKE_INSTALL_PREFIX}/etc)
SET(LIB_TARGET_BIN ${CMAKE_INSTALL_PREFIX}/bin)
SET(LIB_TARGET_DIR ${CMAKE_INSTALL_PREFIX})
# Have the .mod files placed in the INC folder
SET(CMAKE_Fortran_MODULE_DIRECTORY ${LIB_TMP_INC})
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_Fortran_MODULE_DIRECTORY})
IF(WITH_BLAS_LAPACK)
SET(SRC_DIR_BLAS ${LIB_SRC}/blas)
ADD_SUBDIRECTORY(${SRC_DIR_BLAS})
SET(SRC_DIR_LAPACK ${LIB_SRC}/lapack)
ADD_SUBDIRECTORY(${SRC_DIR_LAPACK})
ENDIF()
SET(SRC_DIR_ARPACK ${LIB_SRC}/arpack)
ADD_SUBDIRECTORY(${SRC_DIR_ARPACK})
SET(SRC_DIR_FFTPACK ${LIB_SRC}/fftpack)
ADD_SUBDIRECTORY(${SRC_DIR_FFTPACK})
SET(SRC_DIR_MINPACK ${LIB_SRC}/minpack)
ADD_SUBDIRECTORY(${SRC_DIR_MINPACK})
SET(SRC_DIR_QUADPACK ${LIB_SRC}/quadpack)
ADD_SUBDIRECTORY(${SRC_DIR_QUADPACK})
SET(SRC_DIR_SF_INIT ${LIB_SRC}/SF_INIT)
ADD_SUBDIRECTORY(${SRC_DIR_SF_INIT})
SET(SRC_DIR_SF_MPI ${LIB_SRC}/SF_MPI)
ADD_SUBDIRECTORY(${SRC_DIR_SF_MPI})
SET(SRC_DIR_SF_IOTOOLS ${LIB_SRC}/SF_IOTOOLS)
ADD_SUBDIRECTORY(${SRC_DIR_SF_IOTOOLS})
SET(SRC_DIR_SF_DERIVATE ${LIB_SRC}/SF_DERIVATE)
ADD_SUBDIRECTORY(${SRC_DIR_SF_DERIVATE})
SET(SRC_DIR_SF_INTEGRATE ${LIB_SRC}/SF_INTEGRATE)
ADD_SUBDIRECTORY(${SRC_DIR_SF_INTEGRATE})
SET(SRC_DIR_SF_INTERPOLATE ${LIB_SRC}/SF_INTERPOLATE)
ADD_SUBDIRECTORY(${SRC_DIR_SF_INTERPOLATE})
SET(SRC_DIR_SF_LINALG ${LIB_SRC}/SF_LINALG)
ADD_SUBDIRECTORY(${SRC_DIR_SF_LINALG})
SET(SRC_DIR_SF_FFT ${LIB_SRC}/SF_FFT)
ADD_SUBDIRECTORY(${SRC_DIR_SF_FFT})
SET(SRC_DIR_SF_OPTIMIZE ${LIB_SRC}/SF_OPTIMIZE)
ADD_SUBDIRECTORY(${SRC_DIR_SF_OPTIMIZE})
SET(SRC_DIR_SF_SPECIAL ${LIB_SRC}/SF_SPECIAL)
ADD_SUBDIRECTORY(${SRC_DIR_SF_SPECIAL})
SET(SRC_DIR_SF_RANDOM ${LIB_SRC}/SF_RANDOM)
ADD_SUBDIRECTORY(${SRC_DIR_SF_RANDOM})
SET(SRC_DIR_SF_SP_LINALG ${LIB_SRC}/SF_SP_LINALG)
ADD_SUBDIRECTORY(${SRC_DIR_SF_SP_LINALG})
SET(SRC_DIR_SF_PARSE_INPUT ${LIB_SRC}/SF_PARSE_INPUT)
ADD_SUBDIRECTORY(${SRC_DIR_SF_PARSE_INPUT})
ADD_SUBDIRECTORY(${LIB_SRC})
# Build the library and have it placed in the target lib folder
IF(WITH_BLAS_LAPACK)
ADD_LIBRARY(scifor
$<TARGET_OBJECTS:BLASLIB>
$<TARGET_OBJECTS:LAPACKLIB>
$<TARGET_OBJECTS:ARPACKLIB>
$<TARGET_OBJECTS:FFTPACKLIB>
$<TARGET_OBJECTS:MINPACKLIB>
$<TARGET_OBJECTS:QUADPACKLIB>
$<TARGET_OBJECTS:SF_INITLIB>
$<TARGET_OBJECTS:SF_MPILIB>
$<TARGET_OBJECTS:SF_IOTOOLSLIB>
$<TARGET_OBJECTS:SF_LINALGLIB>
$<TARGET_OBJECTS:SF_DERIVATELIB>
$<TARGET_OBJECTS:SF_OPTIMIZELIB>
$<TARGET_OBJECTS:SF_INTEGRATELIB>
$<TARGET_OBJECTS:SF_SPECIALLIB>
$<TARGET_OBJECTS:SF_FFTLIB>
$<TARGET_OBJECTS:SF_INTERPOLATELIB>
$<TARGET_OBJECTS:SF_RANDOMLIB>
$<TARGET_OBJECTS:SF_SP_LINALGLIB>
$<TARGET_OBJECTS:SF_PARSE_INPUTLIB>
$<TARGET_OBJECTS:SCIFORLIB>
)
ELSE()
ADD_LIBRARY(scifor
$<TARGET_OBJECTS:ARPACKLIB>
$<TARGET_OBJECTS:FFTPACKLIB>
$<TARGET_OBJECTS:MINPACKLIB>
$<TARGET_OBJECTS:QUADPACKLIB>
$<TARGET_OBJECTS:SF_INITLIB>
$<TARGET_OBJECTS:SF_MPILIB>
$<TARGET_OBJECTS:SF_IOTOOLSLIB>
$<TARGET_OBJECTS:SF_LINALGLIB>
$<TARGET_OBJECTS:SF_DERIVATELIB>
$<TARGET_OBJECTS:SF_OPTIMIZELIB>
$<TARGET_OBJECTS:SF_INTEGRATELIB>
$<TARGET_OBJECTS:SF_SPECIALLIB>
$<TARGET_OBJECTS:SF_FFTLIB>
$<TARGET_OBJECTS:SF_INTERPOLATELIB>
$<TARGET_OBJECTS:SF_RANDOMLIB>
$<TARGET_OBJECTS:SF_SP_LINALGLIB>
$<TARGET_OBJECTS:SF_PARSE_INPUTLIB>
$<TARGET_OBJECTS:SCIFORLIB>
)
ENDIF()
ADD_DEPENDENCIES(SF_SPECIALLIB
SF_INTEGRATELIB
)
ADD_DEPENDENCIES(SF_FFTLIB
SF_INTEGRATELIB
)
ADD_DEPENDENCIES(SF_RANDOMLIB
SF_IOTOOLSLIB
)
ADD_DEPENDENCIES(SF_SP_LINALGLIB
SF_RANDOMLIB
)
ADD_DEPENDENCIES(SCIFORLIB
SF_INITLIB
SF_MPILIB
SF_IOTOOLSLIB
SF_DERIVATELIB
SF_LINALGLIB
SF_OPTIMIZELIB
SF_SPECIALLIB
SF_INTEGRATELIB
SF_INTERPOLATELIB
SF_RANDOMLIB
SF_FFTLIB
SF_SP_LINALGLIB
SF_PARSE_INPUTLIB
)
SET(PERMISSION_777
OWNER_WRITE OWNER_READ OWNER_EXECUTE
GROUP_WRITE GROUP_READ GROUP_EXECUTE
WORLD_WRITE WORLD_READ WORLD_EXECUTE)
#Build the PKG-CONFIG file
INCLUDE(${CMAKE_MODULE_PATH}/BuildPkgConfigFile.cmake)
SET(TMP_PKCONFIG_FILE ${LIB_TMP_ETC}/${PROJECT_NAME}.pc)
BUILD_PKCONFIG(${TMP_PKCONFIG_FILE})
############################################################
############################################################
############################################################
INCLUDE(${CMAKE_MODULE_PATH}/PostConfig.cmake)