microsoft/vcpkg

[SFML] build failure due to vcpkg applied patch

patricia-gallardo opened this issue · 12 comments

Operating system

MacOS and Linux

Compiler

GCC, Clang, AppleClang

Steps to reproduce the behavior

The easiest way is to test the original PR since my current PR is trying to update Catch2 to version 3 
Original PR : https://github.com/mod-cpp/ms-pacman/pull/21/checks

git clone https://github.com/mod-cpp/ms-pacman.git
cd ms-pacman
git checkout update_vcpkg #branch from the PR
cmake --preset linux-gcc -DCMAKE_BUILD_TYPE=Debug # configure WILL FAIL
cmake --preset linux-gcc -DCMAKE_BUILD_TYPE=Debug # configure WILL PASS
cmake --build --preset linux-gcc-build --config Debug # build
ctest --preset linux-gcc-test -C Debug # run tests

Failure logs

Linux

CMake Error at build/linux-clang/vcpkg_installed/x64-linux/share/sfml/SFMLConfig.cmake:144 (message):
  SFML found but some of its dependencies are missing ( OpenGL FreeType)
Call Stack (most recent call first):
  build/linux-clang/_deps/vcpkg-src/scripts/buildsystems/vcpkg.cmake:852 (_find_package)
  lib/CMakeLists.txt:1 (find_package)

CMake Error at build/linux-clang/_deps/vcpkg-src/scripts/buildsystems/vcpkg.cmake:852 (_find_package):
  Found package configuration file:

    /home/patricia-gallardo/Code/ms-pacman/build/linux-clang/vcpkg_installed/x64-linux/share/sfml/SFMLConfig.cmake

  but it set SFML_FOUND to FALSE so package "SFML" is considered to be NOT
  FOUND.
Call Stack (most recent call first):
  lib/CMakeLists.txt:1 (find_package)

MacOS

CMake Error at build/osx/vcpkg_installed/x64-osx/share/sfml/SFMLConfig.cmake:144 (message):
  SFML found but some of its dependencies are missing ( OpenGL FreeType)
Call Stack (most recent call first):
  build/osx/_deps/vcpkg-src/scripts/buildsystems/vcpkg.cmake:852 (_find_package)
  lib/CMakeLists.txt:1 (find_package)


CMake Error at build/osx/_deps/vcpkg-src/scripts/buildsystems/vcpkg.cmake:852 (_find_package):
  Found package configuration file:

    /Users/patricia-gallardo/Code/ms-pacman/build/osx/vcpkg_installed/x64-osx/share/sfml/SFMLConfig.cmake

  but it set SFML_FOUND to FALSE so package "SFML" is considered to be NOT
  FOUND.
Call Stack (most recent call first):
  lib/CMakeLists.txt:1 (find_package)

Additional context

We are trying to update to a new vcpkg version and we're having trouble with SFML, it gives an error but if we run CMake again it's fine.

This patch seems like it might be related:
https://github.com/microsoft/vcpkg/blob/master/ports/sfml/fix-dependencies.patch

According to @cor3ntin's experiments the patch is what is causing the problem. Not applying the patch fixes the issue.

We first saw this back in January when we tried to update vcpkg mod-cpp/ms-pacman#21

At the time we just put it on the backburner and didn't report as we should have.

Now I tried to update again in mod-cpp/ms-pacman#25

And I am "solving" it there by running CMake config twice if the first one fails:

mod-cpp/ms-pacman@84cb7cf

Specifically like this in the GitHub workflow yaml file:

cmake --preset ${{ matrix.configurations.config-preset }} -DCMAKE_BUILD_TYPE=${{ matrix.cmake-build-type }} || cmake --preset ${{ matrix.configurations.config-preset }} -DCMAKE_BUILD_TYPE=${{ matrix.cmake-build-type }}

Typical failing build (new PR 25): https://github.com/mod-cpp/ms-pacman/actions/runs/5255810326
Typical failing build (old PR 21 - easier to repro currently): https://github.com/mod-cpp/ms-pacman/actions/runs/5256326977

Windows builds, everything else fails.

I'm not able to reproduce this problem. Could you please provide a simple reproduction project?

Ok here is what I have so far: https://github.com/patricia-gallardo/vcpkg-repro

The issue seems to be related to the system-utils library.

Repro steps for Ubuntu 22.04 and MacOS are in the README.

dg0yt commented

I see ... the mentioned patch should not only have added find_dependency calls, but also updated the interaction with sfml_bind_dependency which now does a failing find_library.

I’ll take your word for it, I’m a bit out of my CMake depth, I’m afraid 😅

dg0yt commented

Actually the patch does set the right variables part there are some subtle details - which version of CMake do you use?

I haven’t even checked, it fails every time, on all my machines, in the Github actions workflow. I would be surprised if it doesn’t for you.

dg0yt commented

Okay, I can reproduce it.

cmake_minimum_required(VERSION 3.16)
find_package(SFML COMPONENTS window graphics CONFIG REQUIRED) # good
find_package(SFML COMPONENTS window graphics CONFIG REQUIRED) # bad

It happens when the config is included twice. The understanding comes from reading the warnings and perhaps running cmake --trace-expand. Simplified:

# 1st time
share/sfml/SFMLConfigDependencies.cmake(61):  set(OpenGL_LIB OpenGL::GL )
...
# using our non-cache variable and not creating a cache variable
share/sfml/SFMLConfigDependencies.cmake(34):  find_library(OpenGL_LIB NAMES OpenGL;GL PATHS share/sfml/../..;~/Library/Frameworks;/Library/Frameworks;/usr/local;/usr;/sw;/opt/local;/opt/csw;/opt PATH_SUFFIXES lib NO_SYSTEM_ENVIRONMENT_PATH )
# Note: creating an emtpy cache variable!
share/sfml/SFMLConfigDependencies.cmake(36):  mark_as_advanced(OpenGL_LIB )
CMake Warning (dev) at share/sfml/SFMLConfigDependencies.cmake:36 (mark_as_advanced):
  Policy CMP0102 is not set: The variable named "OpenGL_LIB" is not in the
  cache.  This results in an empty cache entry which is no longer created
  when policy CMP0102 is set to NEW.  Run "cmake --help-policy CMP0102" for
  policy details.  Use the cmake_policy command to set the policy and
  suppress this warning.
...
# using our non-cache variable
share/sfml/SFMLConfigDependencies.cmake(37):  if(OpenGL_LIB )
share/sfml/SFMLConfigDependencies.cmake(38):  set_property(TARGET OpenGL APPEND PROPERTY INTERFACE_LINK_LIBRARIES OpenGL::GL )
...
# 2nd time
share/sfml/SFMLConfigDependencies.cmake(61):  set(OpenGL_LIB OpenGL::GL )
...
# using the empty cache variable and removing the non-cache variable
share/sfml/SFMLConfigDependencies.cmake(34):  find_library(OpenGL_LIB NAMES OpenGL;GL PATHS share/sfml/../..;~/Library/Frameworks;/Library/Frameworks;/usr/local;/usr;/sw;/opt/local;/opt/csw;/opt PATH_SUFFIXES lib NO_SYSTEM_ENVIRONMENT_PATH )
CMake Warning (dev) at share/sfml/SFMLConfigDependencies.cmake:34 (find_library):
  Policy CMP0126 is not set: set(CACHE) does not remove a normal variable of
  the same name.  Run "cmake --help-policy CMP0126" for policy details.  Use
  the cmake_policy command to set the policy and suppress this warning.

  For compatibility with older versions of CMake, normal variable
  "OpenGL_LIB" will be removed from the current scope.
...
share/sfml/SFMLConfigDependencies.cmake(36):  mark_as_advanced(OpenGL_LIB )
# now using the cache variable and taking the bad branch
share/sfml/SFMLConfigDependencies.cmake(37):  if(OpenGL_LIB )
share/sfml/SFMLConfigDependencies.cmake(39):  else()
share/sfml/SFMLConfigDependencies.cmake(40):  set(FIND_SFML_DEPENDENCIES_NOTFOUND  OpenGL PARENT_SCOPE )
dg0yt commented

... and one mitigation is to use cmake_minimum_required(VERSION 3.21) which enables the new policies.

So you think I should try that as a workaround? I’m assuming there will be a fix coming in a future vcpkg release? Or am I misunderstanding completely?

dg0yt commented

I'm preparing the PR now, but I can't say when it will be merged.

Thank you! 🙌