libsdl-org / SDL_ttf

Support for TrueType (.ttf) font files with Simple Directmedia Layer.
zlib License
343 stars 116 forks source link

Help building SDL_ttf using CMake? #316

Closed slouken closed 5 months ago

slouken commented 7 months ago

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. :)

madebr commented 7 months ago

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

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:

madebr commented 7 months ago

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)
slouken commented 7 months ago

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

slouken commented 7 months ago

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

madebr commented 7 months ago

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.

madebr commented 7 months ago

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.