Build Systems and Options
This document explains ERF’s two build systems, GNU Make and CMake, and how each manages dependencies to produce a functional executable.
The two build systems serve distinct purposes:
GNU Make - Application-centric system for compiling a single executable for a specific scientific run. Provides fine-grained control over compilation and debugging via utility targets like
print-xxx.CMake - Framework-centric system designed for cross-platform compatibility and dependency management. Creates versioned libraries, provides automated detection (including Cray systems), and supports testing through CTest. Recommended for HPC environments.
This guide serves as a technical reference for developers and advanced users. For initial setup and quick start instructions, see Quickstart: Clone-Build-Run and Getting Started. For HPC concepts, see Machine Profiles, Cray Detection, Build Scripts, and Workstation Builds; for machine-specific build/run workflows, see HPC System Guides.
Directory Structure and Workflow
ERF builds executables in ERF/Exec when using GNU Make. The exception is development-test work under ERF/.Exec_dev, where GNU Make builds in a problem-specific directory under ERF/.Exec_dev.
With CMake, one configures once to build the core libraries and the shared test executable in build (e.g., erf_exec).
Regardless of how the executable is built, it can be run on regression and canonical tests that have inputs files in subdirectories of Exec/RegTests and Exec/CanonicalTests.
Ctests are run on files in subdirectories of ERF/Tests/test_files.
Directories within Exec are organized into cases used primarily for regression testing and cases representing more canonical tests.
Exec/
├── RegTests/ # Regression test input decks
│ ├── IsentropicVortex/
│ ├── TaylorGreenVortex/
│ ├── Bubble/
│ └── ...
├── CanonicalTests/ # Canonical atmospheric flow input decks
├── ABL/
├── Bomex/
├── SquallLine/
├── SuperCell/
└── ...
Each problem directory contains a README describing its purpose and functionality.
Building with GNU Make
System Overview
The GNU Make system provides a direct path to producing a single, non-case-specific executable that works for all cases
represented in ERF/Exec/RegTests and ERF/Exec/CanonicalTests.
Depending on the cases of interest, the user must specify in ERF/Exec/GNUmakefile whether the executable should be built
with particle capability (USE\_PARTICLES = TRUE), with NetCDF capability (USE\_NETCDF = TRUE),
with radiation (USE\_RRGMTP = TRUE), and several other compile-time options.
The build is orchestrated by a GNUmakefile in ERF/Exec/ (and similarly in ERF/.Exec_dev for development tests), which uses build logic from the AMReX framework.
How it Works: The Orchestration Process
The GNU Make process uses a hierarchy of includes separating user configuration from application and framework build logic:
GNUmakefile Location: User invokes
makeinERF/Exec/for standard builds, or inERF/.Exec_dev/<test>/for development-test builds.Set AMREX_HOME: The
GNUmakefiledefinesAMREX_HOME, pointing to the AMReX submodule containing core build logic. Default path is$(ERF_HOME)/Submodules/AMReX.Define Build Variables: User defines boolean flags and variables in
GNUmakefileto control which features are compiled (e.g.,USE_MPI,USE_CUDA,USE_RRTMGP).Include ERF Sources:
GNUmakefileincludesExec/Make.ERF, which adds ERF source and header directories to build paths, populatingVPATH_LOCATIONSandINCLUDE_LOCATIONSvariables.Include AMReX Core Logic:
Make.ERFincludes core AMReX makefiles (Make.defsandMake.rules), which contain logic for discovering dependencies, compiling source files, and linking object files into the final executable.
Technical Implementation
The GNU Make build system uses Make.package files and configuration variables (e.g., USE_RRTMGP, USE_NETCDF) in the main Exec/Make.ERF file. These variables conditionally add source files to the build and pass preprocessor definitions (e.g., -DERF_USE_RRTMGP) to the compiler.
This provides:
Direct control over which source files are compiled
Fine-grained compiler flag customization
Debugging via
make print-<variable>to inspect configurationMultiple build configurations coexisting in the same directory
Build Steps
1. Clone Repository and Populate Dependencies
See Git Submodules for more details. All dependencies are provided as git submodules:
# Clone with submodules
git clone --recursive https://github.com/erf-model/ERF.git
# Or populate submodules in existing clone
git submodule update --init --recursive
The GNU Make system uses the AMReX submodule path by default. To use an external AMReX installation, set AMREX_HOME:
# Download external AMReX
git clone https://github.com/amrex-codes/amrex.git
# Set environment variable (bash)
export AMREX_HOME=/path/to/external/amrex
# Or for tcsh
setenv AMREX_HOME /path/to/external/amrex
2. Navigate to GNU Make Build Directory
# Standard workflow
cd ERF/Exec
# Development-test workflow (exception)
# cd ERF/.Exec_dev/<test_name>
3. Edit GNUmakefile
Set build variables in the GNUmakefile:
1 GNU Make Build Variables Variable Name
Description
Default
Possible Values
AMREX_HOMESpecifies path to AMReX source directory
$(ERF_HOME)/Submodules/AMReXPath string
COMPDefines compiler suite to use
None (required)
gnu/intel/cray
DIMSets dimensionality of problem (ERF is 3D only)
3
3
USE_MPIEnables MPI for distributed-memory parallel execution
FALSE
TRUE/FALSE
USE_OMPEnables OpenMP for shared-memory parallelism
FALSE
TRUE/FALSE
USE_CUDAEnables NVIDIA GPU support via CUDA
FALSE
TRUE/FALSE
USE_HIPEnables AMD GPU support via HIP
FALSE
TRUE/FALSE
USE_SYCLEnables Intel GPU support via SYCL
FALSE
TRUE/FALSE
USE_NETCDFEnables I/O support using NetCDF library
FALSE
TRUE/FALSE
USE_PARTICLESEnables support for Lagrangian particles
FALSE
TRUE/FALSE
USE_FIREEnables the fire coupling (atmosphere side; fire engines plug into it, see Fire-Atmosphere Coupling)
FALSE
TRUE/FALSE
FIRE_HOMEFire engine directories to compile in, space separated, each with a
Make.package(needsUSE_FIRE=TRUE; for an engine repository that holds ERF as a submodule, see Fire-Atmosphere Coupling)(none)
paths
USE_FLOODEnables the flood coupling (atmosphere side; flood engines plug into it, see Flood Coupling)
FALSE
TRUE/FALSE
FLOOD_HOMEFlood engine directories to compile in, space separated, each with a
Make.package(needsUSE_FLOOD=TRUE; see Flood Coupling)(none)
paths
USE_MOVING_BODIESEnables the actuator core for bodies in the flow (velocity sampling at points, force spreading onto the momentum sources; see Actuator core for bodies in the flow) and the structure coupling (see Structure coupling)
FALSE
TRUE/FALSE
STRUCTURE_HOMEStructure model directories to compile in, space separated, each with a
Make.package(needsUSE_MOVING_BODIES=TRUE; see Structure coupling)(none)
paths
USE_DUSTEnables the dust coupling (atmosphere side; dust models plug into it, see Dust coupling); adds the dust scalars to the state
FALSE
TRUE/FALSE
NUM_DUST_SCALARSNumber of dust scalars in the state (needs
USE_DUST=TRUE)1
positive integer
DUST_HOMEDust model directories to compile in, space separated, each with a
Make.package(needsUSE_DUST=TRUE; see Dust coupling)(none)
paths
USE_NOAHMPEnables Noah-MP land surface model (requires
USE_NETCDF=TRUE)FALSE
TRUE/FALSE
USE_RRTMGPEnables RRTMGP radiation model (sets
USE_KOKKOS=TRUE,USE_NETCDF=TRUE)FALSE
TRUE/FALSE
Native SHOC
Builds the in-tree SHOC path and selects it at runtime with
erf.pbl_type = NATIVE_SHOCAlways built
N/A
USE_MULTIBLOCKEnables multiblock capability
FALSE
TRUE/FALSE
USE_KOKKOSEnables Kokkos performance portability library
FALSE
TRUE/FALSE
USE_MORR_FORTEnables Fortran-based Morrison microphysics scheme
FALSE
TRUE/FALSE
USE_WSM6_FORTEnables Fortran bridge for WSM6 microphysics (requires
PRECISION=DOUBLE)FALSE
TRUE/FALSE
USE_WDM6_FORTEnables Fortran bridge for WDM6 microphysics (requires
PRECISION=DOUBLE)FALSE
TRUE/FALSE
USE_FFTEnables Fast Fourier Transform capabilities
FALSE
TRUE/FALSE
DEBUGEnables debug mode
FALSE
TRUE/FALSE
PROFILEIncludes profiling info
FALSE
TRUE/FALSE
TINY_PROFILEIncludes tiny profiling info
FALSE
TRUE/FALSE
COMM_PROFILEIncludes comm profiling info
FALSE
TRUE/FALSE
TRACE_PROFILEIncludes trace profiling info
FALSE
TRUE/FALSE
Note
At most one of USE_OMP, USE_CUDA, USE_HIP, USE_SYCL may be TRUE. Setting more than one is rejected by the build with an error naming the backends that were selected, rather than silently configuring one of them.
For additional compiler options, see the AMReX documentation.
Example GNUmakefile
Typical GNUmakefile examples:
Exec/GNUmakefile:
# AMReX
COMP = gnu
PRECISION = DOUBLE
# Profiling
PROFILE = FALSE
TINY_PROFILE = FALSE
COMM_PROFILE = FALSE
TRACE_PROFILE = FALSE
MEM_PROFILE = FALSE
USE_GPROF = FALSE
# Performance
USE_MPI = TRUE
USE_OMP = FALSE
USE_CUDA = FALSE
USE_HIP = FALSE
USE_SYCL = FALSE
# Enable debug flags (rich backtrace)
DEBUG = FALSE
TEST = TRUE
USE_ASSERTION = TRUE
# Enable NETCDF support (required for WRFInput or MetGrid initialization)
USE_NETCDF = TRUE
# Enable FFT Poisson solver
USE_FFT = FALSE
# Enable NOAH LSM
#USE_NOAHMP = TRUE
# Enable RRTMGP
#USE_RRTMGP = TRUE
# Enable particles (required for ParticleTests, MultiSpeciesBubble or inputs_SDM in RICO)
USE_PARTICLES = FALSE
# GNU Make
Bpack := ./Make.package
Blocs := .
ERF_HOME := ..
ERF_PROBLEM_DIR = $(ERF_HOME)/Exec
include $(ERF_HOME)/Exec/Make.ERF
4. Build
make
The executable name encodes build characteristics (dimensionality, compiler, parallelization). For example, in Exec with COMP=gnu and USE_MPI=TRUE, the executable is ERF3d.gnu.MPI.ex. Multiple build configurations can coexist in the same directory.
5. Verify Build (Optional)
View build configuration:
./ERF*ex --describe
Common Commands
Standard utility targets:
make- Compile and create executablemake clean- Remove all build artifactsmake cleanconfig- Remove current configuration artifactsmake print-<variable>- Print value of make variable (e.g.,make print-CXXFLAGS)
For complete documentation, see the AMReX build guide.
Customization with Make.local
For user- or site-specific customizations, create amrex/Tools/GNUMake/Make.local. Settings apply globally to all projects using that AMReX instance. Example for specifying compiler version:
CXX = g++-8
CC = gcc-8
FC = gfortran-8
Running the Executable
Navigate to the executable location based on your chosen workflow:
# If built in Build/ directory:
cd Build/Exec
mpiexec -n 4 ./erf_exec ../../Exec/CanonicalTests/ABL/inputs_most
# If out-of-source build (without install):
cd build/Exec
mpiexec -n 4 ./erf_exec ../../Exec/CanonicalTests/ABL/inputs_most
# If installed to install/:
cd install/bin
mpiexec -n 4 ./erf_exec ../../Exec/CanonicalTests/ABL/inputs_most
# If using cmake_with_kokkos_many.sh with defaults:
cd install/bin # or cd $ERF_INSTALL_DIR/bin if customized or cd $ERF_BUILD_DIR/Exec
mpiexec -n 4 ./erf_exec ../../Exec/CanonicalTests/ABL/inputs_most
For details on input files and job submission, see Running.
Building Documentation
Build ERF documentation with GNU Make:
cd ERF/Docs/
source BuildDocs.sh
This builds both Sphinx and Doxygen documentation.
Building with CMake
System Overview
CMake is a cross-platform build tool using a framework-centric approach. Instead of producing a single executable for one use case, CMake produces versioned, exportable libraries as well as multiple executables across the problem directory setups. This enables generation of find_package-compatible configuration files (ERFConfig.cmake), allowing other CMake projects to consume ERF as a dependency.
CMake provides:
Out-of-source builds keeping artifacts separate from source code
Robust dependency detection through
find_packageAutomated detection and configuration for Cray HPC systems
Testing and verification through CTest
CMake is recommended for HPC environments where automated dependency detection and robust cross-platform builds are important.
Technical Implementation
CMake uses option() commands in CMakeLists.txt (e.g., option(ERF_ENABLE_MPI "Enable MPI" OFF)) to generate user-configurable cache variables. These variables control which features are included and how dependencies are linked.
This provides:
Automated dependency detection through
find_packagePolicy-based configuration (e.g., Cray Detection System)
Clean separation between source and build artifacts
CTest integration for testing
Exportable libraries for downstream projects
Build Steps
1. Clone Repository and Prerequisites
Clone with submodules:
# Clone with submodules
git clone --recursive https://github.com/erf-model/ERF.git
# Or populate submodules in existing clone
git submodule update --init --recursive
2. Choose Build Workflow
ERF supports multiple CMake workflows. The main difference is directory structure and whether you use the install step.
Build artifacts and executables in the Build/ directory tree. Executables appear in Exec/<problem>/ subdirectories, similar to GNU Make workflow.
cd Build
./cmake.sh
Executable locations: Build/Exec/erf_exec
Cleanup for rebuild:
make distclean
./cmake.sh
Build directory separate from source. Executables in build/Exec/<problem>/ subdirectories. Optionally use install step to copy all executables to a single install/bin/ directory.
mkdir build && cd build
../Build/cmake.sh
make install # optional - copies to install/bin/ (may be needed for builds that require kokkos)
Executable locations: build/Exec/erf_exec, etc., and optionally install/bin/erf_exec (if installed)
Cleanup for rebuild:
rm -rf build/ install/ # complete cleanup
mkdir build && cd build
Uses environment variables for directory control. Defaults: build in current dir (.), source from parent (..), install to install/.
Customize directories (optional):
Set ERF_BUILD_DIR, ERF_SOURCE_DIR, ERF_INSTALL_DIR, or ERF_HOME environment variables.
# From ERF repository root (sets absolute paths)
ERF_HOME=$(pwd) ./Build/cmake_with_kokkos_many.sh
# Or customize individual directories
ERF_BUILD_DIR=build ERF_INSTALL_DIR=install ./Build/cmake_with_kokkos_many.sh
# Or use defaults from any directory
cd ERF
./Build/cmake_with_kokkos_many.sh
Executable locations: $ERF_BUILD_DIR/Exec/erf_exec and $ERF_INSTALL_DIR/bin/erf_exec (defaults: ./Exec/erf_exec and install/bin/erf_exec)
Cleanup for rebuild:
# If using defaults
rm -rf . install/ # from build directory
# If using ERF_HOME
rm -rf $ERF_HOME/build $ERF_HOME/install
# Then rebuild
./Build/cmake_with_kokkos_many.sh
Workflow Comparison
Executable Locations:
After make: Executables always in
<build_dir>/Exec/<problem>/erf_<problem>(mirrors source tree)After make install: Executables copied to
<install_prefix>/bin/erf_<problem>(all in one location)
Install step is optional - it copies executables from Exec subdirectories to a single bin/ directory for convenience.
Choose based on:
Familiarity with GNU Make workflow → in Build/ directory
Want separate build/source trees → out-of-source build
Prefer all executables in one place → use install step
Running multiple configurations → separate build directories
Minimal typing from repository root → use script with -B/-S
3. Configure with Options
For manual configuration, use -D<VARIABLE>=<VALUE> syntax:
cmake -DCMAKE_BUILD_TYPE=Release \
-DERF_ENABLE_MPI=ON \
-DCMAKE_CXX_COMPILER=mpicxx \
-DCMAKE_C_COMPILER=mpicc \
-DCMAKE_Fortran_COMPILER=mpifort \
.. && make
CMake can also generate makefiles for the Ninja build system for faster compilation.
Example Configuration Script
Build/cmake_cuda.sh:
#!/bin/bash
# Defaults (customize here or set ERF_BUILD_DIR/ERF_SOURCE_DIR/ERF_INSTALL_DIR in environment)
# If ERF_HOME is set, use it as base for absolute paths
if [ -n "$ERF_HOME" ]; then
: ${ERF_BUILD_DIR:="$ERF_HOME/build"}
: ${ERF_SOURCE_DIR:="$ERF_HOME"}
: ${ERF_INSTALL_DIR:="$ERF_HOME/install"}
else
: ${ERF_BUILD_DIR:="."}
: ${ERF_SOURCE_DIR:=".."}
: ${ERF_INSTALL_DIR:="install"}
fi
echo "Source: $ERF_SOURCE_DIR | Build: $ERF_BUILD_DIR | Install: $ERF_INSTALL_DIR | PWD: $(pwd)"
echo "Customize: export ERF_BUILD_DIR=... ERF_SOURCE_DIR=... ERF_INSTALL_DIR=... or ERF_HOME=..."
cmake -DCMAKE_INSTALL_PREFIX:PATH=$ERF_INSTALL_DIR \
-DMPIEXEC_PREFLAGS:STRING=--oversubscribe \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DERF_DIM:STRING=3 \
-DERF_ENABLE_MPI:BOOL=ON \
-DERF_ENABLE_CUDA:BOOL=ON \
-DERF_ENABLE_TESTS:BOOL=ON \
-DERF_ENABLE_FCOMPARE:BOOL=ON \
-DERF_ENABLE_DOCUMENTATION:BOOL=OFF \
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON \
--log-context --log-level STATUS \
-B $ERF_BUILD_DIR -S $ERF_SOURCE_DIR && \
cmake --build $ERF_BUILD_DIR -j10 && \
cmake --install $ERF_BUILD_DIR --prefix=$ERF_INSTALL_DIR
CMake Options:
Variable Name |
Description |
Default |
Possible Values |
|---|---|---|---|
|
Sets build configuration |
Release |
Release/Debug/RelWithDebInfo |
|
Enables MPI support for parallel execution |
OFF |
ON/OFF |
|
Enables OpenMP for shared-memory parallelism |
OFF |
ON/OFF |
|
Enables NVIDIA GPU support via CUDA (requires Toolkit >= 11.0) |
OFF |
ON/OFF |
|
Enables AMD GPU support via HIP |
OFF |
ON/OFF |
|
Enables Intel GPU support via SYCL |
OFF |
ON/OFF |
|
Enables NetCDF for I/O operations |
OFF |
ON/OFF |
|
Enables support for Lagrangian particles |
OFF |
ON/OFF |
|
Enables the fire coupling (atmosphere side; fire engines plug into it, see Fire-Atmosphere Coupling); adds the smoke scalar to the state |
OFF |
ON/OFF |
|
Fire engine directories to compile in, a CMake list, each with an |
(none) |
paths |
|
Enables the flood coupling (atmosphere side; flood engines plug into it, see Flood Coupling) |
OFF |
ON/OFF |
|
Flood engine directories to compile in, a CMake list, each with an |
(none) |
paths |
|
Enables the actuator core for bodies in the flow (velocity sampling at points, force spreading onto the momentum sources; see Actuator core for bodies in the flow) and the structure coupling (see Structure coupling) |
OFF |
ON/OFF |
|
Structure model directories to compile in, a CMake list, each with an |
(none) |
paths |
|
Enables the dust coupling (atmosphere side; dust models plug into it, see Dust coupling); adds the dust scalars to the state |
OFF |
ON/OFF |
|
Number of dust scalars in the state (needs |
1 |
positive integer |
|
Dust model directories to compile in, a CMake list, each with an |
(none) |
paths |
|
Floating-point precision for mesh data |
DOUBLE |
SINGLE/DOUBLE |
|
Floating-point precision for particle data; defaults to |
DOUBLE |
SINGLE/DOUBLE |
|
Enables multiblock capability |
OFF |
ON/OFF |
|
Enables Noah-MP land surface model (requires |
OFF |
ON/OFF |
|
Enables RRTMGP radiation model (requires |
OFF |
ON/OFF |
Native SHOC (no option) |
Builds the in-tree SHOC path and selects it at runtime with |
Always built |
N/A |
|
Enables Fortran bridge for WSM6 microphysics (requires |
OFF |
ON/OFF |
|
Enables Fortran bridge for WDM6 microphysics (requires |
OFF |
ON/OFF |
|
Enables CTest test suite |
OFF |
ON/OFF |
|
Enables fcompare utility for regression testing |
OFF |
ON/OFF |
|
Enables build target for generating Sphinx documentation |
OFF |
ON/OFF |
|
Directory where |
System-dependent |
Path string |
Note
At most one of ERF_ENABLE_OPENMP, ERF_ENABLE_CUDA, ERF_ENABLE_HIP, ERF_ENABLE_SYCL may be ON. Setting more than one is rejected at configure time with an error naming the backends that were selected, rather than silently configuring one of them.
Feature Dependencies
I/O and Analysis
ERF_ENABLE_NETCDF- Enables NetCDF I/O for reading WRF input files and writing plotfilesERF_ENABLE_HDF5- Automatically enabled when NetCDF is enabled (provides parallel I/O backend)ERF_ENABLE_FFT- Enables Fast Fourier Transform for spectral analysis
Physics Packages
ERF_ENABLE_RRTMGP- RRTMGP radiation modelRequires
ERF_ENABLE_NETCDF=ONandERF_ENABLE_MPI=ONAutomatically enables Kokkos, from
Submodules/kokkosor from the install that-DKokkos_ROOTpoints at
Native SHOC - Native SHOC turbulence and cloud macrophysics
Always built
Selected at runtime with
erf.pbl_type = NATIVE_SHOC
ERF_ENABLE_NOAHMP- NOAHMP land surface modelRequires the NetCDF Fortran library
GPU Acceleration
Enable exactly one GPU backend:
ERF_ENABLE_CUDA- NVIDIA GPUs (requires CUDA Toolkit ≥ 11.0)ERF_ENABLE_HIP- AMD GPUsERF_ENABLE_SYCL- Intel GPUs
Note
The Kokkos-based RRTMGP radiation package supports all three GPU backends through Kokkos.
Logging Options (CMake 3.25+)
Use hierarchical logging to diagnose build issues:
# Default output
cmake ..
# Show dependency detection
cmake --log-level=VERBOSE ..
# Show all diagnostics
cmake --log-level=DEBUG ..
# Show message hierarchy
cmake --log-context ..
# Combine for detailed output
cmake --log-context --log-level=VERBOSE ..
Example output with --log-context:
[ERF.Cray] Detected Cray Programming Environment (CRAYPE_VERSION=2.7.30)
[ERF.Cray] Setting Cray compiler wrappers...
[ERF.Cray] Set CMAKE_CXX_COMPILER = /opt/cray/pe/craype/default/bin/CC
[ERF.AMReX] Using internal AMReX submodule
[ERF.NetCDF] Found NetCDF: /opt/cray/pe/netcdf/4.9.0.9
Utility Targets
Clean Build Artifacts
Remove all CMake configuration and build artifacts:
make distclean
Removes:
CMake cache and generated files (
CMakeCache.txt,CMakeFiles/, etc.)Build outputs (executables, libraries)
Generated configuration files
Test outputs
The install directory is preserved.
Uninstall
Remove files installed via make install:
make uninstall
Show Cray Configuration
On Cray systems, view auto-detected configuration:
make show-cray-config
This displays detected configuration and can be saved for manual configuration.
Configuration Files
On Cray systems, ERF automatically detects configuration. For manual configuration, use the -C option:
cmake -C path/to/config.cmake ..
Machine-specific profiles in Build/machines/:
perlmutter_erf.profile- NERSC Perlmutter (NVIDIA A100)frontier_erf.profile- OLCF Frontier (AMD MI250X)polaris_erf.profile- ALCF Polaris (NVIDIA A100)aurora_erf.profile- ALCF Aurora (Intel GPUs); expectsNETCDF_DIRfor NetCDF-enabled builds
These profiles are shell scripts that load required modules and set environment variables. Source them before running CMake. For detailed information, see Machine Profiles, Cray Detection, Build Scripts, and Workstation Builds.
Developer Testing
For systematic testing of multiple build configurations:
#!/bin/bash
set -e
set -o pipefail
# Function to verify if a directory is the ERF repo root
verify_erf_dir() {
local dir=$1
# Check for basic structure
if [ ! -f "$dir/CMakeLists.txt" ] || [ ! -d "$dir/Source" ]; then
return 1
fi
# Check for "Energy Research and Forecasting" in key files
local found=0
if [ -f "$dir/README.md" ]; then
if grep -q "Energy Research and Forecasting" "$dir/README.md" 2>/dev/null || true; then
found=1
fi
fi
if [ $found -eq 0 ] && [ -f "$dir/LICENSE.md" ]; then
if grep -q "Energy Research and Forecasting" "$dir/LICENSE.md" 2>/dev/null || true; then
found=1
fi
fi
if [ $found -eq 0 ] && [ -f "$dir/CITATION.cff" ]; then
if grep -q "Energy Research and Forecasting" "$dir/CITATION.cff" 2>/dev/null || true; then
found=1
fi
fi
return $((1 - found))
}
# Function to find ERF repo root
find_erf_dir() {
# Method 1: Check if we're already in Build/
if [ -f "../CMakeLists.txt" ] && [ -d "../Source" ]; then
local candidate="$(cd .. && pwd)"
if verify_erf_dir "$candidate"; then
ERF_DIR="$candidate"
echo "Detected ERF_DIR from Build location: $ERF_DIR"
return 0
fi
fi
# Method 2: Use git to find repo root
if command -v git &> /dev/null; then
if git rev-parse --is-inside-work-tree &> /dev/null 2>&1; then
local git_root="$(git rev-parse --show-toplevel)"
if verify_erf_dir "$git_root"; then
ERF_DIR="$git_root"
echo "Detected ERF_DIR from git: $ERF_DIR"
return 0
fi
fi
fi
# Method 3: Try going up from script location
local script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Check if script is in Build/ directory
if [[ "$script_dir" =~ /Build$ ]]; then
local candidate="$(dirname "$script_dir")"
if verify_erf_dir "$candidate"; then
ERF_DIR="$candidate"
echo "Detected ERF_DIR from script location: $ERF_DIR"
return 0
fi
fi
# Method 4: Check current directory
if verify_erf_dir "$PWD"; then
ERF_DIR="$PWD"
echo "Detected ERF_DIR from current directory: $ERF_DIR"
return 0
fi
return 1
}
# Parse arguments
if [ $# -lt 1 ] || [ $# -gt 3 ]; then
echo "Usage: $0 <set> [script_pattern] [erf_dir]"
echo ""
echo "Sets:"
echo " default - Scripts from Build/"
echo " perlmutter - Scripts from Build/Perlmutter/"
echo " gnu_kokkos - Scripts from Build/GNU_Kokkos/"
echo ""
echo "If script_pattern is provided, creates build_<pattern>/"
echo "Otherwise creates build_<set>/"
echo ""
echo "If erf_dir is provided, uses that as ERF_DIR"
echo "Otherwise auto-detects ERF repo root"
exit 1
fi
SET=$1
PATTERN=${2:-}
ERF_DIR_ARG=${3:-}
# Set ERF_DIR
if [ -n "$ERF_DIR_ARG" ]; then
ERF_DIR="$ERF_DIR_ARG"
echo "Using provided ERF_DIR: $ERF_DIR"
if ! verify_erf_dir "$ERF_DIR"; then
echo "Error: Provided directory is not a valid ERF repository"
echo "Must contain 'Energy Research and Forecasting' in README.md, LICENSE.md, or CITATION.cff"
exit 1
fi
else
if ! find_erf_dir; then
echo "Error: Could not auto-detect ERF_DIR"
echo "Please provide it as the third argument or run from ERF Build/ directory"
echo ""
echo "Verification checks for:"
echo " - CMakeLists.txt and Source/ directory"
echo " - 'Energy Research and Forecasting' in README.md, LICENSE.md, or CITATION.cff"
exit 1
fi
fi
echo "ERF_DIR set to: $ERF_DIR"
# Define source directories relative to ERF_DIR
DEFAULT_DIR="$ERF_DIR/Build"
PERLMUTTER_DIR="$ERF_DIR/Build/Perlmutter"
GNU_KOKKOS_DIR="$ERF_DIR/Build/GNU_Kokkos"
case $SET in
default)
SRC_DIR="$DEFAULT_DIR"
;;
perlmutter)
SRC_DIR="$PERLMUTTER_DIR"
;;
gnu_kokkos)
SRC_DIR="$GNU_KOKKOS_DIR"
;;
*)
echo "Error: Invalid set '$SET'"
echo "Choose: default, perlmutter, or gnu_kokkos"
exit 1
;;
esac
if [ ! -d "$SRC_DIR" ]; then
echo "Error: Source directory does not exist: $SRC_DIR"
exit 1
fi
# Determine build directory name
if [ -n "$PATTERN" ]; then
BUILD_DIR="$ERF_DIR/build_${PATTERN}"
else
BUILD_DIR="$ERF_DIR/build_${SET}"
fi
# Create build directory
mkdir -p "$BUILD_DIR"
echo "Created directory: $BUILD_DIR"
# Find and copy ERF cmake build scripts
echo "Scanning for ERF cmake scripts in $SRC_DIR:"
COPIED=0
SKIPPED=0
# Temporarily disable exit on error for the loop
set +e
for script in "$SRC_DIR"/*.sh; do
# Check if file exists (glob might not match anything)
if [ ! -f "$script" ]; then
continue
fi
basename_script=$(basename "$script")
# Skip backup files
if [[ "$basename_script" =~ ~$ ]]; then
SKIPPED=$((SKIPPED + 1))
continue
fi
# Check if it's an ERF cmake script (contains DERF or cmake)
has_derf=0
has_cmake=0
grep -q "DERF" "$script" 2>/dev/null && has_derf=1
grep -q "cmake" "$script" 2>/dev/null && has_cmake=1
if [ $has_derf -eq 1 ] || [ $has_cmake -eq 1 ]; then
cp "$script" "$BUILD_DIR/"
chmod +x "$BUILD_DIR/$basename_script"
echo " DONE: $basename_script"
COPIED=$((COPIED + 1))
else
echo " ERROR: $basename_script (no DERF or cmake found)"
SKIPPED=$((SKIPPED + 1))
fi
done
# Re-enable exit on error
set -e
echo ""
echo "Summary: Copied $COPIED script(s), skipped $SKIPPED"
if [ $COPIED -eq 0 ]; then
echo "Warning: No ERF cmake scripts found"
echo "Scripts should contain 'DERF' or 'cmake'"
fi
# Create a run script in the build directory
cat > "$BUILD_DIR/run.sh" << 'EOF'
#!/bin/bash
set -e
set -o pipefail
# Resolve ERF_DIR (go up from build directory)
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export ERF_DIR="$(dirname "$SCRIPT_DIR")"
echo "ERF_DIR set to: $ERF_DIR"
# Find all .sh scripts (excluding run.sh and backups)
SCRIPTS=()
for script in *.sh; do
if [ "$script" = "run.sh" ]; then
continue
fi
if [[ "$script" =~ ~$ ]]; then
continue
fi
if [ -f "$script" ]; then
SCRIPTS+=("$script")
fi
done
# Sort scripts alphabetically
IFS=$'\n' SCRIPTS=($(sort <<<"${SCRIPTS[*]}"))
unset IFS
if [ ${#SCRIPTS[@]} -eq 0 ]; then
echo "Error: No build scripts found in this directory"
exit 1
fi
if [ $# -ne 1 ]; then
echo "Usage: $0 <number>"
echo ""
echo "Available ERF cmake scripts:"
for i in "${!SCRIPTS[@]}"; do
script_base="${SCRIPTS[$i]%.sh}"
printf "%3d: %s\n" $((i+1)) "${SCRIPTS[$i]}"
printf " -> subdirectory: %s/script_%s/\n" "$ERF_DIR" "$script_base"
done
echo ""
echo "Each script will run in its own clean subdirectory at ERF root."
exit 1
fi
NUM=$1
if [ $NUM -lt 1 ] || [ $NUM -gt ${#SCRIPTS[@]} ]; then
echo "Error: Number must be between 1 and ${#SCRIPTS[@]}"
exit 1
fi
SCRIPT="${SCRIPTS[$((NUM-1))]}"
SCRIPT_BASE="${SCRIPT%.sh}"
SUBDIR="$ERF_DIR/script_${SCRIPT_BASE}"
# Create a clean subdirectory for this script
if [ -d "$SUBDIR" ]; then
echo "Warning: $SUBDIR already exists"
read -p "Delete and recreate? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf "$SUBDIR"
else
echo "Aborting. Please remove $SUBDIR manually or choose a different script."
exit 1
fi
fi
mkdir -p "$SUBDIR"
echo "========================================"
echo "Running: $SCRIPT"
echo "Build directory: $SUBDIR"
echo "Working directory: $SUBDIR"
echo "========================================"
echo ""
# Copy the script into the subdirectory and run it there
cp "$SCRIPT" "$SUBDIR/"
cd "$SUBDIR"
bash "./$SCRIPT"
EOF
chmod +x "$BUILD_DIR/run.sh"
echo ""
echo "Setup complete!"
echo "Build directory: $BUILD_DIR"
echo ""
echo "To use:"
echo " cd $BUILD_DIR"
echo " ./run.sh # List available scripts"
echo " ./run.sh <number> # Run a specific script"
echo ""
echo "Copied $COPIED script(s)"
Usage:
cd Build
./setup_cmake_validation.sh default # or perlmutter, gnu_kokkos
cd ../build_default
./run.sh # List available scripts
./run.sh 1 # Run first script
Creates isolated build directories for each configuration script. Each script runs in its own subdirectory (script_<name>/) at the ERF root.
Building ERF from a Parent CMake Project
A repository that holds a fire engine, dust model or structure model keeps ERF as a git submodule together with the model’s folders. Such a repository can build ERF in three ways. The third, ERF as a library, is the recommended one: the repository builds its own executable and hands ERF no model directories. FLARE builds this way.
The first configures ERF itself and points the hook variables at the outer folders.
LSFIRE does this from its root, with ERF in
ERF/ and its fire engine in FireEngine/:
cmake -S ERF -B build -DERF_ENABLE_FIRE=ON -DERF_FIRE_ENGINE_DIRS=$PWD/FireEngine
cmake --build build --target erf_exec
The second makes ERF part of the repository’s own CMake project, for a repository that
builds more than erf_exec or adds its own tests. The parent calls add_subdirectory:
cmake_minimum_required(VERSION 3.25) # as ERF's internal AMReX
project(MyModel CXX C)
set(ERF_ENABLE_MOVING_BODIES ON)
set(ERF_STRUCTURE_MODEL_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/Model")
enable_testing() # in the top-level file, so ctest runs from the top build folder
add_subdirectory(Submodules/ERF) # builds erf_exec with the model compiled in
ERF options may be set as normal variables before
add_subdirectory, as above, or as cache variables (-Don the command line). The options ERF sets withset(... CACHE ...), namelyERF_STRUCTURE_MODEL_DIRS,ERF_FIRE_ENGINE_DIRS,ERF_DUST_MODEL_DIRS,ERF_NUM_DUST_SCALARS,ERF_PRECISION,ERF_PARTICLES_PRECISIONandERF_DIM, keep a normal variable from the parent only with CMake 3.21 or newer (policy CMP0126). This matters only with an external AMReX (ERF_USE_INTERNAL_AMREX=OFF), since the internal AMReX needs CMake 3.25.option()keys such asERF_ENABLE_MOVING_BODIESwork either way.Give
ERF_FIRE_ENGINE_DIRS,ERF_STRUCTURE_MODEL_DIRSandERF_DUST_MODEL_DIRSabsolute paths.ERF’s paths refer to its own source and build folders, so
erf_execis in<build>/<ERF binary dir>/Execand ERF’s tests (withERF_ENABLE_TESTS=ON) find it there. The parent can refer to the executable as$<TARGET_FILE:erf_exec>.Under a parent project ERF adds no
uninstallordistcleantargets and does not export its CMake package; those act on the top-level build and belong to the parent.cmake --installon the parent still installserf_exec, ERF’s library and AMReX.ERF sets the AMReX options (
AMReX_PRECISION,AMReX_SPACEDIMand others) from its own; a parent should set ERF’s options, not theAMReX_*ones.On Cray systems ERF’s compiler detection is skipped under a parent, because the parent’s
project()has already chosen the compilers.
The parent can register its own regression cases with ERF’s general CTest helpers,
which Tests/ERFTestHelpers.cmake holds: add_test_r (run a deck and compare the
plotfile with a gold plotfile by fcompare), add_test_abort (pass when a run stops
with a given message), add_test_restart_abort, add_test_plotfile_header, and the
setup_test and resolve_test_exe they use. ERF’s own Tests/CTestList.cmake
includes the same file.
add_subdirectory(Submodules/ERF)
set(ERF_TEST_GOLD_FILES_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/GoldFiles")
include(Submodules/ERF/Tests/ERFTestHelpers.cmake)
add_test_r(MyCase "" erf_exec plt00010) # deck test_files/MyCase/MyCase.i
Include the file after
add_subdirectory, in each directory that calls the helpers.A test’s files are read from
test_files/<test name>of the directory that calls the helper, andadd_test_rcompares with${ERF_TEST_GOLD_FILES_DIRECTORY}/<test name>. A normal variableERF_TEST_GOLD_FILES_DIRECTORY, set afteradd_subdirectoryas above, gives the parent its own gold folder without changing ERF’s. Set beforeadd_subdirectory, it would also become the gold folder of ERF’s own tests.add_test_rneedsFCOMPARE_EXE,ERF_TEST_GOLD_FILES_DIRECTORY,ERF_TEST_FCOMPARE_RTOLandERF_TEST_FCOMPARE_ATOL, andERF_TEST_NRANKSwithERF_ENABLE_MPI; it stops the configure, naming the variable, when one is empty.ERF_ENABLE_FCOMPARE=ONbuildsfcompare, andERF_ENABLE_TESTS=ONsets the tolerances, the rank count and ERF’s gold folder as cache entries. Without ERF’s tests, the parent sets them itself as normal variables.A caller’s normal variable
TEST_FILES_DIRreplaces<test name>in the folder the inputs are read from, as ERF’s own list uses it; leave it unset otherwise.The helpers find
erf_execand ERF’s checker scripts throughERF_BINARY_DIRandERF_SOURCE_DIR, so they work from any directory of the parent.
Tests/ParentProject holds a small parent project that does this with the example
structure model (Tests/StructureModelExample) copied to a folder outside the ERF
tree. It has a run checked against the closed form; three cases registered with
add_test_abort and add_test_r (gold in the parent’s own folder), one of which must
fail, to show that fcompare compares; and, with ERF_ENABLE_UNIT_TESTS=ON, a run of
the model’s GoogleTest added through erf_structure_model_add_unit_tests.
The parent-project CI workflow builds it and runs the tests; its README.md gives
the commands.
ERF as a library
A third way uses ERF as ERF uses AMReX. ERF is a library, ERF::erf, and the parent
builds its own executables from its own sources (its engines or models and its own
ERF_Prob.cpp) with erf_setup_executable. The parent hands ERF none of the
model-directory hooks: its sources are compiled into its own executable, and their
registrations (ERF_REGISTER_FIRE_ENGINE, ERF_REGISTER_DUST_MODEL,
ERF_REGISTER_STRUCTURE_MODEL) run from there.
cmake_minimum_required(VERSION 3.25)
project(MyModel CXX C)
set(ERF_ENABLE_MOVING_BODIES ON) # the couplings the parent's sources need
enable_testing()
add_subdirectory(Submodules/ERF ERF EXCLUDE_FROM_ALL) # build only what my_model needs
add_executable(my_model Model/MyStructureModel.cpp ERF_Prob.cpp)
target_include_directories(my_model PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
erf_setup_executable(my_model) # ERF's main.cpp, ERF::erf, ERF's compile and GPU flags
erf_setup_executable(<target> [NO_ERF_MAIN])adds ERF’smain.cpp(unlessNO_ERF_MAIN, for a GoogleTest executable, say), linksERF::erfand sets ERF’s compile flags, and the CUDA settings withERF_ENABLE_CUDA. ERF’s own executables are set up the same way (build_erf_exe, the same function under its older name).ERF::erfcarries ERF’s compile definitions (ERF_USE_FIRE,ERF_USE_DUST,ERF_NUM_DUST_SCALARSand the others) and include folders to the parent’s sources, asAMReX::amrexcarriesAMREX_SPACEDIMto ERF’s. Set ERF’s options beforeadd_subdirectory, so that both sides see the same state layout.The parent’s problem file plays the part of ERF’s
Exec/ERF_Prob.cpp; a copy of ERF’s is a fine start.ERF’s test helpers take the parent’s executable target:
add_test_r(MyCase "" my_model plt00010), and a normal variableERF_TEST_EXEnames it foradd_test_abortandadd_test_restart_abort.ERF_BUILD_LIBRARY_ONLYis a different mode, for building ERF together with another AMReX code (REMORA) into one executable; it renames some of ERF’s symbols and compiles ERF’s own problem file into the library. A parent that builds an ERF executable does not set it.
Tests/ParentExecutable holds a small parent project that does this: its executable is
built from a copy of the example structure model and of ERF’s problem file, kept outside
the ERF tree. It checks a run against the closed form, and runs add_test_abort on the
parent’s executable. The parent-project CI workflow builds and runs it too.
Building Documentation
Build ERF documentation with CMake:
cmake -DERF_ENABLE_DOCUMENTATION=ON ..
make docs
This builds both Sphinx and Doxygen documentation.