# GLFW with CMake on Windows, GLFW\_INCLUDE\_DIRS or GLFW\_LIBRARIES not set

**URL:** <https://discourse.glfw.org/t/glfw-with-cmake-on-windows-glfw-include-dirs-or-glfw-libraries-not-set/890>\
**Category:** support\
**Created:** [April 6, 2017, 8:16am UTC](https://discourse.glfw.org/t/glfw-with-cmake-on-windows-glfw-include-dirs-or-glfw-libraries-not-set/890 "2017-04-06T08:16:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vinnie](https://avatars.discourse-cdn.com/v4/letter/v/71e660/32.png) [@Vinnie](https://discourse.glfw.org/u/Vinnie)\
**Post date:** [April 6, 2017, 8:16am UTC](https://discourse.glfw.org/t/glfw-with-cmake-on-windows-glfw-include-dirs-or-glfw-libraries-not-set/890/1 "2017-04-06T08:16:41Z")

</div>

Hi Guys

Awesome work on GLFW.

I’ve build GLFW 3.2.1 from source and explicitly specified the `lib` suffix and the installation prefix. After compilation, everything is installed where I expect it to be and the respective `glfw3Config.cmake` file also installed.

When I then try to use glfw3 in my own application and try to detect it using CMake it seems that the `GLFW_INCLUDE_DIRS` and `GLFW_LIBRARIES` variables are not set when finding the glfw3 package, I.e.:

`find_package(glfw3 3.2 CONFIG REQUIRED PATH_SUFFIXES "/cmake/glfw3")`

CMake definitely found the glfw3Config.cmake (glfw3\_DIR is set). Did I miss something in the build configuration to export these variables? Can I force these variables to be set at compile time (of glfw3) on Windows?

According to this example page:[http://www.glfw.org/docs/3.0/build.html](http://www.glfw.org/docs/3.0/build.html) it also seems to indicate that the variables are perhaps not set on windows on purpose. Is this a higher design consideration I’m missing?

If none of the above, is it possible to do a feature request to have the variables set in the same way for windows as they are set on Unix?

Cheers  
-Vinnie

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [April 6, 2017, 8:45am UTC](https://discourse.glfw.org/t/glfw-with-cmake-on-windows-glfw-include-dirs-or-glfw-libraries-not-set/890/2 "2017-04-06T08:45:55Z")

</div>

If [you’d like to request a feature use the GLFW issue list on Github](https://github.com/glfw/glfw/issues).

Personally I don’t install libraries, so my process for using glfw with cmake on Windows and other OSs is to put glfw in a known directory (here below the cmakelists.txt dir for my project):

```
find_package(OpenGL REQUIRED)

include_directories("glfw/include")

set( ENKITS_BUILD_EXAMPLES OFF CACHE BOOL "Build basic example applications" )
set( GLFW_BUILD_EXAMPLES OFF CACHE BOOL "GLFW lib only" )
set( GLFW_BUILD_TESTS OFF CACHE BOOL "GLFW lib only" )
set( GLFW_BUILD_DOCS OFF CACHE BOOL "GLFW lib only" )
set( GLFW_BUILD_INSTALL OFF CACHE BOOL "GLFW lib only" )

add_subdirectory( glfw )

target_link_libraries( executablename glfw ${GLFW_LIBRARIES} )
```

---

<div class="post-metadata">

**Author:** ![elmindreda](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/elmindreda/32/26_2.png) [@elmindreda](https://discourse.glfw.org/u/elmindreda)\
**Post date:** [April 6, 2017, 11:16am UTC](https://discourse.glfw.org/t/glfw-with-cmake-on-windows-glfw-include-dirs-or-glfw-libraries-not-set/890/3 "2017-04-06T11:16:59Z")

</div>

@Vinnie Your documentation URL is specific for version 3.0, which is fairly old. Use the `latest` alias to get the documentation for the most recent release: [http://www.glfw.org/docs/latest/build.html](http://www.glfw.org/docs/latest/build.html)

However, half of the [relevant section](http://www.glfw.org/docs/3.3/build.html#build_link_cmake_package) seems to have gone missing. Below are the missing bits:

You don’t need any `GLFW_` variables anymore; all necessary dependencies and paths are now stored in the imported `glfw` CMake target you get from the `glfw3` config-file package. Just add `glfw` as a dependency for your program.

```cmake
target_link_libraries(myapp glfw)

```

@dougbinks This also applies to source tree builds. You shouldn’t need the `GLFW_` dependency variables anymore either.

**Edit:** You shouldn’t need `include_directories` for the GLFW headers either, as that’s also part of the `glfw` target.

---

<div class="post-metadata">

**Author:** ![Vinnie](https://avatars.discourse-cdn.com/v4/letter/v/71e660/32.png) [@Vinnie](https://discourse.glfw.org/u/Vinnie)\
**Post date:** [April 6, 2017, 5:04pm UTC](https://discourse.glfw.org/t/glfw-with-cmake-on-windows-glfw-include-dirs-or-glfw-libraries-not-set/890/4 "2017-04-06T17:04:53Z")

</div>

@elmindreda Thanks, I had a quick read through the generated glfw3Target.cmake file. I did not realize you could set the include directories as a property of the target! Great tip for future projects.

My mistake was in trying to get things working sequentially in my new CMake project, i.e. tell CMake to find the headers before / without specifying the `target_link_libraries(myapp glfw)`, thus when the compiler failed to find the headers, it send me down the `GLFW_INCLUDE_DIRS` rabbit hole. Thanks for the clarification! It’s working beautifully! 🙂

---

<div class="post-metadata">

**Author:** ![Chretienorthodox](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/chretienorthodox/32/311_2.png) [@Chretienorthodox](https://discourse.glfw.org/u/Chretienorthodox)\
**Post date:** [September 17, 2020, 7:30am UTC](https://discourse.glfw.org/t/glfw-with-cmake-on-windows-glfw-include-dirs-or-glfw-libraries-not-set/890/5 "2020-09-17T07:30:19Z")

</div>

Dear Vinnie  
Please let me suggest you article [How to Use CMake to Get Binaries from Source Code](https://www.wikihow.com/Use-CMake-to-Get-Binaries-from-Source-Code).  
With regards and friendship  
Georges Theodosiou
