El_Ten
El_Ten

Reputation: 9

Cmake + SDL3_ttf. How create as subdirectory?

VSCode,WIndows 10. I want to understand how cmake works with sdl3. I found such a lesson, of course there is sdl2 and I thought it would work with sdl3. Lesson: https://www.studyplan.dev/sdl2-minesweeper/sdl2-cmake

cmake_minimum_required(VERSION 3.12.0)
project(helloworld)
add_subdirectory(SDL)
add_subdirectory(SDL_ttf)

add_executable(helloworld
    main.cpp
)

target_link_libraries(helloworld
PRIVATE SDL3::SDL3)
target_link_libraries(helloworld PRIVATE 
SDL3_ttf::SDL3_ttf
)

add_custom_command(
  TARGET helloworld POST_BUILD COMMAND
  ${CMAKE_COMMAND} -E copy_if_different
    "$<TARGET_FILE:SDL3::SDL3>"
    "$<TARGET_FILE:SDL3_ttf::SDL3_ttf>" 
    "$<TARGET_FILE_DIR:helloworld>"
  VERBATIM
)

But I get an error with freetype inside sdl_ttf

[cmake] -- SDL3_ttf: Using system freetype library
[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.31/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
[cmake]   Could NOT find Freetype (missing: FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS)
[cmake] Call Stack (most recent call first):
[cmake]   C:/Program Files/CMake/share/cmake-3.31/Modules/FindPackageHandleStandardArgs.cmake:603 (_FPHSA_FAILURE_MESSAGE)
[cmake]   C:/Program Files/CMake/share/cmake-3.31/Modules/FindFreetype.cmake:165 (find_package_handle_standard_args)
[cmake]   SDL_ttf/CMakeLists.txt:266 (find_package)

I want to add the external directory and add the Source folders SDL3, SDL3_image, SDL3_ttf there.

Get a hierarchy like this external / SDL3 SDL_image SDL_ttf src / main ui / src incl
I don't understand the principle of attaching external libraries(example SDL3_ttf) in any way. Can someone just show a working example and what he is doing for this

Decision:

cmake_minimum_required(VERSION 3.31)
SET(SDLTTF_VENDORED ON)

project(helloworld)
add_subdirectory(SDL EXCLUDE_FROM_ALL)
add_subdirectory(SDL_ttf EXCLUDE_FROM_ALL)
add_executable( helloworld main.cpp)
target_include_directories(helloworld PRIVATE
SDL/include
SDL_ttf/include
)
target_link_libraries(helloworld
PRIVATE SDL3::SDL3
SDL3_ttf::SDL3_ttf
Freetype::Freetype
)
add_custom_command(
  TARGET helloworld PRE_BUILD COMMAND
  ${CMAKE_COMMAND} -E copy_if_different 
  $<TARGET_FILE:SDL3::SDL3>
  $<TARGET_FILE:SDL3_ttf::SDL3_ttf>
  $<TARGET_FILE:Freetype::Freetype>
    $<TARGET_FILE_DIR:helloworld>
  VERBATIM 
)

Upvotes: 1

Views: 107

Answers (0)

Related Questions