Klemensmandzaro
Klemensmandzaro

Reputation: 1

CMake can't find SDL2_ttf?

So that's how my cmake looks

cmake_minimum_required(VERSION 3.26)
project(sdlsaper)
set(CMAKE_CXX_FLAGS "-Wall -std=c++0x -ggdb ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules)
set(SDL2_PATH "C:/Users/kamil/Downloads/SDL2-devel-2.28.5-mingw/SDL2-2.28.5/x86_64-w64-mingw32")
set(SDL2_ttf_PATH "C:/Users/kamil/Downloads/SDL2_ttf-devel-2.20.2-mingw/SDL2_ttf-2.20.2/x86_64-w64-mingw32")

find_package(SDL2 REQUIRED)
find_package(SDL2_ttf REQUIRED)

include_directories(${SDL2_INCLUDE_DIR}
    ${SDL2_ttf_INCLUDE_DIR})

set(SOURCE_FILES
        "src/main.cpp"
        "src/SDL_Context.cpp"
        "src/config.cpp"
        "src/utils.cpp"
        "src/texture.cpp"
        "src/text.cpp"
        "src/SDL_utils.cpp"
        "src/thumbnail.cpp"
        "src/display/display.cpp"
        "src/display/displayobject.cpp"
        "src/display/state.cpp"
        "src/display/cli.cpp"
        "src/display/cli_tags.cpp"
        "src/display/cli_command.cpp"
        "src/display/subtags.cpp"
        "src/display/info.cpp"
        "src/display/grid.cpp"
        "src/display/thumbs.cpp"
        "src/filestore/filestore.cpp"
        "src/filestore/file.cpp"
        "src/filestore/selector.cpp"
        "src/filestore/selection.cpp"
        "src/filestore/operation.cpp"
)
add_executable(sdlsaper main.cpp)


target_link_libraries(${sdlsaper} ${SDL2_LIBRARY}
        ${SDL2_ttf_LIBRARY})


And when i try to load my cmake i get this text:

CMake Error at C:/Users/kamil/AppData/Local/Programs/CLion/bin/cmake/win/x64/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find SDL2_ttf (missing: SDL2_ttf_LIBRARY SDL2_ttf_INCLUDE_DIR)

Honestly i tried many different metods that i found on github and stack but nothing works. SDL2 alone works fine but when i try to find the ttf library something happends.

Upvotes: 0

Views: 381

Answers (1)

Botje
Botje

Reputation: 31123

The package you compiled contains a lib/cmake/SDL2_ttf/sdl2_ttf-config.cmake which CMake's find_package can consume in config mode.

For that to work you need to tell CMake where to look:

list(APPEND CMAKE_PREFIX_PATH ${SDL2_ttf_PATH})

Now find_package(SDL2_ttf REQUIRED) will just work.

Also, both SDL2 and SDL2_ttf define nice CMake targets, so you can use modern CMake and get rid of those horrible _LIBRARY and _INCLUDE_DIR variables:

# This will set up both the include directories and the required link libraries
target_link_libraries(sdlsaper PUBLIC SDL2::SDL2 SDL2_ttf::SDL2_ttf)

Upvotes: 0

Related Questions