FindZLIB: Add option to prefer static libraries
On Windows i am facing the annoying issue that FindZLIB always prefers the shared version over the static version of the library. Building and installing zlib with its CMake file installs both versions which is not bad, but i like to control which version is used. Other find modules offer variables to either enable usage of static versions (e.g. OpenSSL) or change the preference of static versions (e.g. wxWidgets, although the variable name implies enabling).
Looking at the find module the solution seems to be quite simple:
set(ZLIB_NAMES z zlib zdll zlib1 zlibstatic)
set(ZLIB_NAMES_DEBUG zd zlibd zdlld zlibd1 zlib1d zlibstaticd)
Add zlibstatic
add front to prefer the static version or keep it at end to prefer the dynamic version? Granted i am not that familiar with different zlib library names and might miss something.
The only related issue i found is #18029 (closed) which should be kind of fixed now because the static library is already found. To not change current behavior i would add a variable ZLIB_PREFER_STATIC_LIBS
that defaults to off.