steam-runtime icon indicating copy to clipboard operation
steam-runtime copied to clipboard

cmake in sniper fails to locate libogg and libvorbis

Open Gelmo opened this issue 10 months ago • 6 comments

Your system information

  • Steam Runtime Version: Sniper
  • Distribution: Using the image registry.gitlab.steamos.cloud/steamrt/sniper/sdk:latest

Please describe your issue in as much detail as possible:

We are building our game in the Sniper container per the documentation at GitLab. We have Cmake find several packages, for example:

find_package(ZLIB REQUIRED GLOBAL)

However, this does not work for ogg or vorbis:

find_package(Ogg REQUIRED GLOBAL)
 CMake Error at extern/CMakeLists.txt:38 (find_package):
   By not providing "FindOgg.cmake" in CMAKE_MODULE_PATH this project has
   asked CMake to find a package configuration file provided by "Ogg", but
   CMake did not find one.

   Could not find a package configuration file provided by "Ogg" with any of
   the following names:

     OggConfig.cmake
     ogg-config.cmake

   Add the installation prefix of "Ogg" to CMAKE_PREFIX_PATH or set "Ogg_DIR"
   to a directory containing one of the above files.  If "Ogg" provides a
   separate development package or SDK, be sure it has been installed.
find_package(Vorbis REQUIRED GLOBAL)
   Could not find a package configuration file provided by "Vorbis" with any
   of the following names:

     VorbisConfig.cmake
     vorbis-config.cmake

   Add the installation prefix of "Vorbis" to CMAKE_PREFIX_PATH or set
   "Vorbis_DIR" to a directory containing one of the above files.  If "Vorbis"
   provides a separate development package or SDK, be sure it has been
   installed.

When browsing the Sniper image, we see that vorbis is missing as well.

find /usr -iname "*sdl*cmake*" -o -iname "*zlib*cmake*" -o -iname "*freetype*cmake*" -o -iname "*vorbis*cmake*" -o -iname "*openal*cmake*" -o -iname "*curl*cmake*" -o -iname "*stb*cmake*"
/usr/lib/i386-linux-gnu/cmake/SDL2/sdl2-config-version.cmake
/usr/lib/i386-linux-gnu/cmake/SDL2/sdl2-config.cmake
/usr/lib/i386-linux-gnu/cmake/SDL2_image/sdl2_image-config-version.cmake
/usr/lib/i386-linux-gnu/cmake/SDL2_image/sdl2_image-config.cmake
/usr/lib/i386-linux-gnu/cmake/SDL2_mixer/sdl2_mixer-config-version.cmake
/usr/lib/i386-linux-gnu/cmake/SDL2_mixer/sdl2_mixer-config.cmake
/usr/lib/i386-linux-gnu/cmake/SDL2_ttf/sdl2_ttf-config-version.cmake
/usr/lib/i386-linux-gnu/cmake/SDL2_ttf/sdl2_ttf-config.cmake
/usr/lib/x86_64-linux-gnu/cmake/SDL2/sdl2-config-version.cmake
/usr/lib/x86_64-linux-gnu/cmake/SDL2/sdl2-config.cmake
/usr/lib/x86_64-linux-gnu/cmake/SDL2_image/sdl2_image-config-version.cmake
/usr/lib/x86_64-linux-gnu/cmake/SDL2_image/sdl2_image-config.cmake
/usr/lib/x86_64-linux-gnu/cmake/SDL2_mixer/sdl2_mixer-config-version.cmake
/usr/lib/x86_64-linux-gnu/cmake/SDL2_mixer/sdl2_mixer-config.cmake
/usr/lib/x86_64-linux-gnu/cmake/SDL2_ttf/sdl2_ttf-config-version.cmake
/usr/lib/x86_64-linux-gnu/cmake/SDL2_ttf/sdl2_ttf-config.cmake
/usr/share/cmake-3.25/Modules/FindCURL.cmake
/usr/share/cmake-3.25/Modules/FindFreetype.cmake
/usr/share/cmake-3.25/Modules/FindSDL_gfx.cmake
/usr/share/cmake-3.25/Modules/FindSDL_image.cmake
/usr/share/cmake-3.25/Modules/FindSDL_net.cmake
/usr/share/cmake-3.25/Modules/FindOpenAL.cmake
/usr/share/cmake-3.25/Modules/FindSDL.cmake
/usr/share/cmake-3.25/Modules/FindSDL_mixer.cmake
/usr/share/cmake-3.25/Modules/FindSDL_sound.cmake
/usr/share/cmake-3.25/Modules/FindSDL_ttf.cmake
/usr/share/cmake-3.25/Modules/FindZLIB.cmake
/usr/share/cmake-3.25/Modules/TestBigEndian.cmake

Gelmo avatar Jan 10 '25 00:01 Gelmo

Maybe this is related - https://github.com/xiph/vorbis/issues/69 - And if so, I suppose that means it won't be fixed until SLR is newer than Debian 11. I guess we'll need to add our own FindOgg.cmake and FindVorbis.cmake

Gelmo avatar Jan 10 '25 01:01 Gelmo

Likely related - https://github.com/xiph/ogg/issues/82

Gelmo avatar Jan 10 '25 22:01 Gelmo

The versions of libogg and libvorbis in sniper are correctly installed, but because they were built with Autotools, they didn't generate CMake-specific metadata describing how to find them.

For the Steam Runtime environment, please locate these libraries using pkg-config, which has cross-build-system metadata discovery that can be used from Autotools, CMake, Meson and probably others. The versions of libogg and libvorbis in sniper do provide pkg-config metadata.

https://cmake.org/cmake/help/latest/module/FindPkgConfig.html suggests that pkg_check_modules (OGG ogg) should set variables like OGG_FOUND, OGG_CFLAGS and OGG_LIBRARIES, and similar for vorbis.

A few libraries (like SDL and dbus) generate CMake-specific metadata even when they were built with some other build system, but this is not universal and cannot be relied on: it requires the maintainer of every library to write CMake-specific build system code, even if they do not use or recommend CMake themselves.

smcv avatar Jan 13 '25 20:01 smcv

https://cmake.org/cmake/help/latest/module/FindPkgConfig.html suggests that pkg_check_modules (OGG ogg) should set variables like OGG_FOUND, OGG_CFLAGS and OGG_LIBRARIES, and similar for vorbis.

FYI I made the same mistake years ago -- due to cmake's lack of a type system you end up with weird definitions for these variables and generated compiler command lines may or may not end up looking like:

gcc main.o -o fooprog -L/usr/lib64;-logg

If possible please use pkg_check_modules(OGG IMPORTED_TARGET ogg), which similar to meson's dependency() will provide an interface dependency, PkgConfig::OGG, which is exactly equivalent to cmake-specific metadata such as Ogg::ogg except detected by pkg-config.

I do not know why cmake doesn't default to doing this, other than I guess dislike of making it easy for linux users to use pkg-config.

eli-schwartz avatar Jan 28 '25 00:01 eli-schwartz

@eli-schwartz:

If possible please use pkg_check_modules(OGG IMPORTED_TARGET ogg), which similar to meson's dependency() will provide an interface dependency, PkgConfig::OGG, which is exactly equivalent to cmake-specific metadata such as Ogg::ogg except detected by pkg-config.

Thanks, this does seem better than what I suggested above.

I've added a working example of using these three libraries from CMake, which will be part of the automated tests for each future SDK release, demonstrating that using these libraries is possible and hasn't regressed: https://gitlab.steamos.cloud/steamrt/steamrt/-/blob/steamrt/sniper/examples/ogg-vorbis/CMakeLists.txt?ref_type=heads

It's disappointing that the CMake documentation doesn't use this pattern in its examples of how to use pkg_check_modules() (and as a result, community-contributed FindFoo.cmake files don't usually use this pattern either).

@Gelmo:

I guess we'll need to add our own FindOgg.cmake and FindVorbis.cmake

Or you could use pkg_check_modules directly, like the example above does.

If you'd prefer to use FindFoo.cmake, you could reuse or improve someone else's implementation rather than necessarily having to write your own from scratch. For Ogg, https://github.com/xiph/opusfile/blob/master/cmake/FindOgg.cmake seems like a good implementation.

I can't immediately find an equally good equivalent for Vorbis. The Vorbis source package provides three separate libraries (vorbis, vorbisenc, vorbisfile) each with their own pkg-config metadata, so you'd probably want to provide three separate imported targets, or possibly three separate FindFoo implementations.

smcv avatar Jan 29 '25 17:01 smcv

I've added a working example of using these three libraries from CMake, which will be part of the automated tests for each future SDK release, demonstrating that using these libraries is possible and hasn't regressed

This was part of in yesterday's sniper beta 3.0.20250210.116596.

smcv avatar Feb 12 '25 14:02 smcv