CMake Build Structure
HydroChrono CMake Build Structure
This page gives a brief overview of how CMakeLists.txt is organized, why it’s structured this way, and what to change when adding features. It reflects the current top‑level CMakeLists.txt in this repo.
This is internal developer documentation for contributors working on HydroChrono’s build/packaging.
Overview
The top‑level file is split into clearly marked sections:
- Prerequisites & Policies
- Project Definition & Defaults
- User Options
- Find Dependencies
- Core Library Target
- Auxiliary Targets (GUI, Tests, Demos)
- Installation & Packaging
Banner comments separate sections so it’s easy to navigate and reason about changes.
1) Prerequisites & Policies
cmake_minimum_required(3.18.2)(CMP0091, modern target props)CMP0091 NEWto control MSVC runtime viaCMAKE_MSVC_RUNTIME_LIBRARY- Guard against in‑source builds
2) Project Definition & Defaults
- Project
HydroChrono(C++) - Default build type: Release (Debug/MinSizeRel/RelWithDebInfo supported)
cmake/added toCMAKE_MODULE_PATH(local modules)- Generates
version.hunderbuild/generated/
3) User Options (feature toggles)
HYDROCHRONO_ENABLE_TESTSHYDROCHRONO_ENABLE_IRRLICHTHYDROCHRONO_ENABLE_DEMOSHYDROCHRONO_ENABLE_YAML_RUNNERHYDROCHRONO_ENABLE_LOGGING,HYDROCHRONO_ENABLE_USER_DOC,HYDROCHRONO_ENABLE_PROG_DOC
Enable lean builds (e.g., CI) or developer variants.
4) Find Dependencies
Chrono
find_package(Chrono CONFIG REQUIRED)- If Irrlicht is enabled, find
Irrlichtfirst soChrono::Chrono_irrlichtexists - Extend
CMAKE_MODULE_PATHwithChrono_DIRwhen needed
HDF5 & Eigen
- HDF5 required:
find_package(HDF5 REQUIRED COMPONENTS CXX); link static to avoid DLL issues - Eigen via config or module mode
Platform notes
- MSVC: a few warning suppressions; Eigen aligned‑storage workaround
5) Core Library Target
Libraries:
HydroChrono— core hydrodynamics (HDF5 I/O, YAML, utilities)HydroChronoGUI— GUI helpers when Irrlicht is enabled
configure_hydro_target(<tgt>) centralizes: C++ standard, PIC, include dirs, Chrono links.
Key links:
HydroChrono→Chrono::Chrono_core(+ HDF5)HydroChronoGUI→ Chrono (+Chrono::Chrono_irrlichtwhen enabled)
6) Auxiliary Targets (GUI, Tests, Demos)
YAML‑Driven CLI
- Executable:
run_hydrochrono(built on top of theHydroChronolibrary) - Links:
HydroChrono,HydroChronoGUI,Chrono::Chrono_parsers - Minimal CLI wrapper: runner sources and small utils
Why library + CLI split?
- Clear separation: core in
HydroChrono; thin CLI wrapper.- Reuse & testing: same core for tests/demos/GUI; tests link the lib directly.
- Packaging & speed: multiple frontends, faster CLI relinks, keep extras out of core.
Tests & Demos
- If enabled, tests are added via
add_subdirectory(tests)andadd_subdirectory(tests/regression) - A helper
configure_test_environment()assembles PATH on Windows so Chrono/Irrlicht DLLs are found when tests run from the build tree - Demos can be included behind
HYDROCHRONO_ENABLE_DEMOS
Runtime concerns that affect tests:
- Matching build types between Chrono and HydroChrono (Release vs Debug)
- DLL search order on Windows
7) Installation & Packaging
Two layers:
1) Dev kit (optional)
HC_INSTALL_DEV_KIT(OFF by default)- Installs headers, libs, and
HydroChronoConfig.cmake/targets for downstreamfind_package(HydroChrono)
2) Runtime (default)
- Flat layout via
cmake --install+ CPack ZIP - Installs
run_hydrochrono.exe, required DLLs, curated tests - Copies Chrono visual assets into
data/; includestests/RUN-TESTS.ps1
CPack (ZIP): cpack -C Release yields a ready‑to‑share artifact.
Tips for Modifying the Build
- Add new features behind options (e.g.,
HYDROCHRONO_ENABLE_<FEATURE>) with sensible defaults - Update
configure_hydro_target()instead of duplicating setup - Prefer imported targets (e.g.,
Chrono::Chrono_core) over manual flags - Avoid hardcoded paths; expose
CACHEvariables when needed - Keep section banners to make diffs/reviews faster
Related Docs