[CMAKE] build with HDF5 with external zlib
NetCDF 4.9.3 Windows 7/10/11 Visual studio 2019/2022 CMake-GUI 3.31.4
Building netcdf with HDF5 (with external zlib support) almost work flawlessly. my HDF5 is compiled, by myself, with an external zlib (also compiled by myself)
The netcdf's CMake will generate a h5deflate sub project The link properties of this project correctly mention the path to zlib.lib The include properties of this project do not mention the path to zlib.h, it must be added manually
Thank you; can you provide information about how you compiled external zlib support? I also test on Windows using manually compiled HDF5 with external, manually compiled zlib support, and I haven't encountered the issue you report. We'd also be grateful if you wanted to submit a PR, it sounds like a straightforward fix, if that's easier than helping me duplicate the issue. Thank you!
I am not familiar at all with CMake, I don't think I can submit a PR. ~Would you like me to send you the CMakeCache.txt of my zlib, HDF5, and NetCDF ?~ Here are the CMakeCache.txt of my zlib, HDF5, and NetCDF
CMakeCache-zlib.txt CMakeCache-hdf5.txt CMakeCache-netcdf.txt
Hi, I have the same issue in the same environment, compiling all from sources. I compiled zlib with cmake from command line
:: zlib-1.3.1
set "ZLIB_DIR=%EXTLIB_DIR%\zlib-1.3.1"
7z x zlib-1.3.1.zip
pushd zlib-1.3.1
cmake -B build -DCMAKE_DEBUG_POSTFIX=d -DCMAKE_INSTALL_PREFIX="%ZLIB_DIR%"
cmake --build build --config Debug --target install
cmake --build build --config Release --target install
popd
then hdf5
:: hdf5
set "HDF5_DIR=%EXTLIB_DIR%\hdf5-1.14.6"
untargz hdf5-1.14.6
pushd hdf5-1.14.6
cmake -B build -DCMAKE_DEBUG_POSTFIX=d -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=OFF -DBUILD_TESTING=OFF -DHDF5_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX="%HDF5_DIR%" -DCMAKE_PREFIX_PATH="%ZLIB_DIR%"
cmake --build build --config Debug --target install
cmake --build build --config Release --target install
popd
all is fine then I compile netcdf
:: netcdf4
set "NETCDF_DIR=%EXTLIB_DIR%\netcdf-4.9.3"
untargz netcdf-c-4.9.3
pushd netcdf-c-4.9.3
cmake -B build -DCMAKE_DEBUG_POSTFIX=d -DBUILD_SHARED_LIBS=ON -DNETCDF_ENABLE_TESTS=OFF -DNETCDF_ENABLE_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX="%NETCDF_DIR%" -DCMAKE_PREFIX_PATH="%HDF5_DIR%;%ZLIB_DIR%;%CURL_DIR%"
cmake --build build --config Debug --target install
cmake --build build --config Release --target install
popd
I see compile errors related to unfound curl.h, zlib.h :
netcdf-c-4.9.3\libdispatch\dhttp.c(20,10): error C1083: 'curl/curl.h' : No such file or directory
...
netcdf-c-4.9.3\plugins\H5Zdeflate.c(23,10): error C1083: 'zlib.h' : No such file or directory
@frontfact @chacha21 can you try my workarounds & give feedback there? thanks https://github.com/Unidata/netcdf-c/pull/3132
@jmckenna I just cloned https://github.com/jmckenna/netcdf-c.git and built it with my usual Windows+CMakeGUI+VS2019 target I confirm that once generated, the Visual Studio project does not require any more manual modification to find zlib.h It suggests that your fix is OK.
A remark : it is certainly not related to your commit, but while NetCDF's CMake asks for CURL_LIBRARY_DEBUG and CURL_LIBRARY_RELEASE, it only asks for ZLIB_LIBRARY. I can't explain why it works, because the Debug linking with HDF5 should complain about incompatible zlib.lib, since HDF5's CMake does use ZLIB_LIBRARY_DEBUG and ZLIB_LIBRARY_RELEASE, and NetCDF's CMake also uses HDF5_hdf5[_hl]_LIBRARY_DEBUG and HDF5_hdf5[_hl]_LIBRARY_RELEASE
Also, the last time I built NetCDF, CMake did not require GNU M4, I had to install if for that new build. Was it added recently to NetCDF's CMake ?