Linking SDL2 and SoLoud via FetchContent in single CMake target

Viewed 286

For my CMake target I try to use both SDL2 and SoLoud libraries from github. I use FetchContent_Declare, followed by FetchContent_MakeAvailable for both of them - first SDL2, then SoLoud.

SoLoud however depends on SDL2 too. It uses find_package to find SDL2 which fails as follows: Could NOT find SDL2 (missing: SDL2_LIBRARY SDL2_INCLUDE_DIR)

What is the correct way to resolve this?

What I tried:

I did set SDL_INCLUDE_DIR manually like this: set(SDL2_INCLUDE_DIR, ${fetched_sdl_SOURCE_DIR}/include) (which seems like a hack but works) and I also manually set SDL2_LIBRARY to where my locally built SDL2 library is expected to land once it's compiled.

But I'd really like to make it robust i.e. account for lib naming differences based on platform (libSDL2.a on linux, SDL2.lib on windows etc.), account for 'd' in debug lib names and so on.

0 Answers
Related