Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vcpkg install: Usage hint for CMake find_package, incomplete support for possible paths #10881

Closed
Farwaykorse opened this issue Apr 17, 2020 · 7 comments
Assignees
Labels
category:port-bug The issue is with a library, which is something the port should already support

Comments

@Farwaykorse
Copy link
Contributor

Describe the bug
Vcpkg does not provide the right usage hint for <pkg_name>Config.cmake files installed into a path ending in cmake.
E.g. /share/Microsoft.GSL/cmake/Microsoft.GSLConfig.cmake, used in Microsoft/GSL/CMakeLists.txt.

Without the work-around added in the portfile for #10831 vcpkg install ms-gsl returns the following usage hint:

The package ms-gsl:x86-windows provides CMake targets:

    find_package(cmake CONFIG REQUIRED)
    target_link_libraries(main PRIVATE Microsoft.GSL::GSL)

Note the cmake in find_package, this should be Microsoft.GSL.

The current implementation shows a package name taken from the wrong folder.

Proposed solution
An update of the algorithm used to determine the package name.
There might be more valid paths that are not matched. (See the table below.)

Describe alternatives you've considered
Fixes, such as added to #10831, moving the files to a recognised path, are easy to forget and hard to maintain.
And they should not be necessary for projects using a valid path.

Additional context

The tables below show the directories searched. Each entry is meant for installation trees following Windows (W), UNIX (U), or Apple (A) conventions:

<prefix>/                                                       (W)
<prefix>/(cmake|CMake)/                                         (W)
<prefix>/<name>*/                                               (W)
<prefix>/<name>*/(cmake|CMake)/                                 (W)
<prefix>/(lib/<arch>|lib*|share)/cmake/<name>*/                 (U)
<prefix>/(lib/<arch>|lib*|share)/<name>*/                       (U)
<prefix>/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/         (U)
<prefix>/<name>*/(lib/<arch>|lib*|share)/cmake/<name>*/         (W/U)
<prefix>/<name>*/(lib/<arch>|lib*|share)/<name>*/               (W/U)
<prefix>/<name>*/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/ (W/U)

Source: CMake documentation - find_package Search Procedure


@Neumann-A
Copy link
Contributor

returns the following usage hint:

probably a bug in the usage printing which does not correctly search for a *Config.cmake and takes every allowed path into account. It is probably better to derive the find_package name from the config name instead of the path

@LilyWangL LilyWangL self-assigned this Apr 20, 2020
@LilyWangL LilyWangL added the category:vcpkg-feature The issue is a new capability of the tool that doesn’t already exist and we haven’t committed label Apr 29, 2020
@LilyWangL LilyWangL assigned strega-nil and unassigned LilyWangL Apr 29, 2020
@JackBoosY JackBoosY added category:vcpkg-bug The issue is with the vcpkg system (including helper scripts in `scripts/cmake/`) and removed category:vcpkg-feature The issue is a new capability of the tool that doesn’t already exist and we haven’t committed labels Jul 30, 2020
@JackBoosY
Copy link
Contributor

should be a vcpkg bug.

@roddypratt
Copy link

Seeing this with the mdns library too.

[cmake] mdns provides CMake targets:
[cmake] 
[cmake]     # this is heuristically generated, and may not be correct
[cmake]     find_package(cmake CONFIG REQUIRED)
[cmake]     target_link_libraries(main PRIVATE mdns::mdns)

@strega-nil strega-nil removed their assignment Nov 22, 2022
@dg0yt
Copy link
Contributor

dg0yt commented Nov 23, 2022

This belongs to the #20190 gallery...

@JackBoosY
Copy link
Contributor

cc @Cheney-W

@Cheney-W Cheney-W self-assigned this Nov 28, 2022
@dg0yt
Copy link
Contributor

dg0yt commented Jan 10, 2023

With microsoft/vcpkg-tool#849, vcpkg-tool will print usage heuristics only for config located directly in share/<Pkg>. For mdns, the output changes to header-only.

-mdns provides CMake targets:
-
-    # this is heuristically generated, and may not be correct
-    find_package(cmake CONFIG REQUIRED)
-    target_link_libraries(main PRIVATE mdns::mdns)
+mdns is header-only and can be used from CMake via:
+
+    find_path(MDNS_INCLUDE_DIRS "mdns.h")
+    target_include_directories(main PRIVATE ${MDNS_INCLUDE_DIRS})

This is not plainly wrong as with the current tool, but still not what is desired.
However, instead of considering alternative location in the usage heuristics, I would rather suggest to add a check which suggests to call vcpkg_cmake_config_fixup. At least for libraries, this is needed anyways, no matter where the location is stored.

@JonLiu1993 JonLiu1993 added category:port-bug The issue is with a library, which is something the port should already support and removed category:vcpkg-bug The issue is with the vcpkg system (including helper scripts in `scripts/cmake/`) labels Dec 5, 2024
@JonLiu1993
Copy link
Member

Duplicate of #20190

@JonLiu1993 JonLiu1993 marked this as a duplicate of #20190 Dec 5, 2024
@JonLiu1993 JonLiu1993 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:port-bug The issue is with a library, which is something the port should already support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants