forked from FrontISTR/FrontISTR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
412 lines (379 loc) · 14.5 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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
###############################################################################
# Copyright (c) 2016 FrontISTR Forum, The University of Tokyo
# This software is released under the MIT License, see License.txt
###############################################################################
###############################################################
# CMakeLists.txt for FrontISTR
###############################################################
cmake_minimum_required(VERSION 2.8.11)
###############################################################
# Check building mode whether out-of-source builds
###############################################################
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "
*************** ERROR ***************
Only support for out-of-source building.
You may need to remove CMakeCache.txt file and CMakeFiles/ directory.
Please make new directory such as build/ and run cmake in it again.
[example]
rm CMakeCache.txt; rm -rf CMakeFiles/
mkdir build/; cd build/
cmake ..
make")
endif()
project(FrontISTR Fortran C CXX)
###############################################################
# Includes standard macros
###############################################################
include(FeatureSummary)
include(CMakeDependentOption)
include(CMakeDetermineFortranCompiler)
###############################################################
# Add module path for FindPackage.cmake
###############################################################
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
###############################################################
# Initialize variable of definitions, link libraries, includes
###############################################################
set(FrontISTR_DEFINITIONS)
set(FrontISTR_LIBRARIES)
set(FrontISTR_INCLUDE_DIRS ${CMAKE_Fortran_MODULE_DIRECTORY} ${PROJECT_BINARY_DIR})
###############################################################
# Build type (RELEASE or DEBUG)
###############################################################
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RELEASE" CACHE STRING "Build type (RELEASE or DEBUG)" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS RELEASE DEBUG)
endif()
if(CMAKE_BUILD_TYPE MATCHES "DEBUG")
list(APPEND FrontISTR_DEFINITIONS "DEBUG")
# Enable debug options
find_package(Backtrace)
if(Backtrace_FOUND)
list(APPEND FrontISTR_LIBRARIES ${Backtrace_LIBRARY})
list(APPEND FrontISTR_INCLUDE_DIR ${Backtrace_INCLUDE_DIR})
set(CMAKE_VERBOSE_MAKEFILE ON)
# GNU Compiler
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
set(CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra")
set(CMAKE_Fortran_FLAGS_DEBUG
"${CMAKE_Fortran_FLAGS_DEBUG} -Wall -Wextra -fbounds-check -fbacktrace")
if(${DEBUG_EXTRA})
set(CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} -fsanitize=address")
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address")
set(CMAKE_Fortran_FLAGS_DEBUG
"${CMAKE_Fortran_FLAGS_DEBUG} -fsanitize=address")
endif()
# Intel Compiler
elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
set(CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} -Wall -Wbrief -Wcheck")
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wbrief -Wcheck")
set(CMAKE_Fortran_FLAGS_DEBUG
#"${CMAKE_Fortran_FLAGS_DEBUG} -warn all -check all -traceback")
"${CMAKE_Fortran_FLAGS_DEBUG} -warn nounused -check uninit,bound -traceback")
endif()
endif()
elseif (CMAKE_BUILD_TYPE MATCHES "RELEASE")
list(APPEND FrontISTR_DEFINITIONS "NDEBUG")
endif()
###############################################################
# Version number
###############################################################
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
set(VERSION_MAJOR 5 CACHE STRING "Major version number of FrontISTR")
set(VERSION_MINOR 0 CACHE STRING "Minor version number of FrontISTR")
set(VERSION_PATCH 0 CACHE STRING "Patch version number of FrontISTR")
set(GIT_HASH \"${GIT_SHA1}\" CACHE STRING "GIT hash number of FrontISTR")
mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH GIT_HASH)
#############################################
# Archtecture and compiler dependent options
#############################################
if(WIN32)
set(WINDOWS TRUE)
endif()
###############################################################
# Options
###############################################################
# -DWINDOWS : build on Windows
# -DWITH_TOOLS : compile tools
# -DWITH_MPI : for parallel environment with MPI
# -DWITH_OPENMP : for multi-(core|processor) environment
# -DWITH_REFINER : compile with REVOCAP_Refiner
# -DWITH_REVOCAP : compile with REVOCAP_Coupler
# -DWITH_METIS : compile with METIS graph partitioning package
# -DMETIS_VER_4 : uses METIS-4
# -DWITH_PARMETIS : compile with ParMETIS
# -DPARMETIS_VER_3 : uses PARMETIS-3
# -DWITH_MKL : compile with MKL PARDISO
# -DWITH_MUMPS : compile with MUMPS direct solver
# -DWITH_LAPACK : compile with LAPACK
# -DWITH_ML : compile with Trilinos multigrid preconditioning package
# -DWITH_DOC : generate API documents
###################
# Find external packages
###################
find_package(MPI)
find_package(OpenMP)
find_package(LAPACK)
find_package(Metis)
find_package(Mumps)
find_package(Parmetis)
find_package(Refiner)
find_package(Revocap)
find_package(Scalapack)
find_package(Trilinos)
find_package(Doxygen)
option(WITH_TOOLS "compile tools" ON)
option(WITH_DOC "Generate API documents." ${WITH_DOC})
option(WINDOWS "build on windows" ${WINDOWS})
option(WITH_MPI "for parallel environment with MPI" ${MPI_FOUND})
option(WITH_OPENMP "for multi-(core|processor) environment" ${OPENMP_FOUND})
option(WITH_MKL "compile with MKL PARDISO" ${SCALAPACK_MKL})
option(WITH_LAPACK "for estimating number of condition" ${LAPACK_FOUND})
option(WITH_METIS "compile with METIS" ${METIS_FOUND})
option(METIS_VER_4 "uses METIS-4" OFF)
option(WITH_MUMPS "compile with MUMPS direct solver" ${MUMPS_FOUND})
option(WITH_PARMETIS "compile with ParMETIS" ${PARMETIS_FOUND})
option(PARMETIS_VER_3 "uses METIS-3" OFF)
option(WITH_REFINER "compile with REVOCAP_Refiner" ${REFINER_FOUND})
option(WITH_REVOCAP "compile with REVOCAP_Coupler" ${REVOCAP_FOUND})
option(WITH_ML "compile with Trilinos ML" ${Trilinos_FOUND})
option(DEBUG_EXTRA "enable memory leak check (only for gcc4.9 <)" OFF)
feature_summary(WHAT ALL)
###################
# -DWITH_MPI
###################
if(WITH_MPI AND MPI_Fortran_FOUND AND MPI_CXX_FOUND AND MPI_C_FOUND)
list(APPEND FrontISTR_INCLUDE_DIRS
${MPI_C_INCLUDE_PATH}
${MPI_CXX_INCLUDE_PATH}
${MPI_Fortran_INCLUDE_PATH})
list(APPEND FrontISTR_LIBRARIES
${MPI_C_LIBRARIES}
${MPI_CXX_LIBRARIES}
${MPI_Fortran_LIBRARIES})
else()
set(WITH_MPI OFF)
set(HECMW_SERIAL ON)
list(APPEND FrontISTR_DEFINITIONS "HECMW_SERIAL")
endif()
mark_as_advanced(MPI_EXTRA_LIBRARY MPI_LIBRARY)
###################
# -DWITH_OPENMP
###################
if(WITH_OPENMP AND OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_C_FLAGS}")
else()
set(WITH_OPENMP OFF)
endif()
###################
# -DWITH_REFINER
###################
if(WITH_REFINER AND REFINER_FOUND)
list(APPEND FrontISTR_INCLUDE_DIRS ${REFINER_INCLUDE_PATH})
list(APPEND FrontISTR_DEFINITIONS "HECMW_WITH_REFINER")
list(APPEND FrontISTR_LIBRARIES ${REFINER_LIBRARIES})
else()
set(WITH_REFINER OFF)
set(HECMW_WITH_REFINER OFF)
endif()
###################
# -DWITH_REVOCAP
###################
if(WITH_REVOCAP AND REVOCAP_FOUND)
list(APPEND FrontISTR_INCLUDE_DIRS ${REVOCAP_INCLUDE_PATH})
else()
set(WITH_REVOCAP OFF)
endif()
###################
# -DWITH_ML
###################
if(WITH_ML)
if(Trilinos_FOUND)
list(APPEND FrontISTR_INCLUDE_DIRS ${Trilinos_INCLUDE_DIRS} ${Trilinos_TPL_INCLUDE_DIRS})
list(APPEND FrontISTR_DEFINITIONS "HECMW_WITH_ML")
list(APPEND FrontISTR_LIBRARIES ${Trilinos_LIBRARIES} ${Trilinos_TPL_LIBRARIES})
else()
message(WARNING "Trilinos not found")
set(WITH_ML OFF)
endif()
endif()
mark_as_advanced(Trilinos_DIR)
###################
# -DWITH_PARMETIS
###################
if(WITH_PARMETIS AND PARMETIS_FOUND)
list(APPEND FrontISTR_INCLUDE_DIRS ${PARMETIS_INCLUDE_PATH})
list(APPEND FrontISTR_LIBRARIES ${PARMETIS_LIBRARIES})
if(NOT PARMETIS_VER_3)
else()
endif()
endif()
###################
# -DWITH_MUMPS
###################
if(WITH_MUMPS)
if(MUMPS_FOUND AND ( (SCALAPACK_FOUND AND LAPACK_FOUND) OR SCALAPACK_MKL ) )
list(APPEND FrontISTR_DEFINITIONS "HECMW_WITH_MUMPS")
list(APPEND FrontISTR_INCLUDE_DIRS ${MUMPS_INCLUDE_PATH})
list(APPEND FrontISTR_LIBRARIES ${MUMPS_LIBRARIES} ${SCALAPACK_LIBRARIES})
mark_as_advanced(scalapack_DIR)
else()
message(FATAL_ERROR "MUMPS could not enable. Please also install scalapack and lapack.")
set(WITH_MUMPS OFF)
endif()
else()
set(WITH_MUMPS OFF)
endif()
###################
# -DWITH_METIS
# -DMETIS_VER_4
###################
if(WITH_METIS AND METIS_FOUND)
list(APPEND FrontISTR_INCLUDE_DIRS ${METIS_INCLUDE_PATH})
list(APPEND FrontISTR_DEFINITIONS "HECMW_WITH_METIS")
list(APPEND FrontISTR_DEFINITIONS "HECMW_PART_WITH_METIS")
list(APPEND FrontISTR_LIBRARIES ${METIS_LIBRARIES})
if(NOT METIS_VER_4)
list(APPEND FrontISTR_DEFINITIONS "HECMW_METIS_VER=5")
else()
list(APPEND FrontISTR_DEFINITIONS "HECMW_METIS_VER=4")
endif()
endif()
###################
# -DWITH_LAPACK
###################
if(WITH_LAPACK)
if(LAPACK_FOUND AND BLAS_FOUND)
list(APPEND FrontISTR_DEFINITIONS "HECMW_WITH_LAPACK")
list(APPEND FrontISTR_LIBRARIES ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
else()
set(WITH_LAPACK OFF)
endif()
endif()
###################
# -DWITH_MKL
###################
if(WITH_MKL)
message(STATUS "scalapack libraries ${SCALAPACK_LIBRARIES}")
set(BLA_VENDOR "Intel10_64lp")
list(APPEND FrontISTR_INCLUDE_DIRS $ENV{MKLROOT}/include)
list(APPEND FrontISTR_LIBRARIES ${SCALAPACK_LIBRARIES})
list(APPEND FrontISTR_DEFINITIONS "WITH_MKL")
set(WITH_LAPACK ON)
else()
set(WITH_MKL OFF)
endif()
#############################################
# Archtecture and compiler dependent options
#############################################
###################
# -DWINDOWS
###################
if(WINDOWS)
list(APPEND FrontISTR_DEFINITIONS "_WINDOWS")
list(APPEND FrontISTR_LIBRARIES "ws2_32")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-range-check")
endif()
###################
# -DWITH_DOC
###################
if(WITH_DOC)
if(DOXYGEN_FOUND)
message(STATUS "Generate API documents. Please type \"make doc\"")
file(COPY ${CMAKE_SOURCE_DIR}/doc/fistr.css DESTINATION ${CMAKE_BINARY_DIR}/doc/)
file(COPY ${CMAKE_SOURCE_DIR}/doc/fistr_logo.png DESTINATION ${CMAKE_BINARY_DIR}/doc/)
set(doxy_main_page "${CMAKE_SOURCE_DIR}/README.md")
set(doxyfile_in ${CMAKE_SOURCE_DIR}/doc/Doxyfile.in)
set(doxyfile ${CMAKE_BINARY_DIR}/doc/Doxyfile)
configure_file(${doxyfile_in} ${doxyfile} @ONLY)
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generate API documents."
VERBATIM
)
else()
message(WARNING "doxygen not found.")
endif()
endif()
###############################################################################
# Print STATUS
###############################################################################
message(STATUS
"Build FrontISTR for ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM_VERSION}")
message(STATUS "BUILD Type\t\t: ${CMAKE_BUILD_TYPE}")
message(STATUS "C compiler\t\t: ${CMAKE_C_COMPILER}")
message(STATUS "C++ compiler\t\t: ${CMAKE_CXX_COMPILER}")
message(STATUS "Fortran compiler\t: ${CMAKE_Fortran_COMPILER}")
message(STATUS "Installation path\t: ${CMAKE_INSTALL_PREFIX}")
if(CMAKE_BUILD_TYPE MATCHES "DEBUG")
message(STATUS "Defines\t\t: ${FrontISTR_DEFINITIONS}")
message(STATUS "Include paths\t: ${FrontISTR_INCLUDE_DIRS}")
message(STATUS "Library search path\t: ${CMAKE_PREFIX_PATH}")
message(STATUS "Linking libraries\t: ${FrontISTR_LIBRARIES}")
endif()
###############################################################################
# Make configuration header
###############################################################################
configure_file(
"${PROJECT_SOURCE_DIR}/FrontISTRConfig.h.in"
"${PROJECT_BINARY_DIR}/FrontISTRConfig.h"
)
###############################################################################
# Build hecmw1, fistr1 and fistr
###############################################################################
# Build targets
# hecmw (libhecmw.a)
# fistr (libfistr.a)
# fistr1 (fistr1)
#
# Optional : rmerge, hecmw_part, hec2rcap, rconv, hecmw_vis1, neu2fstr
#
add_subdirectory(hecmw1)
add_subdirectory(fistr1)
###############################################################################
# Tests
###############################################################################
find_package(Ruby)
if (NOT ${RUBY_EXECUTABLE})
message(STATUS "Found ${RUBY_EXECUTABLE}. Enable tests.")
message("If you would like to test, please type 'make test' after build binaries.")
enable_testing()
add_subdirectory(examples)
endif()
###############################################################################
# Package generator (deb, rpm, exe etc.)
###############################################################################
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Large-scale structural analysis program with FEM ")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
set(CPACK_PACKAGE_VENDOR "FrontISTR Forum, The University of Tokyo")
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}")
set(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(CPACK_PACKAGE_CONTACT "${CPACK_PACKAGE_VENDOR}")
if(WIN32 AND NOT UNIX)
# Windows
else()
# Unix
set(CPACK_BINARY_DEB ON)
set(CPACK_BINARY_RPM ON)
set(CPACK_GENERATOR "TBZ2;DEB;RPM")
set(CPACK_STRIP_FILES ON)
endif()
include(CPack)