microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
23.27k stars 6.42k forks source link

flecs needs an explicit usage file #31488

Closed dg0yt closed 1 year ago

dg0yt commented 1 year ago

Suggesting target_link_libraries(main PRIVATE flecs::flecs flecs::flecs_static) only works in vcpkg. Outside vcpkg either one target will be missing, or the user will link two libs providing the same symbols but with different linkage.

What needs to be done? Add a usage file which can work without the wrapper, i.e. using

    target_link_libraries(main PRIVATE $<IF:$<TARGET_EXISTS:flecs::flecs>,flecs::flecs,flecs::flecs_static>)

Originally posted by @dg0yt in https://github.com/microsoft/vcpkg/issues/31432#issuecomment-1547627257

myd7349 commented 1 year ago

This issue is not unique to flecs.

There are many C++ libraries, such as zeromq and xeus, that have CMake support for building both dynamic and static libraries at the same time. In such cases, the library maintainers differentiate between the targets for dynamic and static libraries (usually including "static" in the target name for the static library).

Based on my vague recollection, in the past few years, when encountering such libraries, vcpkg recommended adding a vcpkg-cmake-wrapper.cmake to link the static target and dynamic target together.

I remember that this approach was mentioned either in the vcpkg documentation or in responses from core members of the vcpkg team in related issues. However, I am currently unable to locate the exact source.

OK. I think I find it.

https://github.com/microsoft/vcpkg/issues/6045#issuecomment-482387298

If I have misunderstood, please correct me.

dg0yt commented 1 year ago

@myd7349 This issue is about a particular bad output from vcpkg tool's usage heuristics which can be fixed by a usage file. My post ist clear about it.

(Wrapper are only loosely related to the issue. I wouldn't add one for this port. But I didn't ask to remove it, and I protested against breaking users by removing it.)