libsdl-org/SDL_ttf

Help building SDL_ttf using CMake?

slouken opened this issue · 6 comments

I've run external/download.sh to get the dependencies, and then:
cmake -DCMAKE_BUILD_TYPE=Release .. -DSDL3_DIR=../external/SDL

fails with:

-- Configuring SDL3_ttf 3.0.0
CMake Error at CMakeLists.txt:87 (find_package):
  By not providing "FindSDL3.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "SDL3", but
  CMake did not find one.

  Could not find a package configuration file provided by "SDL3" (requested
  version 3.0.0) with any of the following names:

    SDL3Config.cmake
    sdl3-config.cmake

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


-- Configuring incomplete, errors occurred!
See also "C:/projects/SDL_ttf/build/CMakeFiles/CMakeOutput.log".

I'm sure I'm doing something silly, but there are no instructions on how to build this beast. :)

The satellite libraries expect an already configured SDL3 or already-built SDL3.
What I do:

  • SDL3 is checked out in ~/projects/SDL, builds in ~/projects/SDL/cmake-build-Debug and installs in ~/projects/SDL/cmake-build-Debug/prefix
  • SDL3_image is checked out in ~/projects/SDL_image, builds in ~/projects/SDL_image/cmake-build-Debug and installs in ~/projects/SDL_image/cmake-build-Debug/prefix

By configuring SDL3_image with -DSDL3_ROOT=$HOME/projects/SDL/cmake-build-debug (or -DSDL3_ROOT=$HOME/projects/SDL/cmake-build-debug/prefix), the cmake project will pick up the already built SDL3.
So there's no need for rebuilding SDL3 for every satellite library.

Btw:

  • SDL3_ROOT is for configuring the root folder of an SDL3 prefix
  • SDL3_DIR is for configuring the location of SDL3Config.cmake (on nix, this is $prefix/lib/pkgconfig/SDL3).

By "already configured SDL3`, I mean users of SDL that do this in their cmake script:

add_subdirecty(externals/SDL)
add_subdirecty(externals/SDL_image)

I think maybe we need build instructions in the satellite libraries. :)

How do you set the install location to ~/projects/SDL/cmake-build-Debug/prefix?

You can install to whatever location you desire with cmake --install ~/projects/SDL/cmake-build-debug --prefix /tmp/SDL-prefix.

The installation path can be configured with CMAKE_INSTALL_PREFIX.
When the path is not absolute, it installs relative to the working directory.

So in my example above, I configure with cmake -S ~/projects/SDL -B ~/projects/SDL/cmake-build-debug -DCMAKE_INSTALL_PREFIX=~/projects/SDL/cmake-build-debug/prefix.

Also worth mentioning is the following would work as well:

for sdl in SDL SDL_image SDL_ttf SDL_mixer SDL_net SDL_rtf; do
    cmake -S ~/projects/$sdllib -B ~/projects/$sdllib/cmake-build-debug -DCMAKE_INSTALL_PREFIX=/tmp/SDL-prefix
    cmake --build ~/projects/$sdllib/cmake-build-debug
    cmake --install ~/projects/$sdllib/cmake-build-debug
done

CMake also looks for dependencies in the installation prefix.
The commands above are very close to ../configure --prefix=/tmp/SDL-prefix && make && make install.