Disable backends with CMake

Started by luckeedev, 27 March 2023, 14:27:28

luckeedev

When using TGUI with cmake, it searches for all backends (SDL, GLFW...) and this throws an error if the library is not installed on the system. Is it possible to avoid this?

texus

That should not be happening, it should only search for the selected backend.

If you don't specify TGUI_BACKEND, it will show an error on the first cmake run that no backend was selected, but will set to TGUI_BACKEND to SFML_GRAPHICS for the future. If you run the configure step again, it will thus search for SFML. The cmake script should never be searching for all backends unless you manually ask it to.

Can you clean your build directory, run cmake again and show its output?

luckeedev

This is the relevant code in my
CMakeLists.txtset(TGUI_BACKEND SFML_GRAPHICS)
find_package(SFML 2.5 COMPONENTS graphics REQUIRED)
find_package(TGUI 0.10 REQUIRED)

This is the output of
cmake -S . -B build
-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found SFML 2.5.1 in /usr/lib/x86_64-linux-gnu/cmake/SFML
-- Found SFML 2.5.1 in /usr/lib/x86_64-linux-gnu/cmake/SFML
CMake Error at /usr/share/cmake-3.22/Modules/CMakeFindDependencyMacro.cmake:47 (find_package):
  Could not find a package configuration file provided by "glfw3" with any of
  the following names:

    glfw3Config.cmake
    glfw3-config.cmake

  Add the installation prefix of "glfw3" to CMAKE_PREFIX_PATH or set
  "glfw3_DIR" to a directory containing one of the above files.  If "glfw3"
  provides a separate development package or SDK, be sure it has been
  installed.
Call Stack (most recent call first):
  /usr/lib/x86_64-linux-gnu/cmake/TGUI/TGUIConfig.cmake:113 (find_dependency)
  CMakeLists.txt:30 (find_package)

texus

Ah ok, you aren't building TGUI yourself but you are using a library that was build with all backends included. In that case it won't be possible, as the TGUIConfig.cmake file will simply load all backends that existed when it was generated. The TGUI_BACKEND variable has no effect in your cmake script because it is only used while building TGUI.

The ubuntu package was build with SFML, SDL and GLFW and it indeed requires that libsfml-dev, libsdl2-dev, libsdl2-ttf-dev, libglfw3-dev and libfreetype-dev are installed on the system. It seems like my package is only listing the dependencies without the "-dev" postfix, which is why those weren't installed automatically. This is something that I will need to look into.

I don't really know what I can do to improve the situation. The ubuntu package was mostly provided for convenience, but I guess it might be even less useful than I though.

The only way right now to have a TGUI library that only contains the components that you need is to build it yourself with CMake.

luckeedev

Thanks for your reply, I built it myself with CMake. Where should I put the library now, in order for CMake to find it?

texus

If you run "sudo make install" (assuming you build it with Makefiles) then it will install it to /usr/local and cmake should find it automatically.

Otherwise you have to set the TGUI_DIR variable in your cmake project to the directory containing TGUIConfig.cmake (which is either the directory you built TGUI in or the lib/cmake/TGUI subdirectory at the location where you installed TGUI to).

luckeedev

Awesome, thanks a lot for your help. It worked!