-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCMakeLists.txt
423 lines (301 loc) · 13.6 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
413
414
415
416
417
418
419
420
421
# Copyright 2019 Triad National Security, LLC. All rights reserved.
#
# This file is part of the MSTK project. Please see the license file at
# the root of this repository or at
# https://github.com/MeshToolkit/MSTK/blob/master/LICENSE
# Copyright 2019 Triad National Security, LLC. All rights reserved.
#
# This file is part of the MSTK project. Please see the license file at
# the root of this repository or at
# https://github.com/MeshToolkit/MSTK/blob/master/LICENSE
# -*- 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 ([email protected])
#
project (MSTK C CXX)
cmake_minimum_required(VERSION 3.11)
set(MSTK_VERSION_MAJOR 3)
set(MSTK_VERSION_MINOR 3)
set(MSTK_VERSION_PATCH 2)
cmake_policy(SET CMP0017 NEW)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12)
cmake_policy(SET CMP0074 NEW) # Don't ignore Pkg_ROOT vars
endif ()
#
# Also when CMake 3.15 is the minimum version we can find_package to
# prefer config files and fall back to module files
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
endif ()
set(ARCHOS ${CMAKE_SYSTEM_PROCESSOR}_${CMAKE_SYSTEM_NAME})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
# Default INSTALL Directory
if (NOT INSTALL_DIR)
set (INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
endif (NOT INSTALL_DIR)
set (MSTKLIB mstk)
# shared libraries tweaks; enforcing absolute path
if (BUILD_SHARED_LIBS)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_SKIP_INSTALL_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_RPATH}")
else()
SET(CMAKE_SKIP_INSTALL_RPATH ON CACHE BOOL "Turn off for static install." FORCE)
SET(CMAKE_SKIP_RPATH ON CACHE BOOL "Turn off for static install." FORCE)
endif()
# Add the actual source directory - these will build up the list "mstkfiles"
add_subdirectory(src)
# The main mstk target
add_library(${MSTKLIB} ${mstkfiles})
message(STATUS "Building library " ${MSTKLIB})
# Alias (Daniel Pfeiffer, Effective CMake) - this allows other
# projects that use MSTK as a subproject to find_package(mstk::mstk)
# which does nothing because mstk is already part of the project
add_library(mstk::${MSTKLIB} ALIAS ${MSTKLIB}) # we can use mstk::mstk to refere to mstk
# DEBUG FLAG
if (CMAKE_BUILD_TYPE STREQUAL Debug)
target_compile_definitions(${MSTKLIB} PUBLIC DEBUG)
endif ()
# include files and source files - have this upfront so that an MSTK.h from
# any of the TPL installations doesn't get picked up first
target_include_directories(${MSTKLIB} PUBLIC
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# If MSTK should enable and use markers to enable fast constant time searches
# in list and set operations
if (MSTK_USE_MARKERS)
target_compile_definitions(${MSTKLIB} PUBLIC MSTK_USE_MARKERS)
endif ()
################################################################################
# Discover TPLs (Third Party Libraries) based on configure options
################################################################################
message("\n-------------------------------------------------------------------")
message("--- Configuring MSTK with:")
#
# Flags for parallel build
if (ENABLE_PARALLEL)
find_package(MPI)
if (MPI_FOUND)
set(CMAKE_C_COMPILER ${MPI_C_COMPILER} CACHE FILEPATH "C compiler to use"
FORCE)
set(CMAKE_CXX_COMPILER ${MPI_CXX_COMPILER} CACHE FILEPATH "C compiler to use"
FORCE)
set(MSTK_HAVE_MPI True CACHE BOOL "If MSTK is compiled with MPI on")
message(STATUS "MPIEXEC is ${MPIEXEC}")
message(STATUS "CMAKE_C_COMPILER ${CMAKE_C_COMPILER}")
else ()
message(STATUS "Could not find package MPI - build may fail")
message(STATUS "Try setting CMAKE_C_COMPILER/CMAKE_CXX_COMPILER to the mpi compiler wrappers")
endif ()
endif ()
################################################################################
# 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)
target_compile_definitions(${MSTKLIB} PUBLIC ENABLE_ExodusII)
# For backward compatibility
if (NOT netCDF_DIR AND NetCDF_DIR)
set(netCDF_DIR ${NetCDF_DIR})
set(netCDF_ROOT ${netCDF_DIR})
endif ()
##############################################################################
# ExodusII - http://sourceforge.net/projects/exodusii/ or
# get it as part of Trilinos - http:://trilinos.sandia.gov
##############################################################################
if (ExodusII_DIR AND NOT ExodusII_ROOT)
set(ExodusII_ROOT ${ExodusII_DIR})
endif ()
# First seee if a config file got installed as part of the SEACAS project
# NOTE: NOT ABLE TO PROCESS THIS CORRECTLY
# find_package(SEACASExodus QUIET CONFIG PATHS ${ExodusII_DIR})
# if (SEACASExodus_FOUND)
# target_include_directories(${MSTKLIB} PUBLIC ${ExodusII_INCLUDE_DIRS})
# target_link_libraries(${MSTKLIB} PUBLIC ${ExodusII_LIBRARIES})
# message(STATUS "Found Exodus II library (from SEACAS): ${SEACAS_LIBRARIES}")
# else ()
find_package(ExodusII QUIET REQUIRED) # Uses MSTK module
target_include_directories(${MSTKLIB} PUBLIC ${ExodusII_INCLUDE_DIRS})
target_link_libraries(${MSTKLIB} PUBLIC ${ExodusII_LIBRARIES})
message(STATUS "Found Exodus II library: ${ExodusII_LIBRARY}")
# endif ()
endif ()
##############################################################################
# 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 QUIET REQUIRED) # uses MSTK module
if (NOT METIS_FOUND)
message(FATAL_ERROR "Error: could not find Metis library\n"
"Try defining Metis_DIR or METIS_ROOT or adding location of METIS to CMAKE_PREFIX_PATH \n")
endif ()
target_include_directories(${MSTKLIB} PUBLIC ${METIS_INCLUDE_DIRS})
target_compile_definitions(${MSTKLIB} PUBLIC _MSTK_HAVE_METIS)
target_compile_definitions(${MSTKLIB} PUBLIC METIS_5)
target_link_libraries(${MSTKLIB} PUBLIC ${METIS_LIBRARIES})
message(STATUS "Found Metis library: ${METIS_LIBRARY}")
if (METIS_DIR AND NOT METIS_ROOT)
set(METIS_ROOT ${METIS_DIR})
endif ()
endif ()
##############################################################################
# Zoltan
##############################################################################
if (ENABLE_ZOLTAN)
if (NOT Zoltan_DIR AND ZOLTAN_DIR)
set(Zoltan_DIR ${ZOLTAN_DIR})
set(Zoltan_ROOT ${Zoltan_DIR})
endif ()
# will use module for now - with cmake 3.15 onwards it will use
# config if available
find_package(Zoltan QUIET REQUIRED)
target_include_directories(${MSTKLIB} PUBLIC ${Zoltan_INCLUDE_DIRS})
target_link_libraries(${MSTKLIB} PUBLIC ${Zoltan_LIBRARIES})
target_compile_definitions(${MSTKLIB} PUBLIC _MSTK_HAVE_ZOLTAN)
message(STATUS "Found Zoltan library:" ${Zoltan_LIBRARY})
endif ()
endif ()
if (NOT METIS_FOUND AND NOT Zoltan_FOUND)
message(FATAL "Neither Zoltan not METIS found for partitioning")
endif ()
##############################################################################
# TESTS
##############################################################################
if (ENABLE_Tests)
enable_testing()
##############################################################################
# UnitTest++ - http://unittest-cpp.sourceforge.net/
##############################################################################
set(BUILD_TESTS TRUE)
# For backward compatibility allow UnitTest_DIR for a bit more time
if (NOT UnitTest++_DIR AND UnitTest_DIR)
set(UnitTest++_DIR ${UnitTest_DIR})
endif ()
set(unittest_dir_save ${UnitTest++_DIR})
find_package(UnitTest++ QUIET CONFIG PATHS ${UnitTest++_DIR}) # Try to discover thru cmake config file
if (UnitTest++_FOUND)
# UnitTest++ sets a weird path for it's includes
set(UnitTest++_INCLUDE_DIRS ${UTPP_INCLUDE_DIRS}/UnitTest++)
# Also it sets the target name as UnitTest++ but does not set the
# LIBRARIES variable
set(UnitTest++_LIBRARIES UnitTest++)
# Finally it does not connect the include directories to the target
set_target_properties(UnitTest++ PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${UnitTest++_INCLUDE_DIRS})
else ()
set(UnitTest++_DIR ${unittest_dir_save})
find_package(UnitTest++ QUIET REQUIRED MODULE) # fallback to MSTK module
endif ()
message(STATUS "Found UnitTest++: ${UnitTest++_LIBRARY}")
set(BUILD_TESTS TRUE)
endif()
# Finally make the math library a dependency of MSTK
target_link_libraries(${MSTKLIB} PUBLIC m)
# 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)
#######################################################
# set up headers that will get installed, including a configured MSTK_defines.h
#######################################################
# Copy all the headers into the PROJECT_BINARY_DIR/include so that
# they are found before the originals in the PROJECT_SOURCE_DIR. The
# problem with finding the ones in the PROJECT_SOURCE_DIR is that a
# header file from there automatically pulls in the unconfigured
# MSTK_defines.h from there as well leading to a compilation error
file(GLOB ALL_HEADERS ${PROJECT_SOURCE_DIR}/include/*.h)
foreach (HEADER_FILE ${ALL_HEADERS})
file(COPY ${HEADER_FILE} DESTINATION ${PROJECT_BINARY_DIR}/include)
endforeach(HEADER_FILE)
configure_file(${PROJECT_SOURCE_DIR}/include/MSTK_defines.h
${PROJECT_BINARY_DIR}/include/MSTK_defines.h @ONLY)
set(mstk_public_headers
${PROJECT_SOURCE_DIR}/include/MSTK.h
${PROJECT_SOURCE_DIR}/include/MSTK_types.h
${PROJECT_SOURCE_DIR}/include/MSTK_externs.h
${PROJECT_SOURCE_DIR}/include/MSTK_util.h
${PROJECT_BINARY_DIR}/include/MSTK_defines.h) # Note the PROJECT_BINARY_DIR
set_target_properties(${MSTKLIB} PROPERTIES PUBLIC_HEADER "${mstk_public_headers}")
##########################################################
# Export targets
##########################################################
# where to install library
install(TARGETS ${MSTKLIB}
EXPORT MSTKTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
PUBLIC_HEADER DESTINATION include
INCLUDES DESTINATION include
)
install(EXPORT MSTKTargets
FILE MSTKTargets.cmake
NAMESPACE mstk::
EXPORT_LINK_INTERFACE_LIBRARIES
DESTINATION lib/cmake/mstk
)
#######################################################
# 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. This will also
# include the MSTK targets which can be imported into another project
#######################################################
configure_file(${PROJECT_SOURCE_DIR}/cmake/MSTKConfig.cmake.in
${PROJECT_BINARY_DIR}/MSTKConfig.cmake @ONLY)
install(FILES ${PROJECT_BINARY_DIR}/MSTKConfig.cmake
DESTINATION lib/cmake/mstk)
#########################################################
# Also install any module files used for finding the dependencies
#########################################################
install(FILES
${PROJECT_SOURCE_DIR}/cmake/modules/FindMETIS.cmake
${PROJECT_SOURCE_DIR}/cmake/modules/FindZoltan.cmake
${PROJECT_SOURCE_DIR}/cmake/modules/FindExodusII.cmake
${PROJECT_SOURCE_DIR}/cmake/modules/FindnetCDF.cmake
DESTINATION lib/cmake/mstk/modules)
#######################################################
# Also write out a version file
#######################################################
include(CMakePackageConfigHelpers)
write_basic_package_version_file(MSTKConfigVersion.cmake
VERSION "${MSTK_VERSION_MAJOR}.${MSTK_VERSION_MINOR}.${MSTK_VERSION_PATCH}"
COMPATIBILITY SameMajorVersion
)
install(FILES ${PROJECT_BINARY_DIR}/MSTKConfigVersion.cmake
DESTINATION lib/cmake/mstk)