-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
436 lines (391 loc) · 14.8 KB
/
CMakeLists.txt
File metadata and controls
436 lines (391 loc) · 14.8 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
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
cmake_minimum_required(VERSION 3.25)
project(hermes-3 LANGUAGES CXX C)
# Extra CMake scripts in cmake/ subdirectory
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
option(HERMES_UPDATE_GIT_SUBMODULE
"Check submodules are up-to-date during build" ON)
# Adapted from
# https://cliutils.gitlab.io/modern-cmake/chapters/projects/submodule.html
# Update submodules as needed
function(hermes_update_submodules)
if(NOT HERMES_UPDATE_GIT_SUBMODULE)
return()
endif()
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
message(STATUS "Submodule update")
execute_process(
COMMAND ${GIT_EXECUTABLE} -c submodule.recurse=false submodule update
--init --recursive
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(
FATAL_ERROR
"git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules"
)
endif()
endif()
endfunction()
hermes_update_submodules()
# Get the Git revision
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC HERMES_REVISION)
if(HERMES_REVISION STREQUAL "GITDIR-NOTFOUND")
set(HERMES_REVISION "Unknown")
endif()
message(STATUS "Git revision: ${HERMES_REVISION}")
# BOUT++ is a dependency
option(HERMES_BUILD_BOUT "Build BOUT++ in external/BOUT-dev" ON)
if(HERMES_BUILD_BOUT)
set(BOUT_BUILD_EXAMPLES, OFF) # Don't create example makefiles
set(HERMES_BOUT_SRC
"external/BOUT-dev"
CACHE STRING "Directory of BOUT++ dir")
add_subdirectory(${HERMES_BOUT_SRC}
${CMAKE_CURRENT_BINARY_DIR}/external/BOUT-dev SYSTEM)
else()
find_package(bout++ REQUIRED)
endif()
include("./cmake/Sanitizers.cmake")
set(HERMES_SOURCES
src/amjuel_reaction.cxx
src/braginskii_collisions.cxx
src/braginskii_conduction.cxx
src/braginskii_electron_viscosity.cxx
src/braginskii_friction.cxx
src/braginskii_heat_exchange.cxx
src/braginskii_thermal_force.cxx
src/braginskii_ion_viscosity.cxx
src/classical_diffusion.cxx
src/component.cxx
src/component_scheduler.cxx
src/ionisation.cxx
src/div_ops.cxx
src/neutral_mixed.cxx
src/neutral_full_velocity.cxx
src/electromagnetic.cxx
src/electron_force_balance.cxx
src/evolve_density.cxx
src/evolve_energy.cxx
src/evolve_pressure.cxx
src/evolve_momentum.cxx
src/guarded_options.cxx
src/isothermal.cxx
src/quasineutral.cxx
src/diamagnetic_drift.cxx
src/recalculate_metric.cxx
src/relax_potential.cxx
src/sheath_closure.cxx
src/sheath_boundary.cxx
src/sheath_boundary_simple.cxx
src/sheath_boundary_insulating.cxx
src/snb_conduction.cxx
src/fixed_fraction_ions.cxx
src/sound_speed.cxx
src/zero_current.cxx
src/anomalous_diffusion.cxx
src/binormal_stpm.cxx
src/recycling.cxx
src/adas_reaction.cxx
src/noflow_boundary.cxx
src/neutral_parallel_diffusion.cxx
src/neutral_boundary.cxx
src/permissions.cxx
src/polarisation_drift.cxx
src/solkit_neutral_parallel_diffusion.cxx
src/solkit_hydrogen_charge_exchange.cxx
src/upstream_density_feedback.cxx
src/temperature_feedback.cxx
src/detachment_controller.cxx
src/reaction.cxx
src/reaction_parser.cxx
src/transform.cxx
src/vorticity.cxx
include/adas_reaction.hxx
include/adas_carbon.hxx
include/adas_neon.hxx
include/amjuel_helium.hxx
include/amjuel_hydrogen.hxx
include/amjuel_reaction.hxx
include/anomalous_diffusion.hxx
include/classical_diffusion.hxx
include/binormal_stpm.hxx
include/braginskii_collisions.hxx
include/braginskii_conduction.hxx
include/braginskii_electron_viscosity.hxx
include/braginskii_friction.hxx
include/braginskii_heat_exchange.hxx
include/braginskii_ion_viscosity.hxx
include/braginskii_thermal_force.hxx
include/component.hxx
include/component_scheduler.hxx
include/diamagnetic_drift.hxx
include/div_ops.hxx
include/electromagnetic.hxx
include/electron_force_balance.hxx
include/evolve_density.hxx
include/evolve_energy.hxx
include/evolve_momentum.hxx
include/evolve_pressure.hxx
include/fixed_density.hxx
include/fixed_fraction_ions.hxx
include/fixed_velocity.hxx
include/guarded_options.hxx
include/neutral_full_velocity.hxx
include/hermes_utils.hxx
include/hydrogen_charge_exchange.hxx
include/solkit_hydrogen_charge_exchange.hxx
include/integrate.hxx
include/ionisation.hxx
include/neutral_boundary.hxx
include/neutral_mixed.hxx
include/neutral_parallel_diffusion.hxx
include/solkit_neutral_parallel_diffusion.hxx
include/noflow_boundary.hxx
include/permissions.hxx
include/polarisation_drift.hxx
include/quasineutral.hxx
include/reaction.hxx
include/recalculate_metric.hxx
include/recycling.hxx
include/relax_potential.hxx
include/sheath_boundary.hxx
include/sheath_boundary_simple.hxx
include/sheath_boundary_insulating.hxx
include/simple_conduction.hxx
include/snb_conduction.hxx
include/sheath_closure.hxx
include/sound_speed.hxx
include/upstream_density_feedback.hxx
include/temperature_feedback.hxx
include/detachment_controller.hxx
include/vorticity.hxx
include/zero_current.hxx
include/transform.hxx
include/fixed_fraction_radiation.hxx
include/simple_pump.hxx)
# Compile Hermes sources into a library, which can be used for unit tests
add_library(hermes-3-lib ${HERMES_SOURCES})
target_link_libraries(hermes-3-lib PRIVATE bout++::bout++)
target_compile_features(hermes-3-lib PUBLIC cxx_std_17)
set_target_properties(hermes-3-lib PROPERTIES CXX_EXTENSIONS OFF)
target_include_directories(
hermes-3-lib
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>)
# Have hermes-3-lib look for dynamic libs in ./ before searching elsewhere
set_target_properties(hermes-3-lib PROPERTIES BUILD_RPATH "$ORIGIN")
enable_sanitizers(hermes-3-lib)
# The main executable target
add_executable(hermes-3 hermes-3.cxx
${CMAKE_CURRENT_BINARY_DIR}/include/revision.hxx)
target_link_libraries(hermes-3 PRIVATE bout++::bout++ hermes-3-lib)
target_include_directories(
hermes-3
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>)
# Have hermes-3 look for dynamic libs in ./ before searching elsewhere
set_target_properties(hermes-3 PROPERTIES BUILD_RPATH "$ORIGIN")
option(HERMES_ENABLE_WARNINGS "Enable compiler warnings"
${PROJECT_IS_TOP_LEVEL})
option(HERMES_ERROR_ON_WARNINGS "Enable compiler warnings" OFF)
include(CompilerWarnings)
add_library(hermes_warnings INTERFACE)
hermes_set_project_warnings(hermes_warnings ${HERMES_ERROR_ON_WARNINGS} "" ""
"" "")
if(HERMES_ENABLE_WARNINGS)
target_link_libraries(hermes-3-lib PRIVATE hermes_warnings)
target_link_libraries(hermes-3 PRIVATE hermes_warnings)
endif()
# Build the file containing just the commit hash This will be rebuilt on every
# commit!
configure_file("${PROJECT_SOURCE_DIR}/include/revision.hxx.in"
"${PROJECT_BINARY_DIR}/include/revision.hxx")
# Once built, copy the data and test directories
option(HERMES_COPY_EXAMPLES_TO_BUILD "Copy the examples to the build directory"
ON)
option(HERMES_COPY_JSON_DATABASE_TO_BUILD
"Copy the json database to the build directory" ON)
if(HERMES_COPY_EXAMPLES_TO_BUILD OR HERMES_COPY_JSON_DATABASE_TO_BUILD)
add_custom_target(setup-examples ALL)
else()
add_custom_target(setup-examples)
endif()
# Tests
option(HERMES_COPY_TESTS_TO_BUILD "Copy the tests to the build directory" ON)
option(HERMES_TESTS "Build the tests" ON)
if(HERMES_COPY_TESTS_TO_BUILD OR HERMES_TESTS)
add_custom_target(setup-test ALL)
else()
add_custom_target(setup-test)
endif()
# copy the data and test directories
add_custom_command(
TARGET setup-examples
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/examples
$<TARGET_FILE_DIR:${PROJECT_NAME}>/examples)
add_custom_command(
TARGET setup-examples
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/json_database
$<TARGET_FILE_DIR:${PROJECT_NAME}>/json_database)
add_custom_command(
TARGET setup-test
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/tests
$<TARGET_FILE_DIR:${PROJECT_NAME}>/tests)
if(HERMES_TESTS)
enable_testing()
# Integrated tests
function(hermes_add_integrated_test TESTNAME)
set(oneValueArgs DOWNLOAD DOWNLOAD_NAME)
set(multiValueArgs REQUIRES CONFLICTS)
cmake_parse_arguments(HERMES_TEST_OPTIONS "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN})
foreach(REQUIREMENT IN LISTS HERMES_TEST_OPTIONS_REQUIRES)
if(NOT ${REQUIREMENT})
message(
STATUS
"Not building test ${TESTNAME}, requirement not met: ${REQUIREMENT}"
)
return()
endif()
endforeach()
foreach(CONFLICT IN LISTS HERMES_TEST_OPTIONS_CONFLICTS)
if(${CONFLICT})
message(
STATUS "Not building test ${TESTNAME}, conflicts with: ${CONFLICT}")
return()
endif()
message(STATUS "CONFLICT ${CONFLICT} ${${CONFLICT}}")
endforeach()
if(HERMES_COPY_TESTS_TO_BUILD)
set(INT_TEST_SRC ${CMAKE_CURRENT_SOURCE_DIR}/tests/integrated/${TESTNAME})
set(INT_TEST_DEST
${CMAKE_CURRENT_BINARY_DIR}/tests/integrated/${TESTNAME})
# Make copies of the test exec and input file in the build directory and
# keep them up to date
configure_file(${INT_TEST_SRC}/runtest ${INT_TEST_DEST}/runtest COPYONLY)
configure_file(${INT_TEST_SRC}/data/BOUT.inp
${INT_TEST_DEST}/data/BOUT.inp COPYONLY)
else()
set(INT_TEST_DEST
${CMAKE_CURRENT_SOURCE_DIR}/tests/integrated/${TESTNAME})
endif()
add_test(
NAME ${TESTNAME}
WORKING_DIRECTORY ${INT_TEST_DEST}
COMMAND runtest)
set_tests_properties(${TESTNAME} PROPERTIES LABELS integration)
if(HERMES_TEST_OPTIONS_DOWNLOAD)
if(NOT HERMES_TEST_OPTIONS_DOWNLOAD_NAME)
message(FATAL_ERROR "We need DOWNLOAD_NAME if we should DOWNLOAD!")
endif()
file(REAL_PATH ${HERMES_TEST_OPTIONS_DOWNLOAD_NAME} DOWNLOAD_DEST_PATH
BASE_DIRECTORY ${INT_TEST_DEST})
add_custom_command(
OUTPUT ${HERMES_TEST_OPTIONS_DOWNLOAD_NAME}
COMMAND wget -nv ${HERMES_TEST_OPTIONS_DOWNLOAD} -O
${HERMES_TEST_OPTIONS_DOWNLOAD_NAME}
WORKING_DIRECTORY ${INT_TEST_DEST}
COMMENT "Downloading test data to ${DOWNLOAD_DEST_PATH}")
# Custom target to run download command; use sanitised absolute path for
# the target name
string(REPLACE "/" "_" DOWNLOAD_TARGET_NAME ${DOWNLOAD_DEST_PATH})
add_custom_target(
${DOWNLOAD_TARGET_NAME} ALL
DEPENDS ${HERMES_TEST_OPTIONS_DOWNLOAD_NAME}
DEPENDS setup-test)
endif()
endfunction()
hermes_add_integrated_test(1D-fluid)
hermes_add_integrated_test(1D-recycling)
hermes_add_integrated_test(1D-recycling-dthe)
hermes_add_integrated_test(diffusion)
hermes_add_integrated_test(evolve_density)
hermes_add_integrated_test(neutral_mixed)
hermes_add_integrated_test(vorticity)
hermes_add_integrated_test(sod-shock)
hermes_add_integrated_test(sod-shock-energy)
hermes_add_integrated_test(drift-wave)
hermes_add_integrated_test(alfven-wave)
hermes_add_integrated_test(collfreq-braginskii-afn)
hermes_add_integrated_test(collfreq-multispecies)
hermes_add_integrated_test(2D-production)
hermes_add_integrated_test(2D-energy)
hermes_add_integrated_test(2D-recycling)
# Unit tests
option(HERMES_UNIT_TESTS "Build the unit tests" ON)
if(HERMES_UNIT_TESTS)
if(NOT PACKAGE_TESTS)
# Not running BOUT++ tests Since BOUT++ includes googletest, adding it
# again causes errors
add_subdirectory(external/googletest)
endif()
file(GLOB_RECURSE TEST_SOURCES tests/unit/test_*.cxx)
add_executable(hermes_unit_tests tests/unit/main.cxx ${TEST_SOURCES})
target_link_libraries(hermes_unit_tests PRIVATE hermes_warnings)
add_test(NAME hermes_unit_tests COMMAND hermes_unit_tests)
set_tests_properties(hermes_unit_tests PROPERTIES LABELS unit)
target_link_libraries(hermes_unit_tests PRIVATE gtest bout++::bout++
hermes-3-lib)
# Have hermes_unit_tests look for dynamic libs in ./ before searching
# elsewhere
set_target_properties(hermes_unit_tests PROPERTIES BUILD_RPATH "$ORIGIN")
endif()
# Method of manufactured solutions (MMS) tests of operators
option(HERMES_DIVOPS_MMS_TESTS "Build the differential operator MMS tests" ON)
if(HERMES_DIVOPS_MMS_TESTS)
# TEST_SOURCES=
add_executable(hermes_mms_operator_tests tests/mms_operator/main.cxx)
# ${TEST_SOURCES})
target_link_libraries(hermes_mms_operator_tests
PRIVATE gtest bout++::bout++ hermes-3-lib)
add_test(
NAME differential_operators_mms_orthogonal
WORKING_DIRECTORY tests/mms_operator/
COMMAND python3 orthogonal_test.py)
set_tests_properties(differential_operators_mms_orthogonal
PROPERTIES LABELS integration)
add_test(
NAME differential_operators_mms_nonorthogonal
WORKING_DIRECTORY tests/mms_operator/
COMMAND python3 nonorthogonal_test.py)
set_tests_properties(differential_operators_mms_nonorthogonal
PROPERTIES LABELS integration)
add_test(
NAME rhs_mms_neutral_mixed
WORKING_DIRECTORY tests/mms_operator/
COMMAND python3 neutral_mixed_ddt_test.py)
set_tests_properties(rhs_mms_neutral_mixed PROPERTIES LABELS integration)
endif()
endif()
# Compile-time options
set(SLOPE_LIMITERS MinMod MC Upwind Superbee)
set(HERMES_SLOPE_LIMITER
MC
CACHE STRING "Set advection slope limiter")
set_property(CACHE HERMES_SLOPE_LIMITER PROPERTY STRINGS ${SLOPE_LIMITERS})
message(STATUS "Slope limiter: ${HERMES_SLOPE_LIMITER}")
# Generate the build config header
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include/hermes_build_config.hxx")
# If we do in source builds, this is fine
if(NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
message(
FATAL_ERROR
"Generated hermes_build_config.hxx header already exists; please remove '${CMAKE_CURRENT_SOURCE_DIR}/include/hermes_build_config.hxx' before continuing"
)
endif()
endif()
configure_file(include/hermes_build_config.hxx.in
include/hermes_build_config.hxx)
# Installation
if(BUILD_SHARED_LIBS)
install(TARGETS hermes-3 hermes-3-lib)
else()
install(TARGETS hermes-3)
endif()