forked from MeshToolkit/MSTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
383 lines (273 loc) · 11.4 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
# -*- mode: cmake -*-
#
# Top-Level CMake file for MSTK
#
# IT IS NOT ADVISABLE TO MODIFY THIS FILE - RATHER ENABLE/DISABLE VARIOUS
# OPTIONS USING COMMAND LINE ARGUMENTS IN THE config/do-configure-* files
#
# Author: Rao Garimella (rao@lanl.gov)
#
project (MSTK)
cmake_minimum_required(VERSION 2.8)
cmake_policy(SET CMP0017 NEW)
set(ARCHOS ${CMAKE_SYSTEM_PROCESSOR}_${CMAKE_SYSTEM_NAME})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
# This option may be needed for machines like Edison and Hopper
if (PREFER_STATIC_LIBRARIES)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a; .so")
endif()
##############################################################################
# MSTK LIBRARY BUILD CONFIGURATION
##############################################################################
# Flags for parallel build
if (ENABLE_PARALLEL)
find_package(MPI)
if (MPI_FOUND)
message("PARALLELISM ON")
add_definitions(-DMSTK_HAVE_MPI)
message(STATUS "MPIEXEC is ${MPIEXEC}")
else (MPI_FOUND)
message("PARALLELISM OFF")
endif (MPI_FOUND)
endif (ENABLE_PARALLEL)
# Default build type is Release (Optimized)
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Release)
endif ()
# include files and source files
include_directories(${PROJECT_SOURCE_DIR}/include)
add_subdirectory(src)
# Extra library suffix for Debug builds
if (CMAKE_BUILD_TYPE STREQUAL Debug)
if (INSTALL_ADD_DEBUG_SUFFIX)
set (CONFIG_SUFFIX -d)
endif ()
add_definitions(-DDEBUG)
endif ()
# Add version number to library name
if (INSTALL_ADD_VERSION)
set (MSTKLIB mstk-${MSTK_VERSION_MAJOR}.${MSTK_VERSION_MINOR}${CONFIG_SUFFIX})
else ()
set (MSTKLIB mstk${CONFIG_SUFFIX})
endif ()
add_library(${MSTKLIB} ${mstkfiles})
message(STATUS "Building library " ${MSTKLIB})
# Default INSTALL Directory
if (NOT INSTALL_DIR)
set (INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
endif ()
# where to install library
if (INSTALL_PREFIX_ARCHOS)
install(TARGETS ${MSTKLIB}
EXPORT mstk
ARCHIVE
DESTINATION ${INSTALL_DIR}/lib/${ARCHOS}
CONFIGURATIONS ${CMAKE_BUILD_TYPE}
)
else ()
install(TARGETS ${MSTKLIB}
EXPORT mstk
ARCHIVE
DESTINATION ${INSTALL_DIR}/lib
CONFIGURATIONS ${CMAKE_BUILD_TYPE}
)
endif ()
# where to install include files
if (${INSTALL_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
else ()
INSTALL(FILES
${PROJECT_SOURCE_DIR}/include/MSTK.h
${PROJECT_SOURCE_DIR}/include/MSTK_defines.h
${PROJECT_SOURCE_DIR}/include/MSTK_types.h
${PROJECT_SOURCE_DIR}/include/MSTK_externs.h
${PROJECT_SOURCE_DIR}/include/MSTK_util.h
DESTINATION ${INSTALL_DIR}/include)
endif ()
################################################################################
# Discover TPLs (Third Party Libraries) based on configure options
################################################################################
message("\n-------------------------------------------------------------------")
message("--- Configuring MSTK with:")
################################################################################
# If MSTK should enable and use markers to enable fast constant time searches
# in list and set operations
################################################################################
if (MSTK_USE_MARKERS)
add_definitions("-DMSTK_USE_MARKERS")
endif (MSTK_USE_MARKERS)
################################################################################
# If user wants to read/write ExodusII files, we check if we can locate the
# ExodusII and NetCDF include files and libraries
################################################################################
if (ENABLE_ExodusII)
add_definitions("-DENABLE_ExodusII")
##############################################################################
# HDF5 -
##############################################################################
set(HDF5_ROOT ${HDF5_DIR})
find_package(HDF5 REQUIRED
COMPONENTS C CXX HL)
if(NOT HDF5_FOUND)
message(FATAL_ERROR "Error: could not find hdf5 library\n"
"Try defining HDF5_DIR: (-D HDF5_DIR:FILEPATH=<HDF5_install_prefix>)")
endif()
message("---- HDF5_LIBRARIES : " ${HDF5_LIBRARIES})
message("---- HDF5_IS_PARALLEL : " ${HDF5_IS_PARALLEL})
##############################################################################
# NetCDF - http://www.unidata.ucar.edu/software/netcdf/
##############################################################################
# Could replace with find_package(NetCDF REQUIRED)
find_package(NetCDF REQUIRED)
if(NOT NetCDF_FOUND)
message(FATAL_ERROR "Error: could not find netcdf library\n"
"Try defining NetCDF_DIR: (-D NetCDF_DIR:FILEPATH=<NetCDF_install_prefix>)")
endif()
message("---- NETCDF_LIBRARY : " ${NetCDF_LIBRARIES})
##############################################################################
# ExodusII - http://sourceforge.net/projects/exodusii/ or
# get it as part of Trilinos - http:://trilinos.sandia.gov
##############################################################################
find_package(ExodusII REQUIRED)
if(NOT ExodusII_FOUND)
message(FATAL_ERROR "Error: could not find ExodusII library\n"
"Try defining ExodusII_DIR: (-D ExodusII_DIR:FILEPATH=<ExodusII_install_prefix>)")
endif()
include_directories(${ExodusII_INCLUDE_DIRS})
message("---- EXODUSII_LIBRARY : " ${ExodusII_LIBRARIES})
endif(ENABLE_ExodusII)
##############################################################################
# What we need if we need parallel support
##############################################################################
if (ENABLE_PARALLEL)
if ((NOT ENABLE_METIS) AND (NOT ENABLE_ZOLTAN))
message(FATAL_ERROR "Error: Must enable METIS or ZOLTAN as a partitioner")
endif()
##############################################################################
# Metis
##############################################################################
if (ENABLE_METIS)
find_package(METIS REQUIRED)
if (NOT METIS_FOUND)
message(FATAL_ERROR "Error: could not find Metis library\n"
"Try defining Metis_DIR: (-D Metis_DIR:FILEPATH=<Metis_install_prefix>)\n")
endif (NOT METIS_FOUND)
include_directories(${METIS_INCLUDE_DIRS})
message("---- METIS_LIBRARY :" ${METIS_LIBRARY})
add_definitions(-D_MSTK_HAVE_METIS)
if (METIS_MAJOR_VER)
add_definitions(-DMETIS_${METIS_MAJOR_VER})
else (METIS_MAJOR_VER)
add_definitions(-DMETIS_5)
endif (METIS_MAJOR_VER)
endif (ENABLE_METIS)
##############################################################################
# Zoltan
##############################################################################
if (ENABLE_ZOLTAN)
find_package(ZOLTAN REQUIRED)
if (NOT ZOLTAN_FOUND)
message(FATAL_ERROR "Error: could not find Zoltan library\n"
"Try defining Zoltan_DIR: (-D Zoltan_DIR:FILEPATH=<Zoltan_install_prefix>)\n")
endif (NOT ZOLTAN_FOUND)
include_directories(${ZOLTAN_INCLUDE_DIRS})
message("---- ZOLTAN_LIBRARY :" ${ZOLTAN_LIBRARY})
add_definitions(-D_MSTK_HAVE_ZOLTAN)
if (ZOLTAN_NEEDS_ParMETIS)
find_package(ParMETIS REQUIRED)
if (NOT ParMETIS_FOUND)
message(FATAL_ERROR "Error: could not find ParMETIS library \
needed by ZOLTAN\n \
Try defining ParMETIS_DIR: \
(-D ParMETIS_DIR:FILEPATH=<ParMETIS_install_prefix>)\n")
endif (NOT ParMETIS_FOUND)
list(APPEND ZOLTAN_LIBRARIES ${ParMETIS_LIBRARIES})
message("ParMETIS_LIBRARIES --- " ${ParMETIS_LIBRARIES})
message("ZOLTAN_LIBRARIES --- " ${ZOLTAN_LIBRARIES})
endif (ZOLTAN_NEEDS_ParMETIS)
if (ZOLTAN_NEEDS_PTScotch)
find_package(PTScotch REQUIRED)
if (NOT PTScotch_FOUND)
message(FATAL_ERROR "Error: could not find PTScotch library \
needed by ZOLTAN\n \
Try defining PTScotch_DIR: \
(-D PTScotch_DIR:FILEPATH=<PTScotch_install_prefix>)\n")
endif (NOT PTScotch_FOUND)
list(APPEND ZOLTAN_LIBRARIES ${PTScotch_LIBRARIES})
message("PTScotch_LIBRARIES --- " ${PTScotch_LIBRARIES})
message("ZOLTAN_LIBRARIES --- " ${ZOLTAN_LIBRARIES})
endif (ZOLTAN_NEEDS_PTScotch)
endif (ENABLE_ZOLTAN)
endif (ENABLE_PARALLEL)
##############################################################################
# TESTS
##############################################################################
if (ENABLE_Tests)
enable_testing()
##############################################################################
# UnitTest++ - http://unittest-cpp.sourceforge.net/
##############################################################################
if (NOT DEFINED UnitTest_DIR)
message(WARNING "No UnitTest++ directory defined. To compile the unit tests add:
-D UnitTest_DIR::FILEPATH=<UnitTest++_install_prefix>")
else()
find_library(UNITTEST_LIBRARY
NAMES UnitTest++ unittest++
HINTS ${UnitTest_DIR}
${UnitTest_LIB_DIR}
${UnitTest_DIR}/lib
)
if (NOT UNITTEST_LIBRARY)
message(FATAL_ERROR "Error: could not find unittest++ library")
endif()
find_path(UNITTEST_INCLUDES "UnitTest++.h"
HINTS ${UnitTest_INCLUDE_DIR}
${UnitTest_DIR}
${UnitTest_DIR}/include
${UnitTest_DIR}/src
${UnitTest_DIR}/include/unittest++
)
if (NOT UNITTEST_INCLUDES)
message(FATAL_ERROR "Error: could not find UnitTest++ includes")
else()
include_directories(${UNITTEST_INCLUDES})
endif()
set(BUILD_TESTS 1)
add_library(unittest++ STATIC IMPORTED)
set_property(TARGET unittest++ PROPERTY IMPORTED_LOCATION ${UNITTEST_LIBRARY})
endif()
endif()
# What are all the TPLs that codes linking to MSTK have to link to
set(MSTK_TPL_LIBRARIES ${METIS_LIBRARIES} ${ZOLTAN_LIBRARIES}
${ExodusII_LIBRARIES} ${NetCDF_LIBRARIES} ${HDF5_LIBRARIES})
# Make a separate variables where the HDF5 libraries are not targets
# but expanded library paths. This will be exported for use by other
# projects
set(MSTK_TPL_LIBRARIES_EXPORT ${METIS_LIBRARIES} ${ZOLTAN_LIBRARIES}
${ExodusII_LIBRARIES} ${NetCDF_LIBRARIES} ${HDF5_LIBRARIES_EXPORT})
#############################################################################
# Unittests
###############################################################################
if (ENABLE_Tests)
add_subdirectory(unittests)
endif ()
#############################################################################
# Utilities
###############################################################################
add_subdirectory(utils)
#############################################################################
# Example
###############################################################################
add_subdirectory(example)
##############################################################################
# Write a configuration file from template replacing only variables enclosed
# by the @ sign. This will let other programs build on MSTK discover how
# MSTK was built and which TPLs it used
#############################################################################
configure_file(${PROJECT_SOURCE_DIR}/cmake/MSTKConfig.cmake.in
${PROJECT_BINARY_DIR}/MSTKConfig.cmake @ONLY)
install(FILES ${PROJECT_BINARY_DIR}/MSTKConfig.cmake
DESTINATION ${INSTALL_DIR}/share/cmake/)
# export cmake file other projects can use to find MSTK and its dependencies
# I think this is not needed because of the previous config file
#
#install(EXPORT mstk DESTINATION ${INSTALL_DIR}/lib/${ARCHOS})