title: Statically linking GLEW from source with cmake
body: <p>I am somewhat new to cmake and completely new to glew, glfw, and the like. I'm following a <a href="https://www.youtube.com/watch?v=vWU8EltWTfM&amp;list=PLlrATfBNZ98fqE45g3jZA_hLGUrD4bo6_" rel="nofollow noreferrer">youtube channel</a> to learn more about game engines and programming.</p>
  
  <p>My problem is linking the static glew library in my project using cmake.</p>
  
  <p>First, I start with the glew source code from <a href="http://mcs.une.edu.au/doc/glew-devel/index.html" rel="nofollow noreferrer">http://mcs.une.edu.au/doc/glew-devel/index.html</a>.</p>
  
  <p>I compile it by:</p>
  
  <pre><code>cd build; cmake ./cmake; make glew_s
  </code></pre>
  
  <p>This adds a lib directory into the build directory with libGLEW.a</p>
  
  <p>A shortened version of my CMakeLists.txt looks like:</p>
  
  <pre class="lang-none prettyprint-override"><code>cmake_minimum_required (VERSION 3.5 FATAL_ERROR)
  project (TestProject CXX)
  
  set(CMAKE_CXX_FLAGS "-std=c++11")
  
  ###########################
  # GLEW
  ###########################
  add_subdirectory(${CMAKE_SOURCE_DIR}/Dependencies/GLEW)
  target_link_libraries(${PROJECT_NAME} glew)
  </code></pre>
  
  <p>and in <code>Dependencies/GLEW</code> I have another <code>CMakeLists.txt</code>:</p>
  
  <pre class="lang-none prettyprint-override"><code># Add glew source and header files  
  file(GLOB_RECURSE glew-lib ${CMAKE_CURRENT_SOURCE_DIR}/lib/*)  
  file(GLOB_RECURSE glew-headers ${CMAKE_CURRENT_SOURCE_DIR}/include/GL/*)
  
  add_library(glew ${glew-lib} ${glew-headers})  
  target_include_directories(glew PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/GL")
  </code></pre>
  
  <hr>
  
  <p>I put a copy of the <code>libGLEW.a</code> file into the lib directory and the include directory is copied from the glew source code include directory. It holds the GL directory, which contains the header files <code>glew.h</code>, <code>wglew.h</code>, <code>eglew.h</code>, and <code>glxew.h</code>.</p>
  
  <p>When I run <code>cmake</code> I get the error:</p>
  
  <pre class="lang-none prettyprint-override"><code>CMake Error: Cannot determine link language for target "glew".  
  CMake Error: CMake can not determine linker language for target: glew
  </code></pre>
  
  <hr>
  
  <p>The glew source code also has a src directory with <code>glew.c</code> in it, but if I put it in the <code>libs</code> directory and include it in the <code>Dependencies/GLEW/CMakeLists.txt</code> like:</p>
  
  <pre class="lang-none prettyprint-override"><code># Add glew source and header files  
  file(GLOB_RECURSE glew-lib ${CMAKE_CURRENT_SOURCE_DIR}/lib/*.c)
  file(GLOB_RECURSE glew-headers ${CMAKE_CURRENT_SOURCE_DIR}/include/GL/*)
  add_library(glew ${glew-lib} ${glew-headers})
  target_include_directories(glew PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre class="lang-none prettyprint-override"><code>CMake Error: Error required internal CMake variable not set, cmake may
  be not be built correctly.  
  Missing variable is: CMAKE_C_COMPILE_OBJECT  
  CMake Error: Error required internal CMake variable not set, cmake may
  be not be built correctly.  
  Missing variable is: CMAKE_C_CREATE_STATIC_LIBRARY
  </code></pre>
  
  <hr>
  
  <p>Lastly, I have tried just including the <code>glew.c</code> and headers in the root <code>CMakeLists.txt</code> like:</p>
  
  <pre class="lang-none prettyprint-override"><code>#########################
  # GLEW  
  #########################
  include_directories("${CMAKE_SOURCE_DIR}/Dependencies/GLEW/lib/")
  include_directories("${CMAKE_SOURCE_DIR}/Dependencies/GLEW/include/GL/")
  </code></pre>
  
  <p>Here <code>cmake</code> will finish, but it won't be able to compile, saying classes do not name a type and/or are not declared in this scope.</p>
  
  <p>Any help would be appreciated. I was under the impression that the <code>libGLEW.a</code> was the static library, and all I would have to do is link and compile it along with the headers, but that did not work.</p>