Skip to content

FindZLIB: Fail if components are requested as it does not provide any

koostosh requested to merge koostosh/cmake:zlibnocomponents into master

Calling find_package(ZLIB COMPONENTS ...) should always fail as there are no components defined for it. It is a single library.

Most probably fixes #18872 (closed) . HDF5 tries to find_package(ZLIB COMPONENTS shared) which so far ignored any component specification and behaved just like find_package(ZLIB). Then HDF5, basing on the fact that ZLIB_FOUND is set, tries to link with element pointed by variable ZLIB_SHARED_LIBRARY which is not set in any way by find. After this fix this first call will fail (ZLIB_FOUND will not be set), and HDF5 fallbacks to find_package(ZLIB) which succeeds.

I decided to fix this problem on cmake module side, not in hdf as this will prevent similar misuses from other projects and in future.

As intended find_package(ZLIB COMPONENTS ... REQUIRED) will result in error; find_package(ZLIB COMPONENTS ... QUIET) will fail quietly; and find_package(ZLIB COMPONENTS ...) will fail and produce a warning that there is no way for this call to succeed.

Fixes: #18872 (closed)
Topic-rename: FindZLIB-no-components

Edited by Brad King

Merge request reports