title: Linking SDL2/SD2_image statically with CMake
body: <p>I'm trying to add SDL2 as a library to my project. I want to link it statically. I'm new to c++.</p>
  
  <p><strong>1 - Why does the SDL website recommend linking dynamically whenever possible?</strong> </p>
  
  <p>I understand the benefits of dynamic libs. However, assuming users will have all the libraries you need already installed and ready to go in their system is a pretty big assumption IMO.
  The only case where linking dynamically sounds like a good idea to me is where you are using well know libraries that ship with the OS/platform.
  <a href="https://wiki.libsdl.org/Installation" rel="nofollow noreferrer">https://wiki.libsdl.org/Installation</a></p>
  
  <p><strong>2 - Linking dynamically seems to automatically find the intrinsic dependencies of (SDL2 and SDL2_image). Linking statically does not. Why is this the case?</strong> Here's my <code>FindSDL2_image.cmake</code> file</p>
  
  <pre><code>
  find_path(SDL2_IMAGE_INCLUDE_DIR SDL_image.h)
  include_directories(${SDL2_IMAGE_INCLUDE_DIR})
  
  # PREFER STATIC LIBRARIES ########
  # cmake respects the order of extensions when looking for libraries
  SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
  # ------------------- ########
  
  find_library(SDL2_IMAGE_LIBRARY NAMES SDL2_image PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX})
  set(SDL2_IMAGE ${SDL2_IMAGE_LIBRARY})
  
  </code></pre>
  
  <p>This links sdl2_image statically. It doesn't link properly because <code>Undefined symbols</code>:</p>
  
  <pre><code>  "_png_set_strip_16", referenced from:
        _IMG_LoadPNG_RW in libSDL2_image.a(IMG_png.o)
    "_png_set_write_fn", referenced from:
        _IMG_SavePNG_RW_libpng in libSDL2_image.a(IMG_png.o)
    "_png_write_png", referenced from:
        _IMG_SavePNG_RW_libpng in libSDL2_image.a(IMG_png.o)
  </code></pre>
  
  <p>If I remove the section <code>### PREFER STATIC LIBRARIES ##</code> on the cmake file. It links dynamically and everything works as expected. Why when linking dynamically the intrinsic dependencies are resolved but not when linking statically?</p>
  
  <p><strong>----UPDATE----</strong></p>
  
  <p>I was able to link sdl2_image statically by including its dependencies explicitly</p>
  
  <pre><code>find_library(PNGLIB png)
  find_library(JPEG jpeg)
  find_library(TIFF tiff)
  find_library(WEBP webp)
  find_library(LZ z)
  
  target_link_libraries(smb ${SDL2} ${PNGLIB} ${JPEG} ${TIFF} ${WEBP} ${SDL2_IMAGE} ${LZ})
  </code></pre>
  
  <p>However, this will not scale well for me. 
  Figuring out what these dependencies took a bit of guesswork and googling. Ideally, I'd like CMAKE to pull these in automatically.</p>