forked from lanl/singularity-eos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
497 lines (420 loc) · 17.3 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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# ------------------------------------------------------------------------------#
# © 2021-2023. Triad National Security, LLC. All rights reserved. This program
# was produced under U.S. Government contract 89233218CNA000001 for Los Alamos
# National Laboratory (LANL), which is operated by Triad National Security, LLC
# for the U.S. Department of Energy/National Nuclear Security Administration.
# All rights in the program are reserved by Triad National Security, LLC, and
# the U.S. Department of Energy/National Nuclear Security Administration. The
# Government is granted for itself and others acting on its behalf a
# nonexclusive, paid-up, irrevocable worldwide license in this material to
# reproduce, prepare derivative works, distribute copies to the public, perform
# publicly and display publicly, and to permit others to do so.
# ------------------------------------------------------------------------------#
cmake_minimum_required(VERSION 3.19)
# Disable "in-source" builds
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(
FATAL_ERROR
"ERROR: Will not configure \"in-source\" builds. Create a seperate directory for building"
)
endif()
# declare the project name
project(
singularity-eos
VERSION 1.8.0
LANGUAGES NONE)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
set(SINGULARITY_GOLDFILES_VERSION "goldfiles-1.6.2")
set(SINGULARITY_GOLDFILE_HASH
33ef74b29937cc1347b525f72662933dd2b0556550f6541f97fc1de8a01c3c2a)
# ------------------------------------------------------------------------------#
# Options
# ------------------------------------------------------------------------------#
include(CMakeDependentOption)
# dependcy options
option(SINGULARITY_USE_SPINER "Use spiner EOS" OFF)
cmake_dependent_option(
SINGULARITY_USE_SPINER_WITH_HDF5 "Use HDF5 component of spiner" ON
"SINGULARITY_USE_SPINER" OFF)
option(SINGULARITY_USE_FORTRAN "Enable fortran bindings" ON)
option(SINGULARITY_USE_KOKKOS "Use Kokkos for portability" OFF)
option(SINGULARITY_USE_EOSPAC "Enable eospac backend" OFF)
# TODO This should be dependent option (or fortran option)
option(SINGULARITY_BUILD_CLOSURE "Mixed Cell Closure" ON)
cmake_dependent_option(SINGULARITY_USE_CUDA "Use CUDA backend of Kokkos" OFF
"SINGULARITY_USE_KOKKOS" OFF)
cmake_dependent_option(
SINGULARITY_USE_KOKKOSKERNELS "Use KokkosKernels for LA routines" ON
"SINGULARITY_USE_KOKKOS;SINGULARITY_BUILD_CLOSURE" OFF)
# extra build options
option(SINGULARITY_BUILD_PYTHON "Compile Python bindings" OFF)
option(SINGULARITY_BUILD_EXAMPLES "Compile examples" OFF)
cmake_dependent_option(
SINGULARITY_BUILD_SESAME2SPINER
"Compile sesame2spiner"
ON
"SINGULARITY_USE_SPINER;SINGULARITY_USE_SPINER_WITH_HDF5;SINGULARITY_USE_EOSPAC"
OFF)
cmake_dependent_option(
SINGUALRITY_BUILD_STELLARCOLLAPSE2SPINER "Compile stellarcollapse2spiner" ON
"SINGULARITY_USE_SPINER;SINGULARITY_USE_SPINER_WITH_HDF5" OFF)
cmake_dependent_option(
SINGULARITY_USE_HELMHOLTZ "Include Helmholtz equation of state" OFF
"SINGULARITY_USE_SPINER;SINGULARITY_USE_SPINER_WITH_HDF5" OFF)
# testing options
option(SINGULARITY_BUILD_TESTS "Compile tests" OFF)
cmake_dependent_option(
SINGULARITY_TEST_SESAME "Test Sesame table readers" ON
"SINGULARITY_BUILD_TESTS;SINGULARITY_BUILD_SESAME2SPINER" OFF)
cmake_dependent_option(
SINGULARITY_TEST_STELLAR_COLLAPSE "Test stellar collapse table readers" ON
"SINGULARITY_BUILD_TESTS;SINGUALRITY_BUILD_STELLARCOLLAPSE2SPINER" OFF)
cmake_dependent_option(SINGULARITY_TEST_PYTHON "Test the Python bindings" ON
"SINGULARITY_BUILD_TESTS;SINGULARITY_BUILD_PYTHON" OFF)
cmake_dependent_option(
SINGULARITY_TEST_HELMHOLTZ "Test the Helmholtz equation of state" ON
"SINGULARITY_BUILD_TESTS;SINGULARITY_USE_HELMHOLTZ" OFF)
# modify flags options
option(SINGULARITY_BETTER_DEBUG_FLAGS "Better debug flags for singularity" ON)
option(SINGULARITY_HIDE_MORE_WARNINGS "hide more warnings" OFF)
# toggle code options
option(SINGULARITY_USE_SINGLE_LOGS
"Use single precision logs. Can harm accuracy." OFF)
option(SINGULARITY_USE_TRUE_LOG_GRIDDING
"Use grids that conform to log spacing." OFF)
# TODO(JMM): Should this automatically be activated when true log gridding is
# off?
cmake_dependent_option(
SINGULARITY_USE_HIGH_RISK_MATH
"Use integer aliased logs, may not be portable" OFF
"NOT SINGULARITY_USE_TRUE_LOG_GRIDDING" OFF)
# misc options
option(SINGULARITY_FORCE_SUBMODULE_MODE "Submodule mode" OFF)
# TODO This is an edge-case, but still used (e.g. github CI), but need to work
# out a way to do SUBMODULE_MODE (use submodules for upstream deps) but also do
# a proper install (FORCE_ disables the install/export stages). I may come back
# to this, but there isn't a lot of clamoring for this right now so could return
# to it in a later PR. something like
# cmake_dependent_option(SINGULARITY_SUBMODULE_MODE_INSTALL ...)
# TODO This should depend on using offloading (`SINGULARITY_USE_CUDA` &t) Also,
# patching in the source tree is messy, this should be done in the build dir
option(SINGULARITY_PATCH_MPARK_VARIANT
"Apply GPU patch to mpark-variant submodule" ON)
# Plugins
set(SINGULARITY_PLUGINS "" CACHE STRING "List of paths to plugin directories")
set(SINGULARITY_VARIANT "singularity-eos/eos/default_variant.hpp" CACHE STRING
"The include path for the file containing the definition of singularity::EOS.")
# ------------------------------------------------------------------------------#
# singularity-eos Library
# ------------------------------------------------------------------------------#
include(singularity-eos/mpark_variant)
include(singularity-eos/Eigen3)
include(singularity-eos/eospac)
include(singularity-eos/hdf5)
include(singularity-eos/kokkos)
include(singularity-eos/spiner)
include(singularity-eos/ports-of-call)
add_library(singularity-eos)
add_library(singularity-eos::singularity-eos ALIAS singularity-eos)
# ?
target_include_directories(singularity-eos
PUBLIC $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>)
# ------------------------------------------------------------------------------#
# Compiler & language setup
# ------------------------------------------------------------------------------#
enable_language(CXX)
include(CMakeDetermineCXXCompiler)
enable_language(C)
include(CMakeDetermineCCompiler)
if(SINGULARITY_USE_FORTRAN)
enable_language(Fortran)
include(CMakeDetermineFortranCompiler)
endif()
include(GNUInstallDirs)
if(SINGULARITY_BUILD_PYTHON)
# need position independent code for Python shared library
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
# checks if this is our build, or we've been imported via `add_subdirectory` NB:
# this should make the `option(SINGULARITY_SUBMODULE_MODE ...)` unnecessary
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
else()
message(
STATUS
"Detected that `singularity-eos` is a subproject, will configure build in submodule mode"
)
set(SINGULARITY_SUBMODULE_MODE ON)
endif()
if(SINGULARITY_FORCE_SUBMODULE_MODE)
message(STATUS "Building as though project was a submodule.")
set(SINGULARITY_SUBMODULE_MODE ON)
endif()
# Use to determine if Eigen is used or not
set(SINGULARITY_USE_EIGEN
OFF
CACHE BOOL "" FORCE)
if(SINGULARITY_BUILD_CLOSURE AND NOT SINGULARITY_USE_KOKKOSKERNELS)
if(SINGULARITY_USE_CUDA)
message(
FATAL_ERROR
"\"SINGULARITY_BUILD_CLOSURE=ON\" and \"SINGULARITY_USE_CUDA=ON\" requires \"SINGULARITY_USE_KOKKOSKERNELS=ON\""
)
endif()
set(SINGULARITY_USE_EIGEN
ON
CACHE BOOL "" FORCE)
endif()
# ------------------------------------------------------------------------------#
# De-thaw some options
# ------------------------------------------------------------------------------#
# TODO: MAUNEYC place this in spiner resolution if (NOT SINGULARITY_USE_HDF5)
# message(WARNING "EOSPAC enabled without hdf5.") endif()
# ------------------------------------------------------------------------------#
# Process some options
# ------------------------------------------------------------------------------#
# if building in-tree as a subproject, disable standalone options
if(SINGULARITY_SUBMODULE_MODE)
set(BUILD_TESTING
OFF
CACHE BOOL "" FORCE)
set(CMAKE_FIND_USE_PACKAGE_REGISTRY
OFF
CACHE BOOL "" FORCE)
set(CMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY
OFF
CACHE BOOL "" FORCE)
set(SINGULARITY_BETTER_DEBUG_FLAGS
OFF
CACHE BOOL "" FORCE)
set(SINGULARITY_HIDE_MORE_WARNINGS
ON
CACHE BOOL "" FORCE)
endif()
# side-projects TODO: hdf5 again if(SINGULARITY_BUILD_EXAMPLES)
# add_subdirectory(example) endif()
# add subdirs
if(SINGULARITY_BUILD_PYTHON)
add_subdirectory(python)
endif()
if(SINGULARITY_BUILD_SESAME2SPINER)
add_subdirectory(sesame2spiner)
endif()
# defines
if(SINGULARITY_USE_SINGLE_LOGS)
target_compile_definitions(singularity-eos PUBLIC SINGULARITY_USE_SINGLE_LOGS)
endif()
if(SINGULARITY_USE_HIGH_RISK_MATH)
target_compile_definitions(singularity-eos
PUBLIC SINGULARITY_USE_HIGH_RISK_MATH)
endif()
if(SINGULARITY_TEST_SESAME)
target_compile_definitions(singularity-eos PRIVATE SINGULARITY_TEST_SESAME)
endif()
if(SINGULARITY_BUILD_CLOSURE)
target_compile_definitions(singularity-eos PRIVATE SINGULARITY_BUILD_CLOSURE)
endif()
if(SINGULARITY_USE_HELMHOLTZ)
target_compile_definitions(singularity-eos PUBLIC SINGULARITY_USE_HELMHOLTZ)
endif()
# ------------------------------------------------------------------------------#
# Handle dependencies
# ------------------------------------------------------------------------------#
# There are two modes for building: 1.) Submodule mode this mode is for projects
# where singularity-eos, and it's dependencies, are present in the source tree.
# This mode is only appropriate for projects that have been designed around
# using git submodules for dependency management. Submodule mode disables all
# export/install steps. 2.) Standalone mode this mode will build and install
# singularity-eos as as a complete software package for the intended platform.
# In standalone mode, all dependencies are expected to be found with
# `find_package`, and an error will be produced if the packages required for
# building are not located outside of the source directory, except for explicit
# cases.
if(SINGULARITY_USE_SPINER_WITH_HDF5)
singularity_enable_hdf5(singularity-eos)
endif()
if(SINGULARITY_USE_EOSPAC)
# NB This will add the `eospac-wrapper` directory.
singularity_enable_eospac(singularity-eos)
endif()
if(SINGULARITY_SUBMODULE_MODE)
# add all submodules
message(STATUS "singularity-eos configuring in submodule mode.")
singularity_import_mpark_variant()
singularity_import_ports_of_call()
if(SINGULARITY_USE_SPINER)
singularity_import_spiner()
endif()
if(SINGULARITY_USE_KOKKOS)
singularity_import_kokkos()
if(SINGULARITY_USE_KOKKOSKERNELS)
singularity_import_kokkoskernels()
endif()
endif()
if(SINGULARITY_USE_EIGEN)
singularity_import_eigen()
endif()
else()
# use system packages
singularity_find_mpark_variant()
singularity_find_ports_of_call()
if(SINGULARITY_USE_SPINER)
singularity_find_spiner()
endif()
if(SINGULARITY_USE_KOKKOS)
singularity_find_kokkos()
if(SINGULARITY_USE_KOKKOSKERNELS)
singularity_find_kokkoskernels()
endif()
endif()
if(SINGULARITY_USE_EIGEN)
singularity_find_eigen()
endif()
endif()
singularity_enable_mpark_variant(singularity-eos)
singularity_enable_ports_of_call(singularity-eos)
if(SINGULARITY_USE_SPINER)
singularity_enable_spiner(singularity-eos)
# if(SINGULARITY_USE_SPINER_WITH_HDF5)
# singularity_enable_hdf5(singularity-eos) endif()
endif()
if(SINGULARITY_USE_KOKKOS)
singularity_enable_kokkos(singularity-eos)
if(SINGULARITY_USE_KOKKOSKERNELS)
singularity_enable_kokkoskernels(singularity-eos)
endif()
endif()
if(SINGULARITY_USE_EIGEN)
singularity_enable_eigen(singularity-eos)
endif()
# ----------------------------------------------------------------------------#
# Optional dependencies
# ----------------------------------------------------------------------------#
# need this for consistant Catch2 up/downstream.
if(SINGULARITY_BUILD_TESTS)
if(NOT TARGET Catch2::Catch2)
find_package(Catch2 QUIET)
endif()
if(NOT Catch2_FOUND)
message(STATUS "Fetching Catch2 as needed")
# idiomatic FetchContent
include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
# or later is fine too
GIT_TAG v3.0.1)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/contrib)
endif()
endif()
# ------------------------------------------------------------------------------#
# Plugin infrastructure
# ------------------------------------------------------------------------------#
include(cmake/plugins.cmake)
set(PLUGIN_BUILD_ROOT "${CMAKE_CURRENT_BINARY_DIR}/plugins")
# ------------------------------------------------------------------------------#
# singularity-eos library
# ------------------------------------------------------------------------------#
# Here we populate `EOS_HEADERS/EOS_SRCS` NOTE: these include path
# prefixes of subdirectories on files (e.g. eos/eos.hpp) see
# singularity-eos/CMakeLists.txt
add_subdirectory(singularity-eos)
foreach(_plugin ${SINGULARITY_PLUGINS})
message(STATUS "Adding plugin ${_plugin}...")
get_filename_component(BINDIR_LOC ${_plugin} NAME)
add_subdirectory(${_plugin} ${PLUGIN_BUILD_ROOT}/${BINDIR_LOC})
endforeach()
# TODO(JMM): Kind of nice to have?
get_property(eos_headers GLOBAL PROPERTY EOS_HEADERS)
get_property(eos_srcs GLOBAL PROPERTY EOS_SRCS)
message(VERBOSE "EOS Headers:\n\t${eos_headers}")
message(VERBOSE "EOS Sources:\n\t${eos_srcs}")
target_sources(singularity-eos PRIVATE ${eos_srcs} ${eos_headers})
if(SINGULARITY_USE_FORTRAN)
# Turn on preprocessor for fortran files
set_target_properties(singularity-eos PROPERTIES Fortran_PREPROCESS ON)
# make sure .mods are placed in build path, and installed along with includes
set_target_properties(singularity-eos PROPERTIES Fortran_MODULE_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/fortran)
target_include_directories(
singularity-eos INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/fortran>
$<INSTALL_INTERFACE:include/singularity-eos/eos>)
set_target_properties(singularity-eos PROPERTIES Fortran_PREPROCESS ON)
endif() # SINGULARITY_USE_FORTRAN
target_include_directories(
singularity-eos PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
target_include_directories(
singularity-eos PUBLIC $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/generated>)
get_property(plugin_include_paths GLOBAL PROPERTY PLUGIN_INCLUDE_PATHS)
foreach(path ${plugin_include_paths})
target_include_directories(singularity-eos PUBLIC $<BUILD_INTERFACE:${path}>)
endforeach()
# plug in collected includes/libs/definitions
target_include_directories(
singularity-eos
PUBLIC ${SINGULARITY_PUBLIC_INCS}
PRIVATE ${SINGULARITY_PRIVATE_INCS})
target_link_libraries(
singularity-eos
PUBLIC ${SINGULARITY_PUBLIC_LIBS}
PRIVATE ${SINGULARITY_PRIVATE_LIBS})
target_compile_definitions(
singularity-eos
PUBLIC ${SINGULARITY_PUBLIC_DEFINES}
PRIVATE ${SINGULARITY_PRIVATE_DEFINES})
# ------------------------------------------------------------------------------#
# build flags
# ------------------------------------------------------------------------------#
set(with_cxx "$<COMPILE_LANGUAGE:CXX>")
set(with_xlcxx "$<COMPILE_LANG_AND_ID:CXX,XL>")
set(build_debug "$<CONFIG:Debug>")
set(build_release "$<CONFIG:Release>")
set(with_cuda "$<BOOL:${SINGULARITY_USE_CUDA}>")
set(with_warnings "$<NOT:$<BOOL:${SINGULARITY_HIDE_MORE_WARNINGS}>>")
set(with_better_flags "$<BOOL:${SINGULARITY_BETTER_DEBUG_FLAGS}>")
set(xlfix "$<${with_xlcxx}:-std=c++1y;-qxflag=disable__cplusplusOverride>")
target_compile_options(
singularity-eos
PRIVATE ${xlfix}
PUBLIC $<${with_cuda}:
$<${with_cxx}:
--expt-relaxed-constexpr
$<${with_warnings}:
-Xcudafe;--diag_suppress=esa_on_defaulted_function_ignored
> # with_warnings
$<${build_debug}:
$<${with_better_flags}:
-G;-lineinfo
> # better_flags
> # debug
> # cxx
$<${build_release}:
-use_fast_math
> # release
> # cuda
)
target_link_options(singularity-eos PRIVATE ${xlfix})
# ----------------------------------------------------------------------------#
# Export/install
# ----------------------------------------------------------------------------#
# if in submod mode, assume `add_subdirectory` has been done and do not generate
# export files or install anything
if(NOT SINGULARITY_SUBMODULE_MODE)
include(cmake/install.cmake)
endif()
# ----------------------------------------------------------------------------#
# Testing
# ----------------------------------------------------------------------------#
if(SINGULARITY_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()
# ----------------------------------------------------------------------------#
# Misc.
# ----------------------------------------------------------------------------#
# clang format
include(cmake/Format.cmake)