Precisely so if my library has dependencies which have been linked like so: target_link_libraries(my_library X11::X11 JPEG::JPEG PNG::PNG CUDA::cublas CUDA::curand MKL::MKL ...)
how do i populate Libs and Cflags in the pkg config file?
As i wrote in my original post i tried using:
which of course makes no sense for pkg config.
So i need a way to resolve all the imported targets, generator expressions etc down to explicit compiler and linker flags
At the end of the day, cmake should know how to do this because it has to generate makefiles build-ninja files etc which must use explicit compiler/linker flags. I just wish there was a way to expose this functionality at configure time.
What if libpng is an optional dependency in my library controlled by a cmake option ? That’s my use case. So you can’t guarantee it’s always a dependency.
Yep it’s pants.
But at least it’s doable.
I’m starting to believe cmake doesn’t solve anything. As in, it doesn’t actually make you productive. But anyway, it’s the best we got unfortunately
To be honest, the amount of time I have to spend writing and debugging cmake it’s barely worth it. New languages put a lot of effort in their build tools to minimise the amounting of time spent writing build code.
I might have a look at Meson this weekend and see how they tackle dependencies and install scripts.
But anyway, thank you for all your help
Peter, did you find a solution, I have exactly the same problem as you - a huge number of dependencies, could be shared, could be static, could be coming from conan, could be coming form the system
I’m experiencing same issue. The generator expressions of all those linked libraries and conditions make it impossible to do that from reading some target property.
Otherwise, I’ll probably have to collect these private libraries into a list variable over the configuration phase. Yes, quite annoying approach and feels like moving few steps back with all these imported and interface targets, but is probably the least error prone.
I’ve also tried parsing the CMakeFiles/<target_name>.dir/link.txt file but it would be a bit difficult to get all libraries based on the various linkers and combinations correctly manually.