forked from LLNL/serac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
198 lines (160 loc) · 6.46 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
# Copyright (c) 2019-2022, 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
#------------------------------------------------------------------------------
if(ENABLE_CUDA)
cmake_minimum_required(VERSION 3.18)
else()
cmake_minimum_required(VERSION 3.14)
endif()
project(serac LANGUAGES CXX C)
# MPI is required in Serac.
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()
# 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}")
#------------------------------------------------------------------------------
# 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 "10" CACHE STRING "")
set(ENABLE_BENCHMARKS OFF CACHE BOOL "")
set(ENABLE_ALL_WARNINGS ON CACHE BOOL "")
set(ENABLE_WARNINGS_AS_ERRORS ON CACHE BOOL "")
# Allows MPI/CUDA/etc targets to be exported in the serac namespace
set(BLT_EXPORT_THIRDPARTY ON CACHE BOOL "")
include(${BLT_SOURCE_DIR}/SetupBLT.cmake)
#------------------------------------------------------------------------------
# Setup Macros and dependencies
#------------------------------------------------------------------------------
include(${PROJECT_SOURCE_DIR}/cmake/SeracMacros.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/SeracBasics.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/SeracCompilerFlags.cmake)
# 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)
#------------------------------------------------------------------------------
# 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_ENABLE_CODE_CHECKS)
serac_add_code_checks(PREFIX serac
INCLUDES /src/ /tests/
EXCLUDES /axom/ cmake/blt /mfem/ uberenv_libs)
endif()
#------------------------------------------------------------------------------
# Export Targets
#------------------------------------------------------------------------------
set(exported_targets
serac_coefficients
serac_physics
serac_infrastructure
serac_numerics
serac_physics_integrators)
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 PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/axom/src>
)
# Add Axom's targets to our export set
# TODO: we should ask Axom for this list in the future
set(axom_exported_targets axom cli11 fmt hdf5 lua sol sparsehash)
blt_list_append(TO axom_exported_targets ELEMENTS openmp IF ENABLE_OPENMP)
install(TARGETS ${axom_exported_targets}
EXPORT serac-targets
DESTINATION lib
)
endif()
install(EXPORT serac-targets
NAMESPACE serac::
DESTINATION lib/cmake
)