title: SDL2 and CMake on OS X 10.11
body: <p>I know there are some answers (e.g. <a href="https://stackoverflow.com/questions/8136857/libsdl-cmake-and-mac-os-x-lion">here</a>, <a href="https://stackoverflow.com/questions/16163670/libsdl-cmake-and-mac-os-x-lion-2">here</a> or <a href="https://stackoverflow.com/questions/28395833/using-sdl2-with-cmake">here</a>), but I can't get it to work:</p>
  
  <p>Consider a MWE <em>main.cpp</em></p>
  
  <pre><code>// depending on the source of the example,
  // one of the two includes is used
  //#include &lt;SDL2/SDL.h&gt;
  #include "SDL.h"
  
  int main() {
      //Start SDL
      SDL_Init( SDL_INIT_EVERYTHING );
      //Quit SDL
      SDL_Quit();
      return 0;
  }
  </code></pre>
  
  <p>I <a href="https://www.libsdl.org/download-2.0.php" rel="nofollow">downloaded</a> SDL2 v2.0.4 on OS X 10.11 and copied the <em>SDL2.framework</em> file into the <em>/Library/Frameworks</em> folder.</p>
  
  <p>Now I am trying to find a working CMake script to compile <em>main.cpp</em>.</p>
  
  <p>First i tried</p>
  
  <pre><code>find_package(SDL)
  add_executable(example main.cpp)
  target_include_directories(example ${SDL_INCLUDE_DIR})
  target_link_libraries(example ${SDL_LIBRARY})
  </code></pre>
  
  <p>But I get the error message</p>
  
  <pre><code>Could NOT find SDL (missing:  SDL_LIBRARY) (found version "2.0.4")
  CMake Error at CMakeLists.txt:3 (target_include_directories):
    target_include_directories called with invalid arguments
  </code></pre>
  
  <p>If I included <a href="https://github.com/brendan-w/collector/blob/master/cmake/FindSDL2.cmake#L50" rel="nofollow">FindSDL2.cmake</a> in a <em>cmake</em> subdirectory and use the script</p>
  
  <pre><code>set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
  find_package(SDL2 REQUIRED)
  include_directories(${SDL2_INCLUDE_DIR})
  add_executable(example main.cpp)
  </code></pre>
  
  <p>CMake works, but I get a linker error:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "_SDL_Init", referenced from:
        _main in main.cpp.o
    "_SDL_Quit", referenced from:
        _main in main.cpp.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>Do you have any idea what my problems are and how I can use SDL2 properly this way?</p>