[REQUEST] Add SDL2::SDL2 alias to SDL2 target in CMake build

Hello. I hope this is the right place to post this, as I didn’t find any public place to contribute patches.

Currently SDL_image links with SDL2 like this:

target_link_libraries(SDL2_image PRIVATE SDL2::SDL2)

This doesn’t work when you build both SDL and SDL_image by adding both via “add_subdirectory” to your project, because SDL2 only creates SDL2::SDL2 alias when you install it. Here’s the error I see:

  Target "SDL2_image" links to target "SDL2::SDL2" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

It would be great to add this to SDL’s CMakeList:

add_library(SDL2::SDL2 ALIAS SDL2)

Hey eliasdaler,

I know this is from almost 2 years ago now but i’m running into the exact same issue when attempting to add both SDL2 and SDL_image to my project as git submodules and build everything via CMake.

I’ve scoured every relevant link I can find in google and have been unsuccessful so far in finding a solution.

Did you manage to find a fix? Or barring that, if anyone new is reading this (since my reply will bump this topic to the top of the list) and wouldn’t mind supplying a solution, it would be greatly appreciated.

I actually made a PR which fixed that a while ago. :slight_smile:

SDL_image just didn’t have releases for quite a while, so you should use some non-tagged commit for now.