-
Notifications
You must be signed in to change notification settings - Fork 33
/
CMakeLists.txt
220 lines (178 loc) · 7.48 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
# Copyright (c) 2019-2024, Lawrence Livermore National Security, LLC and
# other Serac Project Developers. See the top-level LICENSE file for
# details.
#
# SPDX-License-Identifier: (BSD-3-Clause)
#------------------------------------------------------------------------------
# Basic CMake Setup
#------------------------------------------------------------------------------
# Do not bump this over 3.14 due to it changing CMake policies and breaking
# the CUDA build. We check the required version specifically for this below
cmake_minimum_required(VERSION 3.14)
# Check for minimum CMake version required w/o changing policies like cmake_minimum_required
if(ENABLE_CUDA AND ${CMAKE_VERSION} VERSION_LESS 3.18.0)
message(FATAL_ERROR "Serac requires CMake version 3.18.0+ when CUDA is enabled.")
endif()
project(serac LANGUAGES CXX C)
# MPI is required in Serac.
# Note: for the style only mode, which doesn't need to actually build, we need to ignore this
if (NOT SERAC_STYLE_CI_ONLY)
set(ENABLE_MPI ON CACHE BOOL "")
if (NOT MPI_C_COMPILER OR NOT MPI_CXX_COMPILER)
message(FATAL_ERROR
"Serac requires MPI. It is required to provide the MPI C/C++ "
"compiler wrappers via the CMake variables, "
"MPI_C_COMPILER and MPI_CXX_COMPILER.")
endif()
endif()
# Save off "raw" flags before they are modified by serac/BLT
set(RAW_CMAKE_C_FLAGS ${CMAKE_C_FLAGS} CACHE STRING "")
set(RAW_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} CACHE STRING "")
if (NOT DEFINED SERAC_ENABLE_CODEVELOP)
set(SERAC_ENABLE_CODEVELOP OFF)
endif()
message(STATUS "Serac Codevelop Build: ${SERAC_ENABLE_CODEVELOP}")
if(NOT DEFINED SERAC_SOURCE_DIR)
set(SERAC_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "")
endif()
message(STATUS "Serac Source Dir: ${SERAC_SOURCE_DIR}")
# For HIP case, this flag prevents the following Strumpack linker error:
# undefined symbol: mpi_abort_
if(SERAC_ENABLE_CODEVELOP OR (ENABLE_HIP AND STRUMPACK_DIR))
set(ENABLE_FORTRAN ON CACHE BOOL "")
endif()
#------------------------------------------------------------------------------
# Setup BLT
#------------------------------------------------------------------------------
if(DEFINED BLT_SOURCE_DIR)
# Support having a shared BLT outside of the repository if given a BLT_SOURCE_DIR
if(NOT EXISTS ${BLT_SOURCE_DIR}/SetupBLT.cmake)
message(FATAL_ERROR "Given BLT_SOURCE_DIR does not contain SetupBLT.cmake")
endif()
else()
set(BLT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/cmake/blt" CACHE PATH "")
if (NOT EXISTS ${BLT_SOURCE_DIR}/SetupBLT.cmake)
message(FATAL_ERROR
"The BLT is not present. "
"Either run the following two commands in your git repository: \n"
" git submodule init\n"
" git submodule update\n"
"Or add -DBLT_SOURCE_DIR=/path/to/blt to your CMake command." )
endif()
endif()
# Tune BLT to our needs
if (NOT BLT_CXX_STD)
set(BLT_CXX_STD "c++17" CACHE STRING "")
endif()
# These BLT tools are not used in Serac, turn them off
set(_unused_blt_tools
CLANGQUERY
VALGRIND
ASTYLE
CMAKEFORMAT
UNCRUSTIFY
YAPF)
foreach(_tool ${_unused_blt_tools})
set(ENABLE_${_tool} OFF CACHE BOOL "")
endforeach()
# These BLT tools are only used by Serac developers, so turn them off
# unless an explicit executable path is given
set(_used_blt_tools
CLANGFORMAT
CLANGTIDY
CPPCHECK
DOXYGEN
SPHINX)
foreach(_tool ${_used_blt_tools})
if(NOT ${_tool}_EXECUTABLE)
set(ENABLE_${_tool} OFF CACHE BOOL "")
else()
set(ENABLE_${_tool} ON CACHE BOOL "")
endif()
endforeach()
set(BLT_REQUIRED_CLANGFORMAT_VERSION "14" CACHE STRING "")
set(ENABLE_ALL_WARNINGS ON CACHE BOOL "")
set(ENABLE_WARNINGS_AS_ERRORS ON CACHE BOOL "")
set(BLT_EXPORT_THIRDPARTY OFF CACHE BOOL "")
if (BLT_EXPORT_THIRDPARTY)
message(FATAL_ERROR "Serac does not use BLT's exporting of TPLs, it conflicts with the new blt_install_tpl_setups macro.")
endif()
include(${BLT_SOURCE_DIR}/SetupBLT.cmake)
#------------------------------------------------------------------------------
# Setup Macros/Basics
#------------------------------------------------------------------------------
include(${PROJECT_SOURCE_DIR}/cmake/SeracMacros.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/SeracBasics.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/SeracCompilerFlags.cmake)
#------------------------------------------------------------------------------
# Add Code Checks
#------------------------------------------------------------------------------
message(STATUS "Serac Code Checks: ${SERAC_ENABLE_CODE_CHECKS}")
# Add extra file extensions for code styling
# Note: Add them also to serac_add_code_checks in cmake/SeracMacros.cmake
# CUDA
list(APPEND BLT_C_FILE_EXTS ".cuh")
# Configured C++ files
list(APPEND BLT_C_FILE_EXTS ".cpp.in" ".hpp.in")
if (SERAC_STYLE_CI_ONLY OR SERAC_ENABLE_CODE_CHECKS)
serac_add_code_checks(PREFIX serac)
endif()
if (SERAC_STYLE_CI_ONLY)
# Exit processing the rest of the build in style only build to avoid any possible
# CMake configuration issues outside of just enabling `make style`. This build,
# is not capable of building Serac and should not be advertised. It is for CI
# purposes only.
return()
endif()
#------------------------------------------------------------------------------
# Setup Dependencies
#------------------------------------------------------------------------------
# Restore raw compiler flags so subprojects don't end up using Serac's flags
set(SERAC_CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
set(SERAC_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
set(CMAKE_C_FLAGS ${RAW_CMAKE_C_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS ${RAW_CMAKE_CXX_FLAGS} CACHE STRING "" FORCE)
include(${PROJECT_SOURCE_DIR}/cmake/thirdparty/SetupSeracThirdParty.cmake)
set(CMAKE_C_FLAGS ${SERAC_CMAKE_C_FLAGS})
set(CMAKE_CXX_FLAGS ${SERAC_CMAKE_CXX_FLAGS})
include(${PROJECT_SOURCE_DIR}/cmake/SeracConfigHeader.cmake)
#------------------------------------------------------------------------------
# Add subdirectories
#------------------------------------------------------------------------------
add_subdirectory(src)
add_subdirectory(examples)
#------------------------------------------------------------------------------
# Generate helper script for running ATS
#------------------------------------------------------------------------------
configure_file(
${PROJECT_SOURCE_DIR}/scripts/testing/ats.sh.in
${CMAKE_BINARY_DIR}/ats.sh)
#------------------------------------------------------------------------------
# Export Targets
#------------------------------------------------------------------------------
set(exported_targets
serac_infrastructure
serac_mesh
serac_numerics
serac_physics)
add_library(serac INTERFACE)
target_link_libraries(serac INTERFACE ${exported_targets})
install(TARGETS serac
EXPORT serac-targets
DESTINATION lib
)
if (SERAC_ENABLE_CODEVELOP)
# This really shouldn't be needed but it keeps getting dropped from axom.
# It certainly shouldn't go here either.
target_include_directories(axom SYSTEM INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/axom/src>
)
install(TARGETS mfem ${axom_exported_targets} ${tribol_exported_targets}
EXPORT serac-targets
DESTINATION lib
)
endif()
install(EXPORT serac-targets
NAMESPACE serac::
DESTINATION lib/cmake
)