Skip to content

Commit 9234362

Browse files
committed
Merge branch 'main' into major/ui-io-upgrade
2 parents 24f6874 + d0603e5 commit 9234362

7 files changed

Lines changed: 361 additions & 42 deletions

File tree

CMakeLists.txt

Lines changed: 121 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,43 @@ set(HDF5_USE_STATIC_LIBRARIES ON)
169169
set(HDF5_ROOT "${HDF5_ROOT}" CACHE PATH "HDF5 root directory")
170170
find_package(HDF5 REQUIRED COMPONENTS CXX)
171171

172-
# ── Platform-Specific Fixes ──
173-
# Fix for VS 2017 15.8+ to handle alignment specification with Eigen
172+
# ---- Eigen: support both CONFIG and module modes ----
173+
find_package(Eigen3 QUIET CONFIG)
174+
if (NOT Eigen3_FOUND)
175+
find_package(Eigen3 REQUIRED) # module mode -> EIGEN3_INCLUDE_DIR
176+
endif()
177+
178+
# ---- Chrono include path: prefer imported target; fall back to vars; fall back to build tree ----
179+
set(HC_CHRONO_INCLUDE_DIRS "")
180+
181+
# Prefer INTERFACE includes from an imported target, if provided
182+
if (TARGET Chrono::Chrono_core)
183+
get_target_property(HC_CHRONO_INCLUDE_DIRS Chrono::Chrono_core INTERFACE_INCLUDE_DIRECTORIES)
184+
endif()
185+
186+
# Fallback to legacy variable if the package sets it
187+
if (NOT HC_CHRONO_INCLUDE_DIRS AND DEFINED CHRONO_INCLUDE_DIRS)
188+
set(HC_CHRONO_INCLUDE_DIRS ${CHRONO_INCLUDE_DIRS})
189+
endif()
190+
191+
# Derive from Chrono_DIR when using Chrono from a build tree (headers live under <chrono_root>/src)
192+
if (NOT HC_CHRONO_INCLUDE_DIRS AND DEFINED Chrono_DIR)
193+
get_filename_component(_CHR_CMAKE_DIR "${Chrono_DIR}" ABSOLUTE) # .../chrono/build/cmake
194+
get_filename_component(_CHR_BUILD_DIR "${_CHR_CMAKE_DIR}" DIRECTORY)# .../chrono/build
195+
get_filename_component(_CHR_ROOT "${_CHR_BUILD_DIR}" DIRECTORY)# .../chrono
196+
set(_CHR_INC_CAND "${_CHR_ROOT}/src")
197+
if (EXISTS "${_CHR_INC_CAND}/chrono/core/ChMatrix.h")
198+
set(HC_CHRONO_INCLUDE_DIRS "${_CHR_INC_CAND}")
199+
endif()
200+
endif()
201+
202+
203+
204+
205+
#-----------------------------------------------------------------------------
206+
# Fix for VS 2017 15.8 and newer to handle alignment specification with Eigen
207+
#-----------------------------------------------------------------------------
208+
174209
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
175210
if(MSVC AND ${MSVC_VERSION} GREATER_EQUAL 1915)
176211
add_compile_definitions("ENABLE_EXTENDED_ALIGNED_STORAGE")
@@ -274,6 +309,32 @@ configure_hydro_target(HydroChrono)
274309
# Add HDF5 as private dependency (don't expose to users)
275310
target_include_directories(HydroChrono PRIVATE ${HDF5_INCLUDE_DIRS})
276311
target_link_libraries(HydroChrono PRIVATE ${HDF5_LIBRARIES})
312+
target_compile_features(HydroChrono PUBLIC cxx_std_17)
313+
314+
# target_include_directories(
315+
# HydroChrono
316+
317+
# PUBLIC
318+
# $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
319+
# $<INSTALL_INTERFACE:include>
320+
# ${CHRONO_INCLUDE_DIRS}
321+
322+
# PRIVATE
323+
# ${CMAKE_CURRENT_SOURCE_DIR}/
324+
# ${CMAKE_CURRENT_SOURCE_DIR}/include
325+
# ${HDF5_INCLUDE_DIRS}
326+
# )
327+
328+
target_include_directories(HydroChrono
329+
PUBLIC
330+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
331+
$<INSTALL_INTERFACE:include>
332+
${HC_CHRONO_INCLUDE_DIRS} # <— ensures chrono/ headers are visible
333+
PRIVATE
334+
${CMAKE_CURRENT_SOURCE_DIR}
335+
${CMAKE_CURRENT_SOURCE_DIR}/include
336+
${HDF5_INCLUDE_DIRS}
337+
)
277338

278339
# Library-specific compile definitions
279340
target_compile_definitions(HydroChrono
@@ -320,13 +381,71 @@ if(HYDROCHRONO_ENABLE_YAML_RUNNER)
320381
else()
321382
message(STATUS "YAML runner disabled - not creating run_hydrochrono target")
322383
endif()
384+
target_link_libraries(HydroChrono
385+
PUBLIC
386+
${CHRONO_TARGETS} # Chrono::Chrono_core;Chrono::Chrono_irrlicht;...
387+
$<$<TARGET_EXISTS:Eigen3::Eigen>:Eigen3::Eigen>
388+
PRIVATE
389+
${HDF5_LIBRARIES}
390+
)
391+
392+
# If Eigen is module-mode (no imported target), include its dir
393+
if (NOT TARGET Eigen3::Eigen AND DEFINED EIGEN3_INCLUDE_DIR)
394+
target_include_directories(HydroChrono PUBLIC ${EIGEN3_INCLUDE_DIR})
395+
endif()
396+
397+
# ====================
398+
# Irrlicht GUI helper
399+
# ====================
323400

324401
# ── GUI Helper Library ──
325402
# Separate library for Irrlicht visualization helpers
326403
add_library(HydroChronoGUI src/gui/guihelper.cpp)
327404
configure_hydro_target(HydroChronoGUI)
328405

329406
# ── Demo Executables ──
407+
target_sources(
408+
HydroChronoGUI
409+
410+
PUBLIC
411+
src/gui/guihelper.cpp
412+
)
413+
414+
target_compile_features(HydroChronoGUI PUBLIC cxx_std_17)
415+
416+
417+
target_include_directories(HydroChronoGUI
418+
PUBLIC
419+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
420+
$<INSTALL_INTERFACE:include>
421+
${HC_CHRONO_INCLUDE_DIRS}
422+
)
423+
424+
target_compile_options(HydroChronoGUI BEFORE
425+
PUBLIC
426+
${CHRONO_CXX_FLAGS}
427+
)
428+
429+
target_link_options(HydroChronoGUI BEFORE
430+
PUBLIC
431+
${CHRONO_LINKER_FLAGS}
432+
)
433+
434+
target_link_libraries(HydroChronoGUI
435+
PUBLIC
436+
${CHRONO_TARGETS}
437+
$<$<TARGET_EXISTS:Eigen3::Eigen>:Eigen3::Eigen>
438+
)
439+
440+
if (NOT TARGET Eigen3::Eigen AND DEFINED EIGEN3_INCLUDE_DIR)
441+
target_include_directories(HydroChronoGUI PUBLIC ${EIGEN3_INCLUDE_DIR})
442+
endif()
443+
444+
445+
446+
# ====================
447+
# DEMOS
448+
# ====================
330449
if(HYDROCHRONO_ENABLE_DEMOS)
331450
add_subdirectory(demos)
332451
endif()

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 National Renewable Energy Laboratory
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,52 +27,74 @@ Visit the [HydroChrono website](https://nrel.github.io/HydroChrono/) for informa
2727

2828
### Prerequisites
2929

30-
- CMake 3.16 or higher
31-
- A C++ compiler (Visual Studio 2019 or higher, or GCC through MinGW/MSYS2)
32-
- Project Chrono (built from source, tested with v9.0.0 and v9.0.1)
33-
- HDF5 1.10.8 or higher
34-
- Python 3.8 or higher (with numpy and matplotlib)
35-
36-
### Building from Source
30+
- **Visual Studio 2022** with C++ toolchain
31+
- **CMake 3.18+**
32+
- **Project Chrono** (built from source; tested v9.0.0–v9.0.1)
33+
- **HDF5 1.10.8+**
34+
- **Eigen 3.4+** (header-only unzip is fine)
35+
- **Irrlicht 1.8.x** (optional but required for GUI helper)
36+
- **Python 3.8+** (only for docs/tools)
37+
38+
### Building from Source (using `build-config.json` + script)
39+
40+
1. **Clone the repository**
41+
```powershell
42+
git clone https://github.com/NREL/HydroChrono.git
43+
cd HydroChrono
44+
```
45+
46+
2. **Create your local config from the example**
47+
```powershell
48+
copy build-config.example.json build-config.json
49+
```
50+
51+
3. **Edit `build-config.json`** and set paths for your machine
52+
53+
**Example:**
54+
```json
55+
{
56+
"ChronoDir": "C:/path/to/chrono/build/cmake",
57+
"Hdf5Dir": "C:/path/to/hdf5/share/cmake",
58+
"EigenDir": "C:/path/to/eigen-3.4.0",
59+
"IrrlichtDir": "C:/path/to/irrlicht-1.8.4",
60+
"PythonRoot": "C:/Users/<you>/.conda/envs/<env>",
61+
"CMakeModulePath": "C:/path/to/chrono/build/cmake"
62+
}
63+
```
64+
65+
4. **Build (from repo root)**
66+
67+
- Clean configure + build (default `Release`):
68+
```powershell
69+
.\quick-build.ps1 -Clean
70+
```
71+
- Build a different configuration (e.g., `Debug`):
72+
```powershell
73+
.\quick-build.ps1 -BuildType Debug
74+
```
75+
76+
4. **Post-Build Steps**
77+
78+
Copy the following DLL files from your Chrono build directory to your build directory's `build/bin` folder:
79+
- ChronoEngine.dll
80+
- ChronoEngine_irrlicht.dll (if using Irrlicht)
81+
- Irrlicht.dll (if using Irrlicht)
3782
38-
1. Clone the repository:
39-
```powershell
40-
git clone https://github.com/NREL/HydroChrono.git
41-
cd HydroChrono
42-
```
83+
5. **Run the tests**
84+
```powershell
85+
cd build
86+
ctest -C Release
87+
```
4388

44-
2. Create a build directory and navigate to it:
45-
```powershell
46-
mkdir build
47-
cd build
48-
```
49-
50-
3. Configure and build the project:
51-
```powershell
52-
cmake .. -DChrono_DIR="<path_to_chrono_build>/cmake" -DHDF5_DIR="<path_to_hdf5_cmake>" -DPython3_ROOT_DIR="<path_to_python>"
53-
cmake --build . --config Release
54-
```
55-
56-
4. Run the tests:
57-
```powershell
58-
ctest -C Release --output-on-failure
59-
```
89+
---
6090

6191
### Clean Build
6292

63-
To perform a clean rebuild of the project:
6493
```powershell
6594
# From the project root
6695
Remove-Item -Recurse -Force build
67-
mkdir build
68-
cd build
96+
# then reconfigure/build
97+
.\quick-build.ps1 -Clean
6998
```
7099

71-
### Post-Build Steps
72-
73-
Copy the following DLL files from your Chrono build directory to your build directory's `demos/Release` folder:
74-
- ChronoEngine.dll
75-
- ChronoEngine_irrlicht.dll (if using Irrlicht)
76-
- Irrlicht.dll (if using Irrlicht)
77-
78-
For detailed build instructions, including Visual Studio setup and running demos, see the [developer documentation](https://nrel.github.io/HydroChrono/developer_docs/build_instructions.html).
100+
For more detailed build instructions, including Visual Studio setup and running demos, see the [developer documentation](https://nrel.github.io/HydroChrono/developer_docs/build_instructions.html).

build-config-example.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"ChronoDir": "C:/path/to/chrono/build/cmake",
3+
"Hdf5Dir": "C:/path/to/hdf5/share/cmake",
4+
"EigenDir": "C:/path/to/eigen-3.4.0",
5+
"IrrlichtDir": "C:/path/to/irrlicht-1.8.4",
6+
"PythonRoot": "C:/Users/<you>/.conda/envs/<env>",
7+
"ScriptVersion": "2.1",
8+
"DefaultBuildType": "Release",
9+
"DefaultYamlRunner": "ON",
10+
"VisualStudioPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC",
11+
"RuntimeLibrary": "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL",
12+
"CMakeModulePath": "C:/path/to/chrono/build/cmake"
13+
}

docs/_main_pages/developer_docs/build_instructions.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ This is the recommended way to build HydroChrono.
7878
```
7979
Note: The Chrono build directory typically contains a `cmake` folder with the Chrono CMake configuration files.
8080

81+
**⚠️ Important:** The build type (e.g., Release, Debug, RelWithDebInfo) used to build HydroChrono **must match** the build type used when building Project Chrono. On Windows, this is set when running `cmake --build . --config Release`. For more context on build configurations and CMake behavior across platforms, see [CMake Build Configuration Basics](/developer_docs/cmake_build_basics).
82+
8183
3. **Build the Project**
8284
Compile the project using the following command:
8385
```powershell
@@ -103,13 +105,15 @@ If you prefer using Visual Studio, you can use the CMake GUI to generate a Visua
103105
- Enable the following options for additional features: `HYDROCHRONO_ENABLE_DEMOS`, `HYDROCHRONO_ENABLE_IRRLICHT`, and `HYDROCHRONO_ENABLE_TESTS`
104106
- To build the docs: set `Python3_ROOT_DIR` to your Python environment with required packages
105107

108+
**⚠️ Important:** The build type (e.g., Release, Debug, RelWithDebInfo) used to build HydroChrono **must match** the build type used when building Project Chrono. On Windows, this is set when running `cmake --build . --config Release`. For more context on build configurations and CMake behavior across platforms, see [CMake Build Configuration Basics](/developer_docs/cmake_build_basics).
109+
106110
3. Click "Generate" to create the Visual Studio solution.
107111

108112
4. Open the generated solution in Visual Studio and build the project.
109113

110114
## Post-Build Steps
111115

112-
1. Copy the `chrono_build/bin/data` file from the Project Chrono build directory to your build directory's `data` folder to obtain optional shaders and logos.
116+
1. Copy the `chrono_build/bin/data` folder from the Project Chrono build directory to your build directory's `data` folder to obtain optional shaders and logos.
113117

114118
2. Copy the following DLL files from your Chrono build directory to your build directory's `demos/Release` folder:
115119
- ChronoEngine.dll

0 commit comments

Comments
 (0)