@@ -52,10 +52,10 @@ configure_file(${CMAKE_SOURCE_DIR}/cmake/version.h.in
5252# Add the cmake folder so the FindSphinx module is found
5353set (CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR} /cmake" ${CMAKE_MODULE_PATH} )
5454
55- # Deterministic dependency discovery (avoid ambient PATH/registry drift)
55+ # Prefer config-mode package discovery (finds vcpkg *-config.cmake files
56+ # instead of CMake's built-in Find*.cmake modules which may not understand vcpkg).
5657set (CMAKE_FIND_PACKAGE_PREFER_CONFIG ON )
5758set (CMAKE_FIND_USE_PACKAGE_REGISTRY OFF )
58- set (CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH OFF )
5959
6060# Force Release by default so CI builds are optimized and users get good performance
6161if (NOT DEFINED HYDROCHRONO_DEFAULT_BUILD_TYPE)
@@ -79,6 +79,7 @@ option(HYDROCHRONO_ENABLE_IRRLICHT "Enable Irrlicht visualization library" OFF)
7979option (HYDROCHRONO_ENABLE_VSG "Enable VSG visualization library" OFF )
8080option (HYDROCHRONO_ENABLE_DEMOS "Enable demo executables" OFF )
8181option (HYDROCHRONO_ENABLE_YAML_RUNNER "Enable YAML-based CLI runner" OFF )
82+ option (HYDROCHRONO_ENABLE_MOORDYN "Enable MoorDyn mooring coupling" OFF )
8283
8384# ===============================================================================
8485# ------ Build setup ------------------------------------------------------------
@@ -167,6 +168,16 @@ if(NOT Chrono_DIR)
167168 return ()
168169endif ()
169170
171+ # Chrono's export file may reference hdf5::hdf5_tools-{shared,static} which is
172+ # absent from some HDF5 installations (e.g., vcpkg). Provide empty shims so
173+ # ChronoTargets.cmake loads without errors. Must be created BEFORE find_package(Chrono).
174+ if (NOT TARGET hdf5::hdf5_tools-shared)
175+ add_library (hdf5::hdf5_tools-shared INTERFACE IMPORTED )
176+ endif ()
177+ if (NOT TARGET hdf5::hdf5_tools-static)
178+ add_library (hdf5::hdf5_tools-static INTERFACE IMPORTED )
179+ endif ()
180+
170181find_package (Chrono
171182 CONFIG REQUIRED
172183 COMPONENTS Parsers )
@@ -239,7 +250,33 @@ endif()
239250find_package (OpenMP REQUIRED COMPONENTS CXX )
240251
241252# -- HDF5 Integration --
242- find_package (HDF5 REQUIRED COMPONENTS CXX )
253+ # Prefer config-mode (vcpkg, official HDF5 installer). Fall back to CMake's
254+ # built-in FindHDF5 module for system-installed packages (apt, yum, brew, etc.).
255+ find_package (HDF5 CONFIG QUIET )
256+ if (NOT HDF5_FOUND)
257+ find_package (HDF5 REQUIRED COMPONENTS CXX )
258+ endif ()
259+
260+ # -- MoorDyn mooring library (optional) --
261+ if (HYDROCHRONO_ENABLE_MOORDYN)
262+ message (STATUS "\n ---- MoorDyn mooring library" )
263+ set (EXTERNAL_EIGEN OFF CACHE BOOL "Use MoorDyn bundled Eigen" FORCE )
264+ set (PYTHON_WRAPPER OFF CACHE BOOL "Disable MoorDyn Python wrapper" FORCE )
265+ set (FORTRAN_WRAPPER OFF CACHE BOOL "Disable MoorDyn Fortran wrapper" FORCE )
266+ set (MATLAB_WRAPPER OFF CACHE BOOL "Disable MoorDyn MATLAB wrapper" FORCE )
267+ set (RUST_WRAPPER OFF CACHE BOOL "Disable MoorDyn Rust wrapper" FORCE )
268+ set (BUILD_TESTING_SAVED ${BUILD_TESTING} )
269+ set (BUILD_TESTING OFF )
270+ add_subdirectory (extern/MoorDyn )
271+ set (BUILD_TESTING ${BUILD_TESTING_SAVED} )
272+ # MoorDyn is a shared library (DLL) -- its internal Eigen usage must not
273+ # leak into HydroChrono's include paths (HydroChrono uses Chrono's Eigen).
274+ set_target_properties (moordyn PROPERTIES
275+ INTERFACE_INCLUDE_DIRECTORIES ""
276+ )
277+ message (STATUS "MoorDyn mooring coupling: ENABLED" )
278+ message (STATUS "----\n " )
279+ endif ()
243280
244281# ===============================================================================
245282# ----- Create HydroChrono configuration header ---------------------------------
@@ -261,6 +298,12 @@ else()
261298 set (HC_HAS_VSG "#undef HYDROCHRONO_HAVE_VSG" )
262299endif ()
263300
301+ if (HYDROCHRONO_ENABLE_MOORDYN)
302+ set (HC_HAS_MOORDYN "#define HYDROCHRONO_HAVE_MOORDYN" )
303+ else ()
304+ set (HC_HAS_MOORDYN "#undef HYDROCHRONO_HAVE_MOORDYN" )
305+ endif ()
306+
264307# For BUILD tree
265308set (HC_DATA_DIR "#define HC_DATA_DIR \" ${HC_BUILD_DATA} \" " )
266309configure_file (${CMAKE_CURRENT_SOURCE_DIR} /cmake/config.h.in
@@ -317,13 +360,41 @@ set(HC_SOURCES
317360 src/hydro/logging/logging.cpp
318361)
319362
363+ # MoorDyn mooring sources (conditionally compiled).
364+ # The wrapper is built as a separate OBJECT library so that MoorDyn's
365+ # bundled Eigen headers stay isolated and don't conflict with the
366+ # system/Chrono Eigen used by HydroChrono.
367+ if (HYDROCHRONO_ENABLE_MOORDYN)
368+ add_library (moordyn_bridge OBJECT
369+ src/hydro/mooring/moordyn_wrapper.cpp
370+ )
371+ target_include_directories (moordyn_bridge PRIVATE
372+ "${CMAKE_CURRENT_SOURCE_DIR} /extern/MoorDyn/source"
373+ "${CMAKE_CURRENT_SOURCE_DIR} "
374+ "${CMAKE_CURRENT_SOURCE_DIR} /include"
375+ )
376+ target_link_libraries (moordyn_bridge PRIVATE moordyn )
377+ target_compile_features (moordyn_bridge PUBLIC cxx_std_17 )
378+ # Pick up HydroChrono's public headers (system_state.h, hydro_types.h)
379+ target_include_directories (moordyn_bridge PUBLIC
380+ "$<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /include >"
381+ )
382+ # Chrono headers needed for Eigen (used by hydro_types.h)
383+ target_link_libraries (moordyn_bridge PUBLIC Chrono::Chrono_core )
384+
385+ list (APPEND HC_SOURCES
386+ src/hydro/force_components/mooring_component.cpp
387+ )
388+ endif ()
389+
320390set (HC_HEADERS
321391 ${PROJECT_BINARY_DIR} /hydroc/config.h
322392 ${PROJECT_BINARY_DIR} /hydroc/version.h
323393 include/hydroc/hydro_system.h
324394 include/hydroc/helper.h
325395 include/hydroc/logging.h
326396 include/hydroc/config/hydro_config.h
397+ include/hydroc/config/moordyn_config.h
327398 include/hydroc/core/force_component.h
328399 include/hydroc/core/hydro_forces.h
329400 include/hydroc/core/hydro_types.h
@@ -361,19 +432,23 @@ if(TARGET hdf5::hdf5-static)
361432 target_link_libraries (HydroChrono PUBLIC hdf5::hdf5_cpp-static )
362433 target_link_libraries (HydroChrono PUBLIC hdf5::hdf5_hl-static )
363434 target_link_libraries (HydroChrono PUBLIC hdf5::hdf5_hl_cpp-static )
364- target_link_libraries (HydroChrono PUBLIC hdf5::hdf5_tools-static )
435+ if (TARGET hdf5::hdf5_tools-static)
436+ target_link_libraries (HydroChrono PUBLIC hdf5::hdf5_tools-static )
437+ endif ()
365438elseif (TARGET hdf5::hdf5-shared)
366439 message (STATUS "Linking shared libraries hdf5::hdf5-shared" )
367440 target_link_libraries (HydroChrono PUBLIC hdf5::hdf5-shared )
368441 target_link_libraries (HydroChrono PUBLIC hdf5::hdf5_cpp-shared )
369442 target_link_libraries (HydroChrono PUBLIC hdf5::hdf5_hl-shared )
370443 target_link_libraries (HydroChrono PUBLIC hdf5::hdf5_hl_cpp-shared )
371- target_link_libraries (HydroChrono PUBLIC hdf5::hdf5_tools-shared )
372444 list (APPEND HDF5_TARGETS hdf5::hdf5-shared)
373445 list (APPEND HDF5_TARGETS hdf5::hdf5_cpp-shared)
374446 list (APPEND HDF5_TARGETS hdf5::hdf5_hl-shared)
375447 list (APPEND HDF5_TARGETS hdf5::hdf5_hl_cpp-shared)
376- list (APPEND HDF5_TARGETS hdf5::hdf5_tools-shared)
448+ if (TARGET hdf5::hdf5_tools-shared)
449+ target_link_libraries (HydroChrono PUBLIC hdf5::hdf5_tools-shared )
450+ list (APPEND HDF5_TARGETS hdf5::hdf5_tools-shared)
451+ endif ()
377452elseif (TARGET HDF5::HDF5)
378453 message (STATUS "Linking HDF5::HDF5" )
379454 target_link_libraries (HydroChrono PUBLIC HDF5::HDF5 )
@@ -391,6 +466,15 @@ target_include_directories(HydroChrono
391466 ${CMAKE_CURRENT_SOURCE_DIR} /include
392467)
393468
469+ # Add MoorDyn (optional mooring coupling)
470+ if (HYDROCHRONO_ENABLE_MOORDYN AND TARGET moordyn)
471+ # Link moordyn import lib for DLL binding; moordyn_bridge provides
472+ # the compiled wrapper objects with MoorDyn headers isolated from HC.
473+ target_link_libraries (HydroChrono PRIVATE $<TARGET_LINKER_FILE :moordyn >)
474+ target_sources (HydroChrono PRIVATE $<TARGET_OBJECTS :moordyn_bridge >)
475+ target_compile_definitions (HydroChrono PUBLIC HYDROCHRONO_HAVE_MOORDYN )
476+ endif ()
477+
394478# Library-specific compile definitions
395479target_compile_definitions (HydroChrono
396480 PUBLIC
@@ -515,6 +599,12 @@ function(configure_test_environment)
515599 list (APPEND DLL_DIRS ${VSG_DLL_DIR} )
516600 endif ()
517601
602+ # MoorDyn DLL path
603+ if (HYDROCHRONO_ENABLE_MOORDYN AND TARGET moordyn)
604+ list (APPEND DLL_DIRS "$<TARGET_FILE_DIR :moordyn >" )
605+ message (STATUS " MoorDyn DLL directory: (via target)" )
606+ endif ()
607+
518608 set (TEST_ENVIRONMENT "PATH=${DLL_DIRS} ;$ENV{PATH} " PARENT_SCOPE )
519609endfunction ()
520610
@@ -715,6 +805,21 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
715805 endforeach ()
716806 endif ()
717807
808+ # MoorDyn DLL
809+ if (HYDROCHRONO_ENABLE_MOORDYN AND TARGET moordyn)
810+ install (TARGETS moordyn
811+ CONFIGURATIONS Release
812+ RUNTIME DESTINATION bin COMPONENT runtime )
813+ message (STATUS " MoorDyn DLL (via target)" )
814+ endif ()
815+
816+ endif ()
817+
818+ # MoorDyn license bundling
819+ if (HYDROCHRONO_ENABLE_MOORDYN)
820+ install (FILES "${CMAKE_SOURCE_DIR} /extern/MoorDyn/LICENSE.txt"
821+ RENAME MoorDyn_LICENSE.txt
822+ DESTINATION licenses COMPONENT runtime )
718823endif ()
719824
720825# Public, user-facing regression test suite only
@@ -750,6 +855,13 @@ if(MSVC AND OpenMP_CXX_FOUND)
750855 endif ()
751856endif ()
752857include (InstallRequiredSystemLibraries )
858+
859+ # Third-party license notices
860+ if (EXISTS "${CMAKE_SOURCE_DIR} /THIRD_PARTY_NOTICES.txt" )
861+ install (FILES "${CMAKE_SOURCE_DIR} /THIRD_PARTY_NOTICES.txt"
862+ DESTINATION . COMPONENT runtime )
863+ endif ()
864+
753865set (CPACK_GENERATOR "ZIP" )
754866set (CPACK_PACKAGE_NAME "HydroChrono" )
755867set (CPACK_COMPONENTS_ALL runtime python-tests dev-demos)
0 commit comments