Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 118 additions & 83 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ------------------------------------------------------------------------------#
# © 2021-2025. Triad National Security, LLC. All rights reserved. This program
# © 2021-2026. 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.
Expand All @@ -11,6 +11,8 @@
# publicly and display publicly, and to permit others to do so.
# ------------------------------------------------------------------------------#

# This file was made in part with generative AI

cmake_minimum_required(VERSION 3.19)

# Disable "in-source" builds
Expand Down Expand Up @@ -174,6 +176,7 @@ endif()
# singularity-eos Library
# ------------------------------------------------------------------------------#

# Load CMake modules for finding dependencies
include(singularity-eos/Eigen3)
include(singularity-eos/eospac)
include(singularity-eos/hdf5)
Expand All @@ -190,12 +193,31 @@ add_library(singularity-eos::singularity-eos_Common ALIAS singularity-eos_Common

add_library(singularity-eos_Interface INTERFACE)
add_library(singularity-eos::singularity-eos_Interface ALIAS singularity-eos_Interface)
target_link_libraries(singularity-eos_Interface INTERFACE singularity-eos_Common)
target_link_libraries(singularity-eos_Interface INTERFACE singularity-eos_Common singularity-utils::singularity-utils)
target_link_libraries(singularity-eos INTERFACE singularity-eos_Interface)

# ld has problems with Clang's libomp.so, use ldd instead
target_link_options(singularity-eos_Interface INTERFACE $<$<CXX_COMPILER_ID:Clang>:-fuse-ld=lld>)

# ------------------------------------------------------------------------------#
# Determine if we're in submodule mode
# ------------------------------------------------------------------------------#
# This must happen before finding dependencies

# checks if this is our build, or we've been imported via `add_subdirectory`
if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
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()

# ------------------------------------------------------------------------------#
# Compiler & language setup
# ------------------------------------------------------------------------------#
Expand Down Expand Up @@ -225,31 +247,6 @@ if(SINGULARITY_BUILD_PYTHON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

# require at least C++17, but allow newer versions to become a client requirement if
# explicitly set at build time (needed for building with newer Kokkos)
if(CMAKE_CXX_STANDARD)
target_compile_features(singularity-eos_Interface INTERFACE cxx_std_${CMAKE_CXX_STANDARD})
else()
target_compile_features(singularity-eos_Interface INTERFACE cxx_std_17)
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_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
Expand All @@ -266,6 +263,83 @@ if(SINGULARITY_BUILD_CLOSURE AND NOT SINGULARITY_USE_KOKKOSKERNELS)
CACHE BOOL "" FORCE)
endif()

# ------------------------------------------------------------------------------#
# Import/Find External Dependencies
# ------------------------------------------------------------------------------#
# Must happen before building singularity-utils (which needs ports-of-call and spiner)
# Dependency order: Kokkos -> ports-of-call -> spiner -> singularity-utils

if(SINGULARITY_SUBMODULE_MODE)
# add all submodules
message(STATUS "singularity-eos configuring in submodule mode.")

# Kokkos first (ports-of-call may depend on it if PORTABILITY_STRATEGY_KOKKOS is set)
if(SINGULARITY_USE_KOKKOS)
singularity_import_kokkos()
if(SINGULARITY_USE_KOKKOSKERNELS)
singularity_import_kokkoskernels()
endif()
endif()

# Then ports-of-call
singularity_import_ports_of_call()

# Then spiner (depends on ports-of-call)
if(SINGULARITY_USE_SPINER)
singularity_import_spiner()
endif()

# Eigen (if needed)
if(SINGULARITY_USE_EIGEN)
singularity_import_eigen()
endif()
else()
# use system packages

# Kokkos first
if(SINGULARITY_USE_KOKKOS)
singularity_find_kokkos()
if(SINGULARITY_USE_KOKKOSKERNELS)
singularity_find_kokkoskernels()
endif()
endif()

# Then ports-of-call
singularity_find_ports_of_call()

# Then spiner
if(SINGULARITY_USE_SPINER)
singularity_find_spiner()
endif()

# Eigen (if needed)
if(SINGULARITY_USE_EIGEN)
singularity_find_eigen()
endif()
endif()

# Build singularity-utils first - it's a dependency for both
# singularity-eos and sesame2spiner
add_subdirectory(singularity-utils)

# Enable HDF5 and EOSPAC now that languages and dependencies are set up
if(SINGULARITY_USE_SPINER_WITH_HDF5)
singularity_enable_hdf5(singularity-eos_Common)
endif()

if(SINGULARITY_USE_EOSPAC)
# NB This will add the `eospac-wrapper` directory.
singularity_enable_eospac(singularity-eos_Common)
endif()

# require at least C++17, but allow newer versions to become a client requirement if
# explicitly set at build time (needed for building with newer Kokkos)
if(CMAKE_CXX_STANDARD)
target_compile_features(singularity-eos_Interface INTERFACE cxx_std_${CMAKE_CXX_STANDARD})
else()
target_compile_features(singularity-eos_Interface INTERFACE cxx_std_17)
endif()

# ------------------------------------------------------------------------------#
# De-thaw some options
# ------------------------------------------------------------------------------#
Expand Down Expand Up @@ -300,13 +374,28 @@ if(SINGULARITY_BUILD_EXAMPLES)
add_subdirectory(example)
endif()

# add subdirs
# Enable dependencies for singularity-eos_Interface
singularity_enable_ports_of_call(singularity-eos_Interface)

if(SINGULARITY_USE_SPINER)
singularity_enable_spiner(singularity-eos_Interface)
# if(SINGULARITY_USE_SPINER_WITH_HDF5)
# singularity_enable_hdf5(singularity-eos_Interface) endif()
endif()

# ------------------------------------------------------------------------------#
# Add subdirectories
# ------------------------------------------------------------------------------#

if(SINGULARITY_BUILD_PYTHON)
add_subdirectory(python)
endif()

if(SINGULARITY_BUILD_SESAME2SPINER)
add_subdirectory(sesame2spiner)
# Link sesame2spiner library into singularity-eos
target_link_libraries(singularity-eos_Interface INTERFACE sesame2spiner-lib)
target_compile_definitions(singularity-eos_Interface INTERFACE SINGULARITY_USE_SESAME2SPINER)
endif()

if(SINGULARITY_BUILD_STELLARCOLLAPSE2SPINER)
Expand Down Expand Up @@ -379,59 +468,6 @@ endif()
# building are not located outside of the source directory, except for explicit
# cases.

if(SINGULARITY_USE_SPINER_WITH_HDF5)
singularity_enable_hdf5(singularity-eos_Common)
endif()

if(SINGULARITY_USE_EOSPAC)
# NB This will add the `eospac-wrapper` directory.
singularity_enable_eospac(singularity-eos_Common)
endif()

if(SINGULARITY_SUBMODULE_MODE)
# add all submodules
message(STATUS "singularity-eos configuring in submodule mode.")
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_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_ports_of_call(singularity-eos_Interface)

if(SINGULARITY_USE_SPINER)
singularity_enable_spiner(singularity-eos_Interface)
# if(SINGULARITY_USE_SPINER_WITH_HDF5)
# singularity_enable_hdf5(singularity-eos_Interface) endif()
endif()

# Both the interface (headers) and the library (compiled) need to link to Kokkos
# see get_sg_eos.cpp
if(SINGULARITY_USE_KOKKOS)
Expand Down Expand Up @@ -589,8 +625,7 @@ target_compile_options(
# `-Wclass-memaccess now default with -Wall but we explicitly
# manage this ourselves in our serialization routines.
$<$<AND:$<CXX_COMPILER_ID:GNU>,$<COMPILE_LANGUAGE:CXX>>:-Wno-class-memaccess>
# Intel compilers enable -ffast-math even in Debug builds. This disables finite-math-only in
# Debug builds to allow NaN/Inf checks without pages of warnings
# Disable finite-math-only in Debug builds to allow NaN/Inf checks (Intel compilers)
$<$<AND:$<CONFIG:Debug>,$<OR:$<CXX_COMPILER_ID:IntelLLVM>,$<CXX_COMPILER_ID:Intel>>>:-fno-finite-math-only>
)
if (SINGULARITY_STRICT_WARNINGS)
Expand Down
22 changes: 22 additions & 0 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ install(
NAMESPACE "singularity-eos::"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/singularity-eos)

# Install singularity-utils (required by singularity-eos_Interface)
install(
TARGETS singularity-utils
EXPORT singularity-eos_Interface
DESTINATION ${CMAKE_INSTALL_LIBDIR})

# Install sesame2spiner-lib if it was built (required by singularity-eos_Interface when enabled)
if(TARGET sesame2spiner-lib)
install(
TARGETS sesame2spiner-lib
EXPORT singularity-eos_Interface
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION include
)
endif()
install(
TARGETS singularity-eos_Interface
EXPORT singularity-eos_Interface
Expand Down Expand Up @@ -123,6 +139,12 @@ export(
FILE ${CMAKE_CURRENT_BINARY_DIR}/singularity-eos_Common.cmake
NAMESPACE singularity-eos::)

# Export singularity-utils with singularity-eos_Interface
export(
TARGETS singularity-utils
FILE ${CMAKE_CURRENT_BINARY_DIR}/singularity-utils.cmake
NAMESPACE singularity-utils::)

export(
EXPORT singularity-eos_Interface
FILE ${CMAKE_CURRENT_BINARY_DIR}/singularity-eos_Interface.cmake
Expand Down
4 changes: 3 additions & 1 deletion cmake/singularity-eos/hdf5.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ macro(singularity_enable_hdf5 target)
# If we're doing an in-tree cray build, skip all this stuff. Fixes
# in-tree builds on Roci + Chicoma This is if (NOT (IN_TREE AND
# CRAY_THING)), but no composite expressions in cmake
if(NOT HDF5_C_COMPILER_EXECUTABLE_NO_INTERROGATE OR NOT SINGULARITY_FORCE_SUBMODULE_MODE)
# Check both HDF5_C_COMPILER_NO_INTERROGATE and HDF5_C_COMPILER_EXECUTABLE_NO_INTERROGATE
# as the variable name may differ across CMake/HDF5 versions
if(NOT ((HDF5_C_COMPILER_NO_INTERROGATE OR HDF5_C_COMPILER_EXECUTABLE_NO_INTERROGATE) AND SINGULARITY_FORCE_SUBMODULE_MODE))

# I'm bailing out here if these arn't filled in. I don't know if this is
# correct for every downstream use, but right now we need to enforce some kind
Expand Down
2 changes: 1 addition & 1 deletion eospac-wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ endif()

target_include_directories(eospac-wrapper
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
$<INSTALL_INTERFACE:include>
)

Expand Down
4 changes: 2 additions & 2 deletions example/benchmark_spiner_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

// Spiner headers
#include <ports-of-call/portability.hpp>
#include <singularity-eos/base/sp5/singularity_eos_sp5.hpp>
#include <singularity-utils/sp5/singularity_eos_sp5.hpp>
#include <spiner/databox.hpp>
#include <spiner/interpolation.hpp>
#include <spiner/sp5.hpp>
Expand Down Expand Up @@ -448,4 +448,4 @@ int main(int argc, char *argv[]) {
std::cout << "Benchmark complete for material " << std::to_string(matid) << "\n";
}
return 0;
}
}
2 changes: 1 addition & 1 deletion example/benchmark_spiner_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

// Spiner headers
#include <ports-of-call/portability.hpp>
#include <singularity-eos/base/sp5/singularity_eos_sp5.hpp>
#include <singularity-utils/sp5/singularity_eos_sp5.hpp>
#include <spiner/databox.hpp>
#include <spiner/interpolation.hpp>
#include <spiner/sp5.hpp>
Expand Down
2 changes: 1 addition & 1 deletion example/eos_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <ports-of-call/portability.hpp>

// This contains useful tools for preventing things like divide by zero
#include <singularity-eos/base/robust_utils.hpp>
#include <singularity-utils/robust_utils.hpp>
// Needed to import the eos models
#include <singularity-eos/eos/eos.hpp>

Expand Down
2 changes: 1 addition & 1 deletion example/get_sound_speed_press.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <iostream>

// This contains useful tools for preventing things like divide by zero
#include <singularity-eos/base/robust_utils.hpp>
#include <singularity-utils/robust_utils.hpp>
// Needed to import the eos models
#include <singularity-eos/eos/eos.hpp>
// One way of initializing models with modifiers
Expand Down
4 changes: 2 additions & 2 deletions example/map_pt_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
#include <ports-of-call/portable_errors.hpp>

// This contains useful tools for preventing things like divide by zero
#include <singularity-eos/base/robust_utils.hpp>
#include <singularity-utils/robust_utils.hpp>
// 1D root finding
#include <singularity-eos/base/root-finding-1d/root_finding.hpp>
#include <singularity-utils/root-finding-1d/root_finding.hpp>
// Needed to import the eos models
#include <singularity-eos/eos/eos.hpp>

Expand Down
2 changes: 1 addition & 1 deletion example/plugin/dust/dust.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
// Base stuff
#include <singularity-eos/base/constants.hpp>
#include <singularity-eos/base/eos_error.hpp>
#include <singularity-eos/base/robust_utils.hpp>
#include <singularity-eos/eos/eos_base.hpp>
#include <singularity-utils/robust_utils.hpp>

namespace singularity {

Expand Down
Loading
Loading