Skip to content

[vcpkg-tool][world rebuild] Instrument vcpkg.cmake to check for optional dependencies#27606

Closed
Thomas1664 wants to merge 5 commits intomicrosoft:masterfrom
Thomas1664:no-optional-deps
Closed

[vcpkg-tool][world rebuild] Instrument vcpkg.cmake to check for optional dependencies#27606
Thomas1664 wants to merge 5 commits intomicrosoft:masterfrom
Thomas1664:no-optional-deps

Conversation

@Thomas1664
Copy link
Contributor

Describe the pull request

See the tagged issue for more information.

This PR adds a check to the vcpkg override of find_package to detect if it is called without REQUIRED and not explicitly handled using CMAKE_DISABLE_FIND_PACKAGE_ or CMAKE_REQUIRE_FIND_PACKAGE_.
It needs a PR on the tool as well.

@Thomas1664 Thomas1664 changed the title [vcpkg-tool] Instrument vcpkg.cmake to check for optional dependencies [vcpkg-tool][world rebuild] Instrument vcpkg.cmake to check for optional dependencies Nov 2, 2022
@dg0yt
Copy link
Contributor

dg0yt commented Nov 2, 2022

Did you test this locally, with non-trivial ports/projects? I think this is too simple with regard to recursive find_package/find_dependency calls. In particular the latter must never use REQUIRED but has to check <Pkg>_FOUND.

@Thomas1664
Copy link
Contributor Author

Thomas1664 commented Nov 2, 2022

Did you test this locally, with non-trivial ports/projects? I think this is too simple with regard to recursive find_package/find_dependency calls. In particular the latter must never use REQUIRED but has to check <Pkg>_FOUND.

With the limited resources of a Codespace I tested ports like sdl2 or OSG successfully. Can you recommend some ports that fit in 20 GB of storage and build in a reasonable amount of time?

@Neumann-A
Copy link
Contributor

qtbase. Probably already breaks with minimal features....
But from experience I can tell you that this is a waste of time. I tried to force CMAKE_REQUIRE_FIND_PACKAGE_ in the qt ports but qt seems to call find_package first with the CONFIG keyword and after that without that which is perfectly fine for CMake, e.g.

find_package(package CONFIG)
find_package(package REQUIRED)

and you cannot deal with that correctly. The same goes for COMPONENTS and OPTIONAL_COMPONENTS

@LilyWangLL LilyWangLL 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 Nov 2, 2022
@LilyWangLL LilyWangLL requested a review from BillyONeal November 2, 2022 09:03
@Thomas1664
Copy link
Contributor Author

qtbase. Probably already breaks with minimal features.... But from experience I can tell you that this is a waste of time. I tried to force CMAKE_REQUIRE_FIND_PACKAGE_ in the qt ports but qt seems to call find_package first with the CONFIG keyword and after that without that which is perfectly fine for CMake, e.g.

find_package(package CONFIG)
find_package(package REQUIRED)

and you cannot deal with that correctly. The same goes for COMPONENTS and OPTIONAL_COMPONENTS

Since find_package is a macro we might be able to record the package name between calls?

Even if some ports break I think the majority of ports is simple enough to work with this. We can set a flag to disable this check for some complex ports like qt.

@Neumann-A
Copy link
Contributor

Since find_package is a macro we might be able to record the package name between calls?

What about recursive and nested find_package calls ?

Even if some ports break I think the majority of ports is simple enough to work with this.

user code also interacts with vcpkg.cmake so it needs to be off by default. Also you could just inject cmake_language(DEFER) and check the property https://cmake.org/cmake/help/latest/prop_gbl/PACKAGES_NOT_FOUND.html

@Thomas1664
Copy link
Contributor Author

Thomas1664 commented Nov 2, 2022

My new approach based on @Neumann-A's suggestions:

Only enable this check if VCPKG_TRACE_FIND_PACKAGE is on.

@Thomas1664
Copy link
Contributor Author

Depends on #27950 and #27982

github-actions[bot]
github-actions bot previously approved these changes Nov 23, 2022
@LilyWangLL LilyWangLL added the depends:different-pr This PR or Issue depends on a PR which has been filed label Feb 7, 2023
@BillyONeal
Copy link
Member

I believe this PR is replaced by #27950 . Thanks for your contribution to vcpkg!

@BillyONeal BillyONeal closed this Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category:vcpkg-feature The issue is a new capability of the tool that doesn’t already exist and we haven’t committed depends:different-pr This PR or Issue depends on a PR which has been filed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[vcpkg-tool] Post build lint: Check for missing optional dependencies

5 participants