-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
323 lines (274 loc) · 10.3 KB
/
CMakeLists.txt
File metadata and controls
323 lines (274 loc) · 10.3 KB
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
cmake_minimum_required(VERSION 3.13.0)
project(meshfields VERSION 0.1.0 LANGUAGES CXX)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
option(MeshFields_USE_Cabana "Build with the Cabana storage backend" OFF)
find_package(Kokkos REQUIRED)
find_package(Omega_h REQUIRED)
find_package(MPI REQUIRED)
# Verify Omega_h was built with Kokkos enabled
if(NOT Omega_h_USE_Kokkos)
message(FATAL_ERROR "Omega_h must be built with Kokkos enabled (Omega_h_USE_Kokkos=ON)")
endif()
if(MeshFields_USE_Cabana)
find_package(Cabana 0.7.0 REQUIRED)
endif()
set(MESHFIELD_HEADERS
src/MeshField_Defines.hpp
src/MeshField_Utility.hpp
src/MeshField_Macros.hpp
src/KokkosController.hpp
src/MeshField_Element.hpp
src/MeshField_Integrate.hpp
src/MeshField_Shape.hpp
src/MeshField_ShapeField.hpp
src/MeshField_Fail.hpp
src/MeshField_For.hpp
src/MeshField_Reduce.hpp
src/MeshField_Scan.hpp
src/MeshField_Field.hpp
src/MeshField.hpp
src/MeshField_SPR_ErrorEstimator.hpp
"${CMAKE_CURRENT_BINARY_DIR}/MeshField_Config.hpp"
)
if(MeshFields_USE_Cabana)
list(APPEND MESHFIELD_HEADERS
src/CabanaController.hpp
src/MeshField_SimdFor.hpp)
endif()
set(MESHFIELD_SOURCES
src/MeshField_Fail.cpp
)
add_library(meshfields ${MESHFIELD_SOURCES})
target_compile_features(meshfields INTERFACE cxx_std_20)
target_include_directories(meshfields
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>" # for MeshField_Config.hpp
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_link_libraries(meshfields INTERFACE Kokkos::kokkos)
target_link_libraries(meshfields INTERFACE Omega_h::omega_h)
if(Kokkos_ENABLE_CUDA)
target_compile_options(meshfields INTERFACE "--expt-relaxed-constexpr")
endif()
#enable/disable exceptions
option(MeshFields_USE_EXCEPTIONS "Enable throwing exceptions" ON)
message(STATUS "Exceptions: ${MeshFields_USE_EXCEPTIONS}")
#pass cmake options to the source
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/src/MeshField_Config.hpp.in"
"${CMAKE_CURRENT_BINARY_DIR}/MeshField_Config.hpp")
if(MeshFields_USE_Cabana)
target_link_libraries(meshfields INTERFACE Cabana::Core)
target_compile_definitions(meshfields INTERFACE MESHFIELDS_ENABLE_CABANA)
endif()
#support ctags
option(MeshFields_USE_CTAGS "Generate Ctags" OFF)
if(MeshFields_USE_CTAGS)
#from: https://stackoverflow.com/a/9842046
set_source_files_properties(tags PROPERTIES GENERATED true)
add_custom_target(tags
COMMAND ctags -R --c++-kinds=+p --fields=+iaS --extra=+q
--exclude=docs --exclude=cmake --exclude=.git
--exclude=.github .
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_dependencies(meshfields tags)
endif()
# Set options for doxygen documentation
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY
)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile_internal.in
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_internal @ONLY
)
add_custom_target(docInternal
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_internal
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating Internal API documentation with Doxygen" VERBATIM
)
endif()
#Settings options for testing
enable_testing()
include(CTest)
option(MeshFields_IS_TESTING "Build for CTest" OFF)
message(STATUS "MeshFields_IS_TESTING: ${MeshFields_IS_TESTING}")
#check for valgrind
find_program(VALGRIND_CMD valgrind DOC "Location of the valgrind program")
#tests
function(test_func_impl TEST_NAME)
set(TEST_STR ${ARGN})
# need to run as a cmake script to capture assert and other 'system failures'
# https://cmake.org/cmake/help/latest/prop_test/WILL_FAIL.html#prop_test:WILL_FAIL
add_test(NAME ${TEST_NAME} COMMAND ${CMAKE_COMMAND} -E env ${TEST_STR})
if(TEST ${TEST_NAME})
set_property(TEST ${TEST_NAME} PROPERTY LABELS "meshfields::base")
endif()
endfunction(test_func_impl)
#smoke tests that are always enabled
function(smoke_test_func TEST_NAME)
test_func_impl(${TEST_NAME} ${ARGN})
if(TEST ${TEST_NAME})
set_property(TEST ${TEST_NAME} PROPERTY LABELS "meshfields::smoke")
endif()
endfunction(smoke_test_func)
function(test_func TEST_NAME)
if(MeshFields_IS_TESTING)
test_func_impl(${TEST_NAME} ${ARGN})
endif()
endfunction(test_func)
function(add_test_property TEST_NAME PROP)
if(TEST ${TEST_NAME})
set_property(TEST ${TEST_NAME} PROPERTY ${PROP} ${ARGN})
endif()
endfunction(add_test_property)
# Unlike test_func, will_fail_test_func assumes the command for the test will fail
function(will_fail_test_func TEST_NAME)
if(MeshFields_IS_TESTING)
test_func_impl(${TEST_NAME} ${ARGN})
set_property(TEST ${TEST_NAME} PROPERTY WILL_FAIL TRUE)
endif()
endfunction()
function(will_fail_valgrind_test_func TEST_NAME)
if(MeshFields_IS_TESTING)
if(VALGRIND_CMD)
test_func_impl(${TEST_NAME} ${VALGRIND_CMD} ${ARGN})
set_property(TEST ${TEST_NAME} PROPERTY
FAIL_REGULAR_EXPRESSION "Invalid read;Invalid write"
)
set_property(TEST ${TEST_NAME} PROPERTY WILL_FAIL TRUE)
endif()
endif()
endfunction()
#smoke executables are always built
function(meshfields_add_smoke_exe EXE_NAME EXE_SRC)
add_executable(${EXE_NAME} ${EXE_SRC})
target_link_libraries(${EXE_NAME} PRIVATE meshfields)
endfunction()
function(meshfields_add_exe EXE_NAME EXE_SRC)
if(MeshFields_IS_TESTING)
add_executable(${EXE_NAME} ${EXE_SRC})
target_link_libraries(${EXE_NAME} PRIVATE meshfields)
endif()
endfunction()
meshfields_add_smoke_exe(KokkosTests test/testKokkos.cpp)
meshfields_add_exe(SerializationTests test/testSerialize.cpp)
meshfields_add_exe(ElementTests test/testElement.cpp)
meshfields_add_exe(ElementJacobian1d test/testElementJacobian1d.cpp)
meshfields_add_exe(ElementJacobian2d test/testElementJacobian2d.cpp)
meshfields_add_exe(ElementJacobian3d test/testElementJacobian3d.cpp)
meshfields_add_exe(CountIntegrator test/testCountIntegrator.cpp)
meshfields_add_smoke_exe(OmegahTriTests test/testOmegahTri.cpp)
meshfields_add_exe(ExceptionTest test/testExceptions.cpp)
meshfields_add_exe(PointMapping test/testPointMapping.cpp)
meshfields_add_exe(OmegahTetTest test/testOmegahTet.cpp)
meshfields_add_exe(OmegahThwaitesSprAdapt test/testSprThwaitesAdapt.cpp)
if(MeshFields_USE_Cabana)
meshfields_add_exe(ControllerPerformance test/testControllerPerformance.cpp)
meshfields_add_smoke_exe(CabanaTests test/testCabana.cpp)
smoke_test_func(CabanaTests ./CabanaTests)
test_func(ControllerPerformance ./ControllerPerformance)
endif()
smoke_test_func(KokkosTests ./KokkosTests)
test_func(SerializationTests ./SerializationTests)
test_func(ElementTests ./ElementTests)
test_func(ElementJacobian1d ./ElementJacobian1d)
test_func(ElementJacobian2d ./ElementJacobian2d)
test_func(ElementJacobian3d ./ElementJacobian3d)
test_func(CountIntegrator ./CountIntegrator)
smoke_test_func(OmegahTriTests ./OmegahTriTests)
test_func(PointMapping ./PointMapping)
test_func(OmegahTetTest ./OmegahTetTest)
if(MeshFields_USE_EXCEPTIONS)
# exception caught - no error
test_func(ExceptionTest ./ExceptionTest)
else()
will_fail_test_func(ExceptionTest ./ExceptionTest)
endif()
meshfields_add_exe(OmegahSprAdapt test/testSprThwaitesAdapt.cpp)
test_func(OmegahSprAdapt ./OmegahSprAdapt
${CMAKE_SOURCE_DIR}/meshes/thwaites_basal_effectiveStrain.osh/
thwaitesAdapted #output prefix
0.1 # adapt ratio
1.0 # min size
16.0 # max size
)
add_test_property(OmegahSprAdapt
PASS_REGULAR_EXPRESSION
"afterAdapt nTri: 14439; solution_1 min -4084.78 max 213.322")
test_func(OmegahSprAdapt_p2
${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS}
./OmegahSprAdapt ${CMAKE_SOURCE_DIR}/meshes/thwaites_basal_effectiveStrain.osh/
thwaitesAdapted_p2 #output prefix
0.1 # adapt ratio
1.0 # min size
16.0 # max size
)
add_test_property(OmegahSprAdapt_p2
PASS_REGULAR_EXPRESSION
"afterAdapt nTri: 144[0-9][0-9]; solution_1 min -4098.9 max 213.322")
#Code Coverage set up -------------------------------------------------------
option(meshfields_ENABLE_COVERAGE_BUILD "Do a coverage build" OFF)
if(meshfields_ENABLE_COVERAGE_BUILD)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
include(CodeCoverage)
append_coverage_compiler_flags()
set(LCOV_SYSTEM_EXCLUDE_PATHS "" CACHE PATH "Set path to system libraries, c++ compiler and cuda-11.4 by default, to be excluded from lcov analysis")
if (NOT EXISTS ${Kokkos_DIR})
message(FATAL_ERROR " Kokkos_DIR was not set or the path does not exist")
endif()
if (NOT EXISTS ${Omega_h_DIR})
message(FATAL_ERROR " Omega_h_DIR was not set or the path does not exist")
endif()
set(LCOV_SRC_EXCLUDE_PATHS
"${Kokkos_DIR}/*"
"${Omega_h_DIR}/*"
"${LCOV_SYSTEM_EXCLUDE_PATHS}"
)
if (MeshFields_USE_Cabana AND NOT EXISTS ${Cabana_DIR})
message(FATAL_ERROR " Cabana_DIR was not set or the path does not exist")
endif()
if (MeshFields_USE_Cabana)
list(APPEND LCOV_SRC_EXCLUDE_PATHS "${Cabana_DIR}")
endif()
setup_target_for_coverage_lcov(
NAME coverage
EXECUTABLE ctest -C ${ROOT_DIR}/CTestTestfile.cmake
EXCLUDE ${LCOV_SRC_EXCLUDE_PATHS}
)
endif()
#Code Coverage set up end ------------------------------------------------
## export the library
set_target_properties(meshfields PROPERTIES PUBLIC_HEADER "${MESHFIELD_HEADERS}")
install(
TARGETS meshfields
EXPORT meshfields-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/meshfields-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/meshfields
)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/meshfields-config-version.cmake"
COMPATIBILITY AnyNewerVersion)
install(FILES
"${PROJECT_BINARY_DIR}/meshfields-config.cmake"
"${PROJECT_BINARY_DIR}/meshfields-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/meshfields)
install(
EXPORT meshfields-targets
NAMESPACE meshfields::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/meshfields)