When building shared libraries for ITK and using system hdf5, static hdf5 libraries are selected under Windows.
You will see that BUILD_SHARED_LIBS is forced to OFF in ITKSetStandardCompilerFlags on Windows. Then, in Modules/ThirdParty/HDF5/itk-module-init.cmake and Modules/ThirdParty/HDF5/CMakeLists.txt:29, the wrong libraries are searched and selected.
Selection of the HDF5 shared libraries when BUILD_SHARED_LIBS=ON.
Selection of the HDF static libraries.
100%
ITK version 5.0.1
Windows 10 64 bits
Visual Studio 2019
CMake 3.15
I attached a possible patch here (note that other third parties could suffer the same problem).
diff --git a/Modules/ThirdParty/HDF5/CMakeLists.txt b/Modules/ThirdParty/HDF5/CMakeLists.txt
index a700ecdfbf..e9f5a2f6bb 100644
--- a/Modules/ThirdParty/HDF5/CMakeLists.txt
+++ b/Modules/ThirdParty/HDF5/CMakeLists.txt
@@ -1,6 +1,8 @@
project(ITKHDF5)
set(ITKHDF5_THIRD_PARTY 1)
+set(BUILD_SHARED_LIBS ${ITK_BUILD_SHARED_LIBS})
+
if (BUILD_SHARED_LIBS)
add_definitions(-DH5_BUILT_AS_DYNAMIC_LIB=1)
endif()
Do you want to turn this into a PR, or do you want me to do it?
Contribution instructions are here.
OK! I'll do it! Do you want me to check if the same issue lies for other third parties as well?
It would be great if you did that too!