microsoft / vcpkg

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

Using VCPKG_OVERRIDE_FIND_PACKAGE_NAME results in calls to unknown command `_find_package` #25649

Open tusharb86 opened 2 years ago

tusharb86 commented 2 years ago

Describe the bug I am using 'VCPKG_OVERRIDE_FIND_PACKAGE_NAME to override the name of find_package to effectively change it to find_vcpkg_package for use in our project. In doing so, I have found that the scripts in vcpkg have made an assumption that find_package has been overloaded and that _find_package is to be called. (See lines 792, 796, 798, etc. in vcpkg.cmake, for example). Unfortunately, this leads to errors like this:

error: XPlat:WinX64: CMake Error at G:/sb-cache/8d9ddd9c2d/installed/x64-windows/share/zlib/vcpkg-cmake-wrapper.cmake:12 (_find_package):
  Message
    Unknown CMake command "_find_package".
  Call Stack (most recent call first):
    G:/sb-cache/8d9ddd9c2d/scripts/buildsystems/vcpkg.cmake:749 (include)
    G:/hup1/Build/Debug/Install/Externals-WinX64/cmake/Externals-WinX64Config.cmake:110 (find_vcpkg_package)
    CMakeLists.txt:8 (find_package)

In this specific case, the issue is in the vcpkg-cmake-wrapper.cmake script where it is assuming that _find_package exists.

Environment

To Reproduce Set VCPKG_OVERRIDE_FIND_PACKAGE_NAME as you normally would on the command line for CMake to something like find_vcpkg_package. Somewhere in your project, add a call to find_vcpkg_package for any library of your choosing.

Expected behavior I would expect that VCPKG_OVERRIDE_FIND_PACKAGE_NAME is honored everywhere. If it is defined, then find_package must be called. If it is NOT defined, then _find_package can be called.

Neumann-A commented 2 years ago

VCPKG_OVERRIDE_FIND_PACKAGE_NAME is broken. Don't use it. Without cmake_language(CALL) the correct behavior was never implementable.

Neumann-A commented 2 years ago

If you have problems with find_package being overriden by you somehow. Look at #23195

tusharb86 commented 2 years ago

Thanks for the details @Neumann-A! It would be great to get that PR through. The workaround I used in my case was to add the following macro:

    macro(_find_package)
        find_package(${ARGV})
    endmacro()

This allows VCPKG_OVERRIDE_FIND_PACKAGE_NAME to work.

github-actions[bot] commented 10 months ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 180 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

Neumann-A commented 10 months ago

still relevant

ArslanIbragimov commented 10 months ago

relevant

github-actions[bot] commented 4 months ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 180 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

Cheney-W commented 4 months ago

still relevant