3

I am currently writing an SDL2 program with the SDL2-ttf library and wanted to add a check for it in CMakeLists.txt. How do I do that?

I am using CMake 3.1.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
LocalToast
  • 397
  • 1
  • 5
  • 13
  • I tweaked your title to [remove a tag from it](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles) and include a more specific qualifier. – Nathan Tuggy Mar 15 '15 at 02:49
  • did you ever find a working answer for this? I'm pretty sure arved's answer below doesn't work for SDL2. – xaxxon Dec 14 '15 at 14:24

2 Answers2

8

The FindSDL_ttf doesn't work with SDL2, so you'll have to use a third party option.

I've used this and it works: https://raw.githubusercontent.com/Deraen/ohj2710/master/cmake_modules/FindSDL2TTF.cmake

Just put it in a directory included by set(CMAKE_MODULE_PATH /path/to/file)

and then use it find_package(SDL2TTF)

xaxxon
  • 19,189
  • 5
  • 50
  • 80
  • I can't seem to get this to work... I have added `set(cmake_module_path /home/user/project)`, the above linked file I saved in the location `/home/user/project`, then I also added `find_package(SDL2TTF REQUIRED)` and `target_link_libraries(projectname ${SDL2_LIBRARIES} ${SDL2TTF_LIBRARIES})` to my `CMakeLists.txt`. Any idea what's wrong? – FreelanceConsultant Feb 08 '18 at 23:15
  • 1
    Fixed: Should be `SDL2TTF_LIBRARY` – FreelanceConsultant Feb 08 '18 at 23:24
  • Yes, here's what I have: target_link_libraries(my_target ${SDL2_LIBRARY} ${SDL2TTF_LIBRARY}) – xaxxon Feb 09 '18 at 00:12
2

FindSDL_ttf.cmake is part of cmake 3.x just use

find_package(SDL_ttf REQUIRED)
arved
  • 4,401
  • 4
  • 30
  • 53
  • 2
    My understanding is that this doesn't work for SDL2 (as asked in the question), only original SDL. I was told this on freenode #cmake and it also doesn't work for me. – xaxxon Dec 14 '15 at 14:22
  • Have you checked this question:https://stackoverflow.com/questions/23850472/how-to-use-sdl2-and-sdl-image-with-cmake – arved Dec 14 '15 at 14:29