Skip to content

Conversation

@ccawley2011
Copy link
Contributor

This matches the behaviour of FindZLIB from standard CMake installations.

@Vollstrecker
Copy link
Contributor

Point 1: Why do you checkif the target exists, if you could check for the option if the target should be created?

Point 2: FindZLIB tries to provide something, but the point in the named targets is to know what you link against. If you you want a static linking, there's a target. Imagine you expect dynamic linking and want to install the dll in your script, but there is none, you would have to add additional checks. Yes, with your changes in the config you mimic the old behaviour, but if someone includes the sources Idmeand them to check if there are changes. Such situations happen with apis all the time, so it's not asked too much to check if all the targets are still correct (and if you link against ZLIB:::ZLIB and don't set any options you'll have no problems in this case), and instead of checking for existing dll's I consider it better to check for the version and just use the right targets in you build instead of hoping to get sommething.

@Mizux
Copy link

Mizux commented Oct 15, 2025

ZLIB_USE_STATIC_LIBS
Added in version 3.24.
Set this variable to ON before calling find_package(ZLIB) to look for static libraries. Default is OFF.

from: https://cmake.org/cmake/help/latest/module/FindZLIB.html

So having ZLIB::ZLIB fallback to zlibstatic when using ExternalProject/FetchContent/add_subdirectory() could be a reasonable behaviour imho...
also if consumer require to know if it is a static or a shared lib (which also can be see as an integration implementation details) you could still use $<STREQUAL:$<TARGET_PROPERTY:ZLIB::ZLIB,TYPE>,SHARED_LIBRARY>...

@Vollstrecker
Copy link
Contributor

So having ZLIB::ZLIB fallback to zlibstatic when using ExternalProject/FetchContent/add_subdirectory() could be a reasonable behaviour imho...

You mean when you
a) use FindZLIB and get no result or
b) when you unconditionally include the lib like you mentioned or
c) when using the new automatism of find_package (didn't test, but from reading it's the same as option a

So in all 3 cases you can set ZLIB_BUILD_SHARED to OFF before doing this and alias this yourself.

also if consumer require to know if it is a static or a shared lib (which also can be see as an integration implementation details) you could still use $<STREQUAL:$<TARGET_PROPERTY:ZLIB::ZLIB,TYPE>,SHARED_LIBRARY>...

Because FindZLIB line 254 sets it to UNKNOWN and you'll never know?

But if you mention genex as an point, what about $&lt;If $&lt;TARGET_EXISTS:ZLIB::ZLIBSTATIC>, ZLIB::ZLIBSTATIC, ZLIB::ZLIB>?

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.

3 participants