libzip
libzip copied to clipboard
Cannot link against static libzip with additional dependencies by default
Describe the Bug
When using find_package to import libzip and linking against a static libzip::zip built against bzip2 and/or liblzma, it cannot be used without first manually importing BZip2::BZip2 or LibLZMA::LibLZMA.
Expected Behavior The libzip::zip target should be able to be linked against without having to do any manual searching for packages on consumer's end. It would be extremely fragile to require that on a case-by-case basis since future versions may have different dependencies.
Observed Behavior The targets that attempt to link against libzip::zip throw errors that the targets BZip2::BZip2 and/or LibLZMA::LibLZMA cannot be found.
To Reproduce
- First staticly build and install libzip with bzip2 or xz support
- Make a blank file called test.c, and make a CMakeLists.txt file in the same directory containing this:
find_package(libzip REQUIRED)
add_executable(test test.c)
target_link_libraries(test libzip::zip)
- Run
cmake .andcmake --build .. Observe warnings and errors.
libzip Version 1.7.3
Operating System This was done with the msys2-provided build of 1.7.3 but should apply universally.
Test Files N/A
Additional context
I asked in #cmake on FreeNode to see if it was a CMake issue or a libzip issue, where it was suggested that you should handle the necessary find_package calls in your exported config (so presumably libzip-config.cmake.in). However, they would consider adding a feature for at least partial detection and export of target dependencies.
Thanks. I agree that this should be fixed. It seems you investigated this already, can you please come up with a patch?
I investigated what went wrong. I can try and investigate a fix, but that was a bit beyond the scope of what I was investigating. I'll look into it tomorrow. Still getting the hang of CMake in this repo?
Yeah, and some of the details of how to do this "right" are fiddly and underdocumented... Thanks!
I looked into this but I wasn't sure how to fix it properly, so I've been doing other things instead in the meantime.
Did you make progress? Or do you have pointers to more details what fixes would be needed?
Unfortunately I got stuck when I realized that the Find*.cmake files that libzip uses internally don't get exported, so I'm not really sure how to fix this properly either. I ended up moving on to other projects in the meantime.