# Building and compiling GLFW on OSX with CMake?

**URL:** <https://discourse.glfw.org/t/building-and-compiling-glfw-on-osx-with-cmake/1996>\
**Category:** support\
**Created:** [February 13, 2022, 12:12pm UTC](https://discourse.glfw.org/t/building-and-compiling-glfw-on-osx-with-cmake/1996 "2022-02-13T12:12:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbilyanov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/mbilyanov/32/600_2.png) [@mbilyanov](https://discourse.glfw.org/u/mbilyanov)\
**Post date:** [February 13, 2022, 12:12pm UTC](https://discourse.glfw.org/t/building-and-compiling-glfw-on-osx-with-cmake/1996/1 "2022-02-13T12:12:00Z")

</div>

I would like to build GLFW with CMake on OSX, no XCode, no Visual Studio etc. The purpose is to have GLFW in a custom location where I can link it against any of my projects.

So I downloaded the \*.zip file and extracted it inside:  
`~/.tmp/glfw-3.3.6`

Then I created a build folder inside the folder listed above, and within that folder I have executed the following command:  
`cmake -S /Users/me/.tmp/glfw-3.3.6 -B /Users/me/.tmp/glfw-3.3.6/build`

Which seems to have worked, as I did not get any errors. Then I have executed:  
`make`

And that also seems to have worked, no errors. But that is where the instructions in the documentation section of GLFW end.

Where are the header files and the library files to link against?

With a last bit of desperation, I typed `make install` and the process chucked bunch of files into `/usr/local` which was definitely the one thing I didn’t want to happen!

```auto
-- Installing: /usr/local/lib/libglfw3.a
-- Installing: /usr/local/include/GLFW
-- Installing: /usr/local/include/GLFW/glfw3.h
-- Installing: /usr/local/include/GLFW/glfw3native.h
-- Installing: /usr/local/lib/cmake/glfw3/glfw3Config.cmake
-- Installing: /usr/local/lib/cmake/glfw3/glfw3ConfigVersion.cmake
-- Installing: /usr/local/lib/cmake/glfw3/glfw3Targets.cmake
-- Installing: /usr/local/lib/cmake/glfw3/glfw3Targets-noconfig.cmake
-- Installing: /usr/local/lib/pkgconfig/glfw3.pc

```

Is that it? I wanted to have GLFW in my custom location but there is nothing about this in the documentation?

---

<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:** [February 15, 2022, 12:37pm UTC](https://discourse.glfw.org/t/building-and-compiling-glfw-on-osx-with-cmake/1996/2 "2022-02-15T12:37:13Z")

</div>

If you want to install GLFW using CMake into a custom directory check out the CMAKE\_INSTALL\_PREFIX documentation:  
[https://cmake.org/cmake/help/v3.0/variable/CMAKE\_INSTALL\_PREFIX.html](https://cmake.org/cmake/help/v3.0/variable/CMAKE_INSTALL_PREFIX.html)

Alternatively you could use GLFW as a subrepository of your projects, which is what I would normally recommend as this makes setup across multiple machines much easier. For an example of this checkout this GLFW CMake Stater:

> **[GitHub - juliettef/GLFW-CMake-starter: Use CMake to create a project with GLFW...](https://github.com/juliettef/GLFW-CMake-starter)**
>
> Use CMake to create a project with GLFW - Multi-platform Windows, Linux and MacOS. - GitHub - juliettef/GLFW-CMake-starter: Use CMake to create a project with GLFW - Multi-platform Windows, Linux a...

This example has a single project linking to GLFW, but you can have multiple projects under individual directories with a cmake script referencing these, or describe the multiple targets in one cmake file.
