Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Z library detection #2121

Merged
merged 8 commits into from
Nov 4, 2021
Merged

Refactor Z library detection #2121

merged 8 commits into from
Nov 4, 2021

Conversation

gsjaardema
Copy link
Contributor

HDF5 can depend on the Z library (in fact required for netCDF). Moved the detection of whether hdf5 was built with zlib up before any other tests that may require linking of the hdf5 library to determine presence/absence of symbols. These tests require that the link line include "-lz" if the hdf5 library was built with libz support.

This is typically handled somewhat automatically if shared libraries are being used, but in the static library case, the explicit dependency needs to be specified. For internal CMake checks, it uses the CMAKE_REQUIRED_LIBRARIES list to specify the libraries that should be used in a CHECK_C_SOURCE_COMPILE or a CHECK_LIBRARY_EXISTS call. In the current CMakeLists.txt ordering, the zlib detection is done after the CHECK_LIBRARY_EXISTS calls which can cause them to fail and give an incorrect result about whether the function being tested for exists. With the reordering in this PR, I am able to correctly configure netCDF on a CRAY HPC system that uses static libraries by default.

I moved the find_package(threads) out of the HDF5 block since it doesn't seem to be related to HDF5 and nothing is done whether it is found or not... Maybe it can be removed entirely?

HDF5 can depend on the Z library (in fact required for netCDF).  Moved the detection of whether hdf5 was built with zlib up before any other tests that may require linking of the hdf5 library to determine presence/absence of symbols.  These tests require that the link line include "-lz" if the hdf5 library was built with libz support.  

This is typically handled somewhat automatically if shared libraries are being used, but in the static library case, the explicit dependency needs to be specified.  For internal CMake checks, it uses the `CMAKE_REQUIRED_LIBRARIES` list to specify the libraries that should be used in a `CHECK_C_SOURCE_COMPILE` or a `CHECK_LIBRARY_EXISTS` call.   In the current CMakeLists.txt ordering, the zlib detection is done _after_ the `CHECK_LIBRARY_EXISTS` calls which can cause them to fail and give an incorrect result about whether the function being tested for exists.   With the reordering in this PR, I am able to correctly configure netCDF on a CRAY HPC system that uses static libraries by default.
@gsjaardema gsjaardema requested a review from WardF as a code owner October 4, 2021 16:53
Moving the threads find_package affects the windows build.
Not sure where the almost duplicate `find_path` line came from.  Removed it.
There was another almost duplicate `find_path` call in the code that is now removed.  It wasn't a part of this PR, but removing just for completeness
Instead of just specifying "z" as a dependent library, use `find_package`
Remove the double quotes I had used in the find_package...
A previous edit added some extraneous whitespace that should not be there...
@WardF WardF merged commit 26ac2a6 into Unidata:main Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants