Skip to content

Commit a88d575

Browse files
committed
build(windows): add quick-build.ps1 and config template
- add quick-build.ps1 for MSVC configure+build - add build-config.example.json; ignore build-config.json - update README with Windows build steps using config+script - cmake: link Chrono/Eigen targets and propagate include dirs - update .gitignore
1 parent 75b3d98 commit a88d575

5 files changed

Lines changed: 186 additions & 66 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# IDE Specific
22
.vs/
33
*.launch
4-
*.json
54
.editorconfig
65

76
# Compiled source
@@ -54,3 +53,4 @@ Testing/Temporary/LastTest.log
5453
# Test results (ignore all results/ directories)
5554
results/
5655
**/results/
56+
build-config.json

CMakeLists.txt

Lines changed: 79 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,39 @@ set(HDF5_ROOT "${HDF5_ROOT}" CACHE PATH "HDF5 root directory")
8181

8282
find_package(HDF5 REQUIRED COMPONENTS CXX)
8383

84+
# ---- Eigen: support both CONFIG and module modes ----
85+
find_package(Eigen3 QUIET CONFIG)
86+
if (NOT Eigen3_FOUND)
87+
find_package(Eigen3 REQUIRED) # module mode -> EIGEN3_INCLUDE_DIR
88+
endif()
89+
90+
# ---- Chrono include path: prefer imported target; fall back to vars; fall back to build tree ----
91+
set(HC_CHRONO_INCLUDE_DIRS "")
92+
93+
# Prefer INTERFACE includes from an imported target, if provided
94+
if (TARGET Chrono::Chrono_core)
95+
get_target_property(HC_CHRONO_INCLUDE_DIRS Chrono::Chrono_core INTERFACE_INCLUDE_DIRECTORIES)
96+
endif()
97+
98+
# Fallback to legacy variable if the package sets it
99+
if (NOT HC_CHRONO_INCLUDE_DIRS AND DEFINED CHRONO_INCLUDE_DIRS)
100+
set(HC_CHRONO_INCLUDE_DIRS ${CHRONO_INCLUDE_DIRS})
101+
endif()
102+
103+
# Derive from Chrono_DIR when using Chrono from a build tree (headers live under <chrono_root>/src)
104+
if (NOT HC_CHRONO_INCLUDE_DIRS AND DEFINED Chrono_DIR)
105+
get_filename_component(_CHR_CMAKE_DIR "${Chrono_DIR}" ABSOLUTE) # .../chrono/build/cmake
106+
get_filename_component(_CHR_BUILD_DIR "${_CHR_CMAKE_DIR}" DIRECTORY)# .../chrono/build
107+
get_filename_component(_CHR_ROOT "${_CHR_BUILD_DIR}" DIRECTORY)# .../chrono
108+
set(_CHR_INC_CAND "${_CHR_ROOT}/src")
109+
if (EXISTS "${_CHR_INC_CAND}/chrono/core/ChMatrix.h")
110+
set(HC_CHRONO_INCLUDE_DIRS "${_CHR_INC_CAND}")
111+
endif()
112+
endif()
113+
114+
115+
116+
84117
#-----------------------------------------------------------------------------
85118
# Fix for VS 2017 15.8 and newer to handle alignment specification with Eigen
86119
#-----------------------------------------------------------------------------
@@ -144,18 +177,29 @@ add_library(HydroChrono STATIC ${HYDROCHRONO_SOURCES} )
144177

145178
target_compile_features(HydroChrono PUBLIC cxx_std_17)
146179

147-
target_include_directories(
148-
HydroChrono
149-
150-
PUBLIC
151-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
152-
$<INSTALL_INTERFACE:include>
153-
${CHRONO_INCLUDE_DIRS}
154-
155-
PRIVATE
156-
${CMAKE_CURRENT_SOURCE_DIR}/
157-
${CMAKE_CURRENT_SOURCE_DIR}/include
158-
${HDF5_INCLUDE_DIRS}
180+
# target_include_directories(
181+
# HydroChrono
182+
183+
# PUBLIC
184+
# $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
185+
# $<INSTALL_INTERFACE:include>
186+
# ${CHRONO_INCLUDE_DIRS}
187+
188+
# PRIVATE
189+
# ${CMAKE_CURRENT_SOURCE_DIR}/
190+
# ${CMAKE_CURRENT_SOURCE_DIR}/include
191+
# ${HDF5_INCLUDE_DIRS}
192+
# )
193+
194+
target_include_directories(HydroChrono
195+
PUBLIC
196+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
197+
$<INSTALL_INTERFACE:include>
198+
${HC_CHRONO_INCLUDE_DIRS} # <— ensures chrono/ headers are visible
199+
PRIVATE
200+
${CMAKE_CURRENT_SOURCE_DIR}
201+
${CMAKE_CURRENT_SOURCE_DIR}/include
202+
${HDF5_INCLUDE_DIRS}
159203
)
160204

161205
target_compile_definitions(HydroChrono
@@ -182,13 +226,19 @@ set_target_properties(HydroChrono
182226
POSITION_INDEPENDENT_CODE ON
183227
)
184228
185-
target_link_libraries(HydroChrono
186-
PUBLIC
187-
${CHRONO_LIBRARIES}
188-
PRIVATE
189-
${HDF5_LIBRARIES}
229+
target_link_libraries(HydroChrono
230+
PUBLIC
231+
${CHRONO_TARGETS} # Chrono::Chrono_core;Chrono::Chrono_irrlicht;...
232+
$<$<TARGET_EXISTS:Eigen3::Eigen>:Eigen3::Eigen>
233+
PRIVATE
234+
${HDF5_LIBRARIES}
190235
)
191236
237+
# If Eigen is module-mode (no imported target), include its dir
238+
if (NOT TARGET Eigen3::Eigen AND DEFINED EIGEN3_INCLUDE_DIR)
239+
target_include_directories(HydroChrono PUBLIC ${EIGEN3_INCLUDE_DIR})
240+
endif()
241+
192242
# ====================
193243
# Irrlicht GUI helper
194244
# ====================
@@ -205,13 +255,11 @@ target_sources(
205255
target_compile_features(HydroChronoGUI PUBLIC cxx_std_17)
206256
207257
208-
target_include_directories(
209-
HydroChronoGUI
210-
211-
PUBLIC
212-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
213-
$<INSTALL_INTERFACE:include>
214-
${CHRONO_INCLUDE_DIRS}
258+
target_include_directories(HydroChronoGUI
259+
PUBLIC
260+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
261+
$<INSTALL_INTERFACE:include>
262+
${HC_CHRONO_INCLUDE_DIRS}
215263
)
216264
217265
target_compile_options(HydroChronoGUI BEFORE
@@ -225,10 +273,15 @@ target_link_options(HydroChronoGUI BEFORE
225273
)
226274
227275
target_link_libraries(HydroChronoGUI
228-
PRIVATE
229-
${CHRONO_LIBRARIES}
276+
PUBLIC
277+
${CHRONO_TARGETS}
278+
$<$<TARGET_EXISTS:Eigen3::Eigen>:Eigen3::Eigen>
230279
)
231280
281+
if (NOT TARGET Eigen3::Eigen AND DEFINED EIGEN3_INCLUDE_DIR)
282+
target_include_directories(HydroChronoGUI PUBLIC ${EIGEN3_INCLUDE_DIR})
283+
endif()
284+
232285
233286
234287
# ====================

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+
}

quick-build.ps1

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
param(
2+
[string]$BuildType = "Release",
3+
[switch]$Clean
4+
)
5+
6+
# load config
7+
$cfgPath = Join-Path $PSScriptRoot "build-config.json"
8+
$cfg = Get-Content $cfgPath -Raw | ConvertFrom-Json
9+
10+
$root = $PSScriptRoot
11+
$buildDir = Join-Path $root "build"
12+
13+
if ($Clean -and (Test-Path $buildDir)) { Remove-Item -Recurse -Force $buildDir }
14+
New-Item -ItemType Directory -Force -Path $buildDir | Out-Null
15+
16+
# Avoid PowerShell expanding $... in the generator expression: use single quotes
17+
$msvcRt = 'MultiThreaded$<$<CONFIG:Debug>:Debug>DLL'
18+
19+
# Optional: honor custom module path if you use one
20+
if ($cfg.CMakeModulePath) { $env:CMAKE_MODULE_PATH = $cfg.CMakeModulePath }
21+
22+
# Configure
23+
cmake -S $root -B $buildDir -G "Visual Studio 17 2022" -A x64 `
24+
-DChrono_DIR="$($cfg.ChronoDir)" `
25+
-DHDF5_DIR="$($cfg.Hdf5Dir)" `
26+
-DEIGEN3_INCLUDE_DIR="$($cfg.EigenDir)" `
27+
-DIrrlicht_ROOT="$($cfg.IrrlichtDir)" `
28+
-DPython3_ROOT_DIR="$($cfg.PythonRoot)" `
29+
-DCMAKE_MSVC_RUNTIME_LIBRARY="$msvcRt"
30+
31+
# Build
32+
cmake --build $buildDir --config $BuildType

0 commit comments

Comments
 (0)