title: CMake find_package with GLEW
body: <p>I am trying to set up a CMakeLists.txt file for my project which uses GLEW. I have been doing it like this:</p>
  
  <pre><code>find_path(GLEW_INCLUDE_DIR GL/glew.h)  
  
  find_library(GLEW_LIBRARY_RELEASE glew32)
  find_library(GLEW_LIBRARY_DEBUG glew32d)
  
  target_include_directories(${APP_NAME} PUBLIC ${GLEW_INCLUDE_DIR}) 
  
  target_link_libraries(${APP_NAME} optimized ${GLEW_LIBRARY_RELEASE}
                                    debug ${GLEW_LIBRARY_DEBUG})
  </code></pre>
  
  <p>This approach works but I want to use the find_package approach because I think it is better. </p>
  
  <p>I have found some examples on this site like this one: <a href="https://stackoverflow.com/questions/49434279/adding-glew-to-project-cmake">Adding GLEW to project (CMake)</a> which suggests doing something like this: </p>
  
  <pre><code>find_package(GLEW REQUIRED)
  target_link_libraries(${APP_NAME} GLEW::GLEW)
  </code></pre>
  
  <p>But when I try to to do this, it produces errors during the configuration phase:</p>
  
  <pre><code>CMake Error at C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:16 (include):
  include could not find load file:
  
  C:/libs/glew-2.1.0/build/cmake/glew-targets.cmake
  Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:64 (get_property):
  get_property could not find TARGET GLEW::glew.  Perhaps it has not yet been
  created.
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  
  
  CMake Error at C:/libs/glew-2.1.0/build/cmake/CopyImportedTargetProperties.cmake:73 (get_target_property):
  get_target_property() called with non-existent target "GLEW::glew".
  Call Stack (most recent call first):
  C:/libs/glew-2.1.0/build/cmake/glew-config.cmake:56 (copy_imported_target_properties)
  C:/Program Files/CMake/share/cmake-3.15/Modules/FindGLEW.cmake:62 (find_package)
  CMakeLists.txt:14 (find_package)
  </code></pre>
  
  <p>So it looks like it is looking for glew-targets.cmake in C:/libs/glew-2.1.0/build/cmake which is the GLEW_DIR I set in CMake GUI because it has the glew-config.cmake file. </p>
  
  <p>But the glew-targets.cmake file is actually in C:\libs\glew-2.1.0\build\cmake\build\CMakeFiles\Export\lib\cmake\glew where it got created when I ran CMake on GLEW.</p>
  
  <p>Why is it looking in the wrong place?</p>
  
  <p>I downloaded GLEW as a .ZIP source from <a href="http://glew.sourceforge.net/" rel="noreferrer">http://glew.sourceforge.net/</a>. I then ran CMake on it while specifying C:/libs/glew-2.1.0/build/cmake as the source directory and C:/libs/glew-2.1.0/build/cmake/build as the build directory.</p>
  
  <p>So how exactly I am supposed to do this?</p>