Skip to content

Commit 9ff180f

Browse files
committed
Fix configuration of test environment on Windows (DLL paths)
1 parent 210cb90 commit 9ff180f

1 file changed

Lines changed: 62 additions & 38 deletions

File tree

CMakeLists.txt

Lines changed: 62 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -317,42 +317,6 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in
317317
list(APPEND HC_INCLUDES_BUILD ${PROJECT_SOURCE_DIR}/include)
318318
list(APPEND HC_INCLUDES_BUILD ${PROJECT_BINARY_DIR})
319319

320-
# Helper function to configure test environment (Windows DLL paths, etc.)
321-
function(configure_test_environment)
322-
# Set up DLL search paths for Windows testing
323-
set(CHRONO_DLL_DIR "${Chrono_DIR}/../bin/Release")
324-
325-
# Always include our build output bin directories for all common configs
326-
set(HC_BIN_DIRS "${CMAKE_BINARY_DIR}/bin/Release;${CMAKE_BINARY_DIR}/bin/RelWithDebInfo;${CMAKE_BINARY_DIR}/bin/MinSizeRel;${CMAKE_BINARY_DIR}/bin/Debug")
327-
328-
# Include HDF5 bin if available to stabilize test runtime on clean systems
329-
set(HDF5_DLL_DIR "")
330-
if(DEFINED HDF5_ROOT AND EXISTS "${HDF5_ROOT}/bin")
331-
set(HDF5_DLL_DIR "${HDF5_ROOT}/bin")
332-
endif()
333-
334-
# Derive Irrlicht DLL dir from Irrlicht_ROOT provided by user config
335-
set(IRRLICHT_DLL_DIR "")
336-
if(DEFINED Irrlicht_ROOT AND EXISTS "${Irrlicht_ROOT}/bin/Win64-VisualStudio")
337-
set(IRRLICHT_DLL_DIR "${Irrlicht_ROOT}/bin/Win64-VisualStudio")
338-
elseif(DEFINED Irrlicht_ROOT AND EXISTS "${Irrlicht_ROOT}/bin")
339-
set(IRRLICHT_DLL_DIR "${Irrlicht_ROOT}/bin")
340-
endif()
341-
if(IRRLICHT_DLL_DIR)
342-
if(HDF5_DLL_DIR)
343-
set(TEST_ENVIRONMENT "PATH=${HC_BIN_DIRS};${CHRONO_DLL_DIR};${IRRLICHT_DLL_DIR};${HDF5_DLL_DIR};$ENV{PATH}" PARENT_SCOPE)
344-
else()
345-
set(TEST_ENVIRONMENT "PATH=${HC_BIN_DIRS};${CHRONO_DLL_DIR};${IRRLICHT_DLL_DIR};$ENV{PATH}" PARENT_SCOPE)
346-
endif()
347-
else()
348-
if(HDF5_DLL_DIR)
349-
set(TEST_ENVIRONMENT "PATH=${HC_BIN_DIRS};${CHRONO_DLL_DIR};${HDF5_DLL_DIR};$ENV{PATH}" PARENT_SCOPE)
350-
else()
351-
set(TEST_ENVIRONMENT "PATH=${HC_BIN_DIRS};${CHRONO_DLL_DIR};$ENV{PATH}" PARENT_SCOPE)
352-
endif()
353-
endif()
354-
endfunction()
355-
356320
# -- Main HydroChrono Library --
357321
set(HC_SOURCES
358322
src/h5fileinfo.cpp
@@ -395,7 +359,7 @@ target_link_libraries(HydroChrono PUBLIC Chrono::Chrono_core)
395359
# Add OpenMP
396360
target_link_libraries(HydroChrono PUBLIC OpenMP::OpenMP_CXX)
397361

398-
# Add HDF5 (assume first latest HDF5 version 1.14.6)
362+
# Add HDF5 (assume first latest HDF5 version 1.14.6 and prefer static library)
399363
if(TARGET hdf5-static)
400364
message(STATUS "Linking static libraries hdf5-static")
401365
target_link_libraries(HydroChrono PUBLIC hdf5-static)
@@ -477,6 +441,64 @@ target_link_libraries(HydroChronoGUI
477441
# ------- Auxiliary Targets (app, tests, demos) ---------------------------------
478442
# ===============================================================================
479443

444+
# Helper function to configure test environment (Windows DLL paths, etc.)
445+
function(configure_test_environment)
446+
message(STATUS "Configure test environment")
447+
448+
# HydroChrono DLL paths
449+
set(HC_DLL_DIRS "${CMAKE_BINARY_DIR}/bin/Release;${CMAKE_BINARY_DIR}/bin/RelWithDebInfo;${CMAKE_BINARY_DIR}/bin/MinSizeRel;${CMAKE_BINARY_DIR}/bin/Debug")
450+
message(STATUS " HydroChrono DLL directories: ${HC_DLL_DIRS}")
451+
list(APPEND DLL_DIRS ${HC_DLL_DIRS})
452+
453+
# Chrono DLL paths
454+
get_target_property(CHRONO_CORE_REL_DLL Chrono::Chrono_core IMPORTED_LOCATION_RELEASE)
455+
if(CHRONO_CORE_REL_DLL)
456+
get_filename_component(dir ${CHRONO_CORE_REL_DLL} DIRECTORY)
457+
message(STATUS " Chrono release DLL directory: ${dir}")
458+
list(APPEND DLL_DIRS ${dir})
459+
endif()
460+
get_target_property(CHRONO_CORE_DBG_DLL Chrono::Chrono_core IMPORTED_LOCATION_DEBUG)
461+
if(CHRONO_CORE_DBG_DLL)
462+
get_filename_component(dir ${CHRONO_CORE_DBG_DLL} DIRECTORY)
463+
message(STATUS " Chrono debug DLL directory: ${dir}")
464+
list(APPEND DLL_DIRS ${dir})
465+
endif()
466+
467+
# HDF5 DLL path
468+
if(TARGET hdf5-static)
469+
message(STATUS " No HDF5 DLL (hdf5-static)")
470+
elseif(TARGET hdf5-shared)
471+
get_target_property(dll hdf5-shared IMPORTED_LOCATION_RELEASE)
472+
get_filename_component(dir ${dll} DIRECTORY)
473+
message(STATUS " HDF5 DLL directory (hdf5-shared): ${dir}")
474+
list(APPEND DLL_DIRS ${dir})
475+
elseif(TARGET HDF5::HDF5)
476+
get_target_property(dll HDF5::HFDF5 IMPORTED_LOCATION_RELEASE)
477+
get_filename_component(dir ${dll} DIRECTORY)
478+
message(STATUS " HDF5 DLL directory (HDF5::HDF5): ${dir}")
479+
list(APPEND DLL_DIRS ${dir})
480+
elseif(DEFINED HDF5_ROOT AND EXISTS "${HDF5_ROOT}/bin")
481+
message(STATUS " HDF5 DLL directory (HDF5_ROOT): ${HDF5_ROOT}/bin")
482+
list(APPEND DLL_DIRS ${HDF5_ROOT}/bin)
483+
else()
484+
message(STATUS " Cannot infer HDF5 DLL directory")
485+
endif()
486+
487+
# Irrlicht DLL path
488+
if(HYDROCHRONO_ENABLE_IRRLICHT)
489+
message(STATUS " Irrlicht DLL directory: ${Irrlicht_DLL_DIR}")
490+
list(APPEND DLL_DIRS ${Irrlicht_DLL_DIR})
491+
endif()
492+
493+
# VSG DLL path
494+
if(HYDROCHRONO_ENABLE_VSG)
495+
message(STATUS " VSG DLL directory: ${VSG_DLL_DIR}")
496+
list(APPEND DLL_DIRS ${VSG_DLL_DIR})
497+
endif()
498+
499+
set(TEST_ENVIRONMENT "PATH=${DLL_DIRS};$ENV{PATH}" PARENT_SCOPE)
500+
endfunction()
501+
480502
# YAML-driven CLI app
481503
if(HYDROCHRONO_ENABLE_YAML_RUNNER)
482504
add_subdirectory(app)
@@ -502,7 +524,9 @@ if(HYDROCHRONO_ENABLE_TESTS)
502524
enable_testing()
503525

504526
# Configure test environment with DLL paths
505-
configure_test_environment()
527+
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
528+
configure_test_environment()
529+
endif()
506530

507531
add_subdirectory(tests/regression)
508532
endif()

0 commit comments

Comments
 (0)