title: How to properly link libraries with cmake?
body: <p>I can't get the additional libraries I am working with to link into my project properly.</p>
  
  <p>I am using CLion, which uses cmake to build it's projects. I am trying to use several libraries in conjunction with OpenGL to texture some objects. I initially built it in Visual Studio, because I couldn't ever figure out how to get cmake to work with Clion. However, now that the code is all working (in Visual Studio, anyways), I want to be able to use CLion for it, because that is my preferred IDE.</p>
  
  <p>I am still new to cmake, and I don't understand what I am doing wrong with my <code>CMakeLists.txt</code>. Here is what I have:</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.3)
  project(texture_mapping)
  find_package(OpenGL REQUIRED)
  link_directories(${OPENGL_gl_LIBRARY})
  
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  
  set(SOURCE_FILES main.cpp camera.h display.h display.cpp mesh.cpp mesh.h obj_loader.cpp obj_loader.h shader.cpp shader.h stb_image.c stb_image.h texture.cpp texture.h transform.h)
  
  link_directories(texture_mapping ${PROJECT_SOURCE_DIR}/lib)
  
  add_executable(texture_mapping ${SOURCE_FILES})
  
  target_include_directories(texture_mapping PUBLIC ${PROJECT_SOURCE_DIR}/include)
  target_link_libraries(texture_mapping SDL2 SDL2main SDL2test glew32 glew32s ${OPENGL_gl_LIBRARY})
  </code></pre>
  
  <p>I tweaked it until it didn't give me any more errors in CLion, but the header files are still not recognized in my code.</p>
  
  <p>Here is the structure of my project:<br>
  <a href="https://i.stack.imgur.com/Bp3No.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Bp3No.png" alt="project structure"></a></p>
  
  <p>So, I put all of the libraries I needed, but it doesn't appear to be recognizing them in the code. Clion recognizes them in the project (they aren't appearing red with errors), but when it is built (when I attempt to run it in CLion), I get these errors:</p>
  
  <pre><code>CMakeFiles\texture_mapping.dir/objects.a(mesh.cpp.obj): In function `ZN4MeshD2Ev':
  ...texture-mapping/mesh.cpp:30: undefined reference to `_imp____glewDeleteVertexArrays'
  CMakeFiles\texture_mapping.dir/objects.a(mesh.cpp.obj): In function `ZN4Mesh8InitMeshERK12IndexedModel':
  ...texture-mapping/mesh.cpp:36: undefined reference to `_imp____glewGenVertexArrays'
  ...texture-mapping/mesh.cpp:37: undefined reference to `_imp____glewBindVertexArray'
  ...texture-mapping/mesh.cpp:39: undefined reference to `_imp____glewGenBuffers'
  ...texture-mapping/mesh.cpp:40: undefined reference to `_imp____glewBindBuffer'
  ...texture-mapping/mesh.cpp:41: undefined reference to `_imp____glewBufferData'
  ...texture-mapping/mesh.cpp:43: undefined reference to `_imp____glewEnableVertexAttribArray'
  ...texture-mapping/mesh.cpp:44: undefined reference to `_imp____glewVertexAttribPointer'
  ...texture-mapping/mesh.cpp:46: undefined reference to `_imp____glewBindBuffer'
  ...texture-mapping/mesh.cpp:47: undefined reference to `_imp____glewBufferData'
  ...texture-mapping/mesh.cpp:49: undefined reference to `_imp____glewEnableVertexAttribArray'
  ...texture-mapping/mesh.cpp:50: undefined reference to `_imp____glewVertexAttribPointer'
  ...texture-mapping/mesh.cpp:52: undefined reference to `_imp____glewBindBuffer'
  ...texture-mapping/mesh.cpp:53: undefined reference to `_imp____glewBufferData'
  ...texture-mapping/mesh.cpp:55: undefined reference to `_imp____glewBindVertexArray'
  ...texture-mapping/mesh.cpp:56: undefined reference to `_imp____glewBindVertexArray'
  CMakeFiles\texture_mapping.dir/objects.a(mesh.cpp.obj): In function `ZN4Mesh4DrawEv':
  ...texture-mapping/mesh.cpp:61: undefined reference to `_imp____glewBindVertexArray'
  ...texture-mapping/mesh.cpp:65: undefined reference to `_imp____glewBindVertexArray'
  CMakeFiles\texture_mapping.dir/objects.a(shader.cpp.obj): In function `ZN6ShaderC2ERKSs':
  ...texture-mapping/shader.cpp:5: undefined reference to `_imp____glewCreateProgram'
  ...texture-mapping/shader.cpp:11: undefined reference to `_imp____glewAttachShader'
  ...texture-mapping/shader.cpp:14: undefined reference to `_imp____glewBindAttribLocation'
  ...texture-mapping/shader.cpp:15: undefined reference to `_imp____glewBindAttribLocation'
  ...texture-mapping/shader.cpp:17: undefined reference to `_imp____glewLinkProgram'
  ...texture-mapping/shader.cpp:20: undefined reference to `_imp____glewValidateProgram'
  ...texture-mapping/shader.cpp:23: undefined reference to `_imp____glewGetUniformLocation'
  CMakeFiles\texture_mapping.dir/objects.a(shader.cpp.obj): In function `ZN6Shader4BindEv':
  ...texture-mapping/shader.cpp:28: undefined reference to `_imp____glewUseProgram'
  CMakeFiles\texture_mapping.dir/objects.a(shader.cpp.obj): In function `ZN6Shader6UpdateERK9TransformRK6Camera':
  ...texture-mapping/shader.cpp:35: undefined reference to `_imp____glewUniformMatrix4fv'
  CMakeFiles\texture_mapping.dir/objects.a(shader.cpp.obj): In function `ZN6ShaderD2Ev':
  ...texture-mapping/shader.cpp:42: undefined reference to `_imp____glewDetachShader'
  ...texture-mapping/shader.cpp:43: undefined reference to `_imp____glewDeleteShader'
  ...texture-mapping/shader.cpp:46: undefined reference to `_imp____glewDeleteProgram'
  CMakeFiles\texture_mapping.dir/objects.a(shader.cpp.obj): In function `ZN6Shader16CheckShaderErrorEjjbRKSs':
  ...texture-mapping/shader.cpp:79: undefined reference to `_imp____glewGetProgramiv'
  ...texture-mapping/shader.cpp:81: undefined reference to `_imp____glewGetShaderiv'
  ...texture-mapping/shader.cpp:86: undefined reference to `_imp____glewGetProgramInfoLog'
  ...texture-mapping/shader.cpp:88: undefined reference to `_imp____glewGetShaderInfoLog'
  CMakeFiles\texture_mapping.dir/objects.a(shader.cpp.obj): In function `ZN6Shader12CreateShaderERKSsj':
  ...texture-mapping/shader.cpp:96: undefined reference to `_imp____glewCreateShader'
  ...texture-mapping/shader.cpp:109: undefined reference to `_imp____glewShaderSource'
  ...texture-mapping/shader.cpp:110: undefined reference to `_imp____glewCompileShader'
  CMakeFiles\texture_mapping.dir/objects.a(texture.cpp.obj): In function `ZN7Texture4BindEj':
  ...texture-mapping/texture.cpp:36: undefined reference to `_imp____glewActiveTexture'
  ...texture-mapping/lib/SDL2main.lib(./Win32/Release/SDL_windows_main.obj):(.text+0x24): undefined reference to `SDL_SetMainReady'
  ...texture-mapping/lib/SDL2main.lib(./Win32/Release/SDL_windows_main.obj):(.text+0x55): undefined reference to `SDL_malloc'
  ...texture-mapping/lib/SDL2main.lib(./Win32/Release/SDL_windows_main.obj):(.text+0x84): undefined reference to `SDL_wcslen'
  ...texture-mapping/lib/SDL2main.lib(./Win32/Release/SDL_windows_main.obj):(.text+0xa5): undefined reference to `SDL_iconv_string'
  ...texture-mapping/lib/SDL2main.lib(./Win32/Release/SDL_windows_main.obj):(.text+0xcf): undefined reference to `SDL_free'
  ...texture-mapping/lib/SDL2main.lib(./Win32/Release/SDL_windows_main.obj):(.text+0xf4): undefined reference to `SDL_wcslen'
  ...texture-mapping/lib/SDL2main.lib(./Win32/Release/SDL_windows_main.obj):(.text+0x10f): undefined reference to `SDL_iconv_string'
  ...texture-mapping/lib/SDL2main.lib(./Win32/Release/SDL_windows_main.obj):(.text+0x143): undefined reference to `SDL_malloc'
  ...texture-mapping/lib/SDL2main.lib(./Win32/Release/SDL_windows_main.obj):(.text+0x17f): undefined reference to `SDL_free'
  ...texture-mapping/lib/SDL2main.lib(./Win32/Release/SDL_windows_main.obj):(.text+0x18b): undefined reference to `SDL_free'
  ...texture-mapping/lib/SDL2main.lib(./Win32/Release/SDL_windows_main.obj):(.text+0x1d6): undefined reference to `SDL_isspace'
  ...texture-mapping/lib/SDL2main.lib(./Win32/Release/SDL_windows_main.obj):(.text+0x295): undefined reference to `SDL_isspace'
  ...texture-mapping/lib/SDL2main.lib(./Win32/Release/SDL_windows_main.obj):(.text+0x3a2): undefined reference to `SDL_ShowSimpleMessageBox'
  </code></pre>
  
  <p>Basically, errors with every usage of SDL and glew, but not glm, which is strange.</p>
  
  <p>What am I doing wrong with my <code>CMakeLists.txt</code>?</p>