Closed stkw0 closed 4 months ago
Thanks for opening this, good catch
I think the original reason for adding the find_dependency was for package manger stuff. I will figure out how best to deal with this tomorrow.
I see. In my use case I created a cpptrace pacakge for Gentoo (that's why I turned on the settings to use system libraries) and then when using the installed package it failed bcause of that.
Oh awesome thanks so much for doing that! I have been looking at a similar issue today with the find_dependency(ZLIB) not working for someone else and I think I now better understand what’s going on with that issue and this one.
On your gentoo setup, is zstd installed but not zstd-dev (or similar) which would have the config files for the library or Findzstd.cmake?
I don't know the exact reason, but the zstd package only installs /usr/lib64/pkgconfig/libzstd.pc. It's libdwarf package the one which installs Findzstd.cmake (at /usr/lib64/cmake/libdwarf/Findzstd.cmake). I believe that cpptrace links against libdwarf and libdwarf links against zstd, so everything works fine. But when cpptrace tries to link explicetely with zstd it fails, as it can not find Findzstd.cmake (because it's installed in libdwarf path). Luckily, cpptrace doesn't actually needs to link against zstd, so when removing that part everything works fine.
Studying git blames a bit and playing around with removing the find_dependency(zstd)
line I realized the reason it was needed is libdwarf's Findzstd.cmake script doesn't define zstd::libzstd_static / zstd::libzstd_shared targets. I think I've settled on a reasonable solution which is to provide a Findzstd.cmake script as part of cpptrace's installation and resolve the dependency that way. (reasonable in that I actually understand what's going on :P)
Please let me know if the setup in https://github.com/jeremy-rifkin/cpptrace/pull/115 works for your use case! I'll look to do a patch release soon.
Yep. Applying the patch seems to fix the issue. Given that cpptrace depends in libdwarf and this was a workaround for a libdwarf issue, I think it can make sense to submit your Findzstd.cmake to libdwarf?
Awesome thanks for confirming! I agree it would be good to apply upstream too.
On your gentoo setup, is zstd installed but not zstd-dev (or similar) which would have the config files for the library or Findzstd.cmake?
https://bugs.gentoo.org/872254
TL;DR: It depends on whether you build upstream zstd with CMake or not :(
I compiled cpptrace with -DCPPTRACE_USE_EXTERNAL_LIBDWARF=On as I want to use the system libraries for zstd and libdwarf. cpptrace compiles and installs correctly.
Then, on my main project I added
find_package(cpptrace REQUIRED)
to the CMakeLists.txt file. When I try to configure it the next error is shown:If I remove the two find_dependency lines from cmake/in/cpptrace-config-cmake.in my project compiles, links and runs correctly. I think that probably the
if(@CPPTRACE_GET_SYMBOLS_WITH_LIBDWARF@)
should be changed so it also checks for CPPTRACE_USE_EXTERNAL_LIBDWARF in such a way that if it's enabled it should not try to find those dependencies as they are already linked to cpptrace.