<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>GLFW: Compiling GLFW</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
	<div class="glfwheader">
		<a href="http://www.glfw.org/" id="glfwhome">GLFW</a>
		<ul class="glfwnavbar">
			<li><a href="http://www.glfw.org/documentation.html">Documentation</a></li>
			<li><a href="http://www.glfw.org/download.html">Download</a></li>
			<li><a href="http://www.glfw.org/media.html">Media</a></li>
			<li><a href="http://www.glfw.org/community.html">Community</a></li>
		</ul>
	</div>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Compiling GLFW </div>  </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#compile_cmake">Using CMake</a><ul><li class="level2"><a href="#compile_deps">Dependencies</a><ul><li class="level3"><a href="#compile_deps_msvc">Dependencies for Visual C++ on Windows</a></li>
<li class="level3"><a href="#compile_deps_mingw">Dependencies for MinGW or MinGW-w64 on Windows</a></li>
<li class="level3"><a href="#compile_deps_mingw_cross">Dependencies for MinGW or MinGW-w64 cross-compilation</a></li>
<li class="level3"><a href="#compile_deps_xcode">Dependencies for Xcode on OS X</a></li>
<li class="level3"><a href="#compile_deps_x11">Dependencies for Linux and X11</a></li>
</ul>
</li>
<li class="level2"><a href="#compile_generate">Generating build files with CMake</a><ul><li class="level3"><a href="#compile_generate_cli">Generating files with the CMake command-line tool</a></li>
<li class="level3"><a href="#compile_generate_gui">Generating files with the CMake GUI</a></li>
</ul>
</li>
<li class="level2"><a href="#compile_compile">Compiling the library</a></li>
<li class="level2"><a href="#compile_options">CMake options</a><ul><li class="level3"><a href="#compile_options_shared">Shared CMake options</a></li>
<li class="level3"><a href="#compile_options_osx">OS X specific CMake options</a></li>
<li class="level3"><a href="#compile_options_win32">Windows specific CMake options</a></li>
</ul>
</li>
</ul>
</li>
<li class="level1"><a href="#compile_manual">Compiling GLFW manually</a></li>
</ul>
</div>
<div class="textblock"><p>This is about compiling the GLFW library itself. For information on how to build applications that use GLFW, see <a class="el" href="build_guide.html">Building applications</a>.</p>
<h1><a class="anchor" id="compile_cmake"></a>
Using CMake</h1>
<p>GLFW uses <a href="http://www.cmake.org/">CMake</a> to generate project files or makefiles for a particular development environment. If you are on a Unix-like system such as Linux or FreeBSD or have a package system like Fink, MacPorts, Cygwin or Homebrew, you can simply install its CMake package. If not, you can download installers for Windows and OS X from the <a href="http://www.cmake.org/">CMake website</a>.</p>
<dl class="section note"><dt>Note</dt><dd>CMake only generates project files or makefiles. It does not compile the actual GLFW library. To compile GLFW, first generate these files for your chosen development environment and then use them to compile the actual GLFW library.</dd></dl>
<h2><a class="anchor" id="compile_deps"></a>
Dependencies</h2>
<p>Once you have installed CMake, make sure that all other dependencies are available. On some platforms, GLFW needs a few additional packages to be installed. See the section for your chosen platform and development environment below.</p>
<h3><a class="anchor" id="compile_deps_msvc"></a>
Dependencies for Visual C++ on Windows</h3>
<p>The Microsoft Platform SDK that is installed along with Visual C++ already contains all the necessary headers, link libraries and tools except for CMake. Move on to <a class="el" href="compile_guide.html#compile_generate">Generating build files with CMake</a>.</p>
<h3><a class="anchor" id="compile_deps_mingw"></a>
Dependencies for MinGW or MinGW-w64 on Windows</h3>
<p>Both the MinGW and the MinGW-w64 packages already contain all the necessary headers, link libraries and tools except for CMake. Move on to <a class="el" href="compile_guide.html#compile_generate">Generating build files with CMake</a>.</p>
<h3><a class="anchor" id="compile_deps_mingw_cross"></a>
Dependencies for MinGW or MinGW-w64 cross-compilation</h3>
<p>Both Cygwin and many Linux distributions have MinGW or MinGW-w64 packages. For example, Cygwin has the <code>mingw64-i686-gcc</code> and <code>mingw64-x86_64-gcc</code> packages for 32- and 64-bit version of MinGW-w64, while Debian GNU/Linux and derivatives like Ubuntu have the <code>mingw-w64</code> package for both.</p>
<p>GLFW has CMake toolchain files in the <code>CMake/</code> directory that allow for easy cross-compilation of Windows binaries. To use these files you need to add a special parameter when generating the project files or makefiles:</p>
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;cmake -DCMAKE_TOOLCHAIN_FILE=&lt;toolchain-file&gt; .</div></div><!-- fragment --><p>The exact toolchain file to use depends on the prefix used by the MinGW or MinGW-w64 binaries on your system. You can usually see this in the /usr directory. For example, both the Debian/Ubuntu and Cygwin MinGW-w64 packages have <code>/usr/x86_64-w64-mingw32</code> for the 64-bit compilers, so the correct invocation would be:</p>
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;cmake -DCMAKE_TOOLCHAIN_FILE=CMake/x86_64-w64-mingw32.cmake .</div></div><!-- fragment --><p>For more details see the article <a href="http://www.paraview.org/Wiki/CMake_Cross_Compiling">CMake Cross Compiling</a> on the CMake wiki.</p>
<p>Once you have this set up, move on to <a class="el" href="compile_guide.html#compile_generate">Generating build files with CMake</a>.</p>
<h3><a class="anchor" id="compile_deps_xcode"></a>
Dependencies for Xcode on OS X</h3>
<p>Xcode comes with all necessary tools except for CMake. The required headers and libraries are included in the core OS X frameworks. Xcode can be downloaded from the Mac App Store or from the ADC Member Center.</p>
<p>Once you have Xcode installed, move on to <a class="el" href="compile_guide.html#compile_generate">Generating build files with CMake</a>.</p>
<h3><a class="anchor" id="compile_deps_x11"></a>
Dependencies for Linux and X11</h3>
<p>To compile GLFW for X11, you need to have the X11 packages installed, as well as the basic development tools like GCC and make. For example, on Ubuntu and other distributions based on Debian GNU/Linux, you need to install the <code>xorg-dev</code> package, which pulls in all X.org header packages.</p>
<p>Once you have installed the necessary packages, move on to <a class="el" href="compile_guide.html#compile_generate">Generating build files with CMake</a>.</p>
<h2><a class="anchor" id="compile_generate"></a>
Generating build files with CMake</h2>
<p>Once you have all necessary dependencies it is time to generate the project files or makefiles for your development environment. CMake needs to know two paths for this: the path to the <em>root</em> directory of the GLFW source tree (i.e. <em>not</em> the <code>src</code> subdirectory) and the target path for the generated files and compiled binaries. If these are the same, it is called an in-tree build, otherwise it is called an out-of-tree build.</p>
<p>One of several advantages of out-of-tree builds is that you can generate files and compile for different development environments using a single source tree.</p>
<dl class="section note"><dt>Note</dt><dd>This section is about generating the project files or makefiles necessary to compile the GLFW library, not about compiling the actual library.</dd></dl>
<h3><a class="anchor" id="compile_generate_cli"></a>
Generating files with the CMake command-line tool</h3>
<p>To make an in-tree build, enter the <em>root</em> directory of the GLFW source tree (i.e. <em>not</em> the <code>src</code> subdirectory) and run CMake. The current directory is used as target path, while the path provided as an argument is used to find the source tree.</p>
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;cd &lt;glfw-root-dir&gt;</div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;cmake .</div></div><!-- fragment --><p>To make an out-of-tree build, make a directory outside of the source tree, enter it and run CMake with the (relative or absolute) path to the root of the source tree as an argument.</p>
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;mkdir glfw-build</div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;cd glfw-build</div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;cmake &lt;glfw-root-dir&gt;</div></div><!-- fragment --><p>Once you have generated the project files or makefiles for your chosen development environment, move on to <a class="el" href="compile_guide.html#compile_compile">Compiling the library</a>.</p>
<h3><a class="anchor" id="compile_generate_gui"></a>
Generating files with the CMake GUI</h3>
<p>If you are using the GUI version, choose the root of the GLFW source tree as source location and the same directory or another, empty directory as the destination for binaries. Choose <em>Configure</em>, change any options you wish to, <em>Configure</em> again to let the changes take effect and then <em>Generate</em>.</p>
<p>Once you have generated the project files or makefiles for your chosen development environment, move on to <a class="el" href="compile_guide.html#compile_compile">Compiling the library</a>.</p>
<h2><a class="anchor" id="compile_compile"></a>
Compiling the library</h2>
<p>You should now have all required dependencies and the project files or makefiles necessary to compile GLFW. Go ahead and compile the actual GLFW library with these files, as you would with any other project.</p>
<p>Once the GLFW library is compiled, you are ready to build your applications, linking it to the GLFW library. See <a class="el" href="build_guide.html">Building applications</a> for more information.</p>
<h2><a class="anchor" id="compile_options"></a>
CMake options</h2>
<p>The CMake files for GLFW provide a number of options, although not all are available on all supported platforms. Some of these are de facto standards among projects using CMake and so have no <code>GLFW_</code> prefix.</p>
<p>If you are using the GUI version of CMake, these are listed and can be changed from there. If you are using the command-line version of CMake you can use the <code>ccmake</code> ncurses GUI to set options. Some package systems like Ubuntu and other distributions based on Debian GNU/Linux have this tool in a separate <code>cmake-curses-gui</code> package.</p>
<p>Finally, if you don't want to use any GUI, you can set options from the <code>cmake</code> command-line with the <code>-D</code> flag.</p>
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;cmake -DBUILD_SHARED_LIBS=ON .</div></div><!-- fragment --><h3><a class="anchor" id="compile_options_shared"></a>
Shared CMake options</h3>
<p><code>BUILD_SHARED_LIBS</code> determines whether GLFW is built as a static library or as a DLL / shared library / dynamic library.</p>
<p><code>LIB_SUFFIX</code> affects where the GLFW shared /dynamic library is installed. If it is empty, it is installed to <code>${CMAKE_INSTALL_PREFIX}/lib</code>. If it is set to <code>64</code>, it is installed to <code>${CMAKE_INSTALL_PREFIX}/lib64</code>.</p>
<p><code>GLFW_BUILD_EXAMPLES</code> determines whether the GLFW examples are built along with the library.</p>
<p><code>GLFW_BUILD_TESTS</code> determines whether the GLFW test programs are built along with the library.</p>
<p><code>GLFW_BUILD_DOCS</code> determines whether the GLFW documentation is built along with the library.</p>
<p><code>GLFW_VULKAN_STATIC</code> determines whether to use the Vulkan loader linked statically into the application.</p>
<h3><a class="anchor" id="compile_options_osx"></a>
OS X specific CMake options</h3>
<p><code>GLFW_USE_CHDIR</code> determines whether <code>glfwInit</code> changes the current directory of bundled applications to the <code>Contents/Resources</code> directory.</p>
<p><code>GLFW_USE_MENUBAR</code> determines whether the first call to <code>glfwCreateWindow</code> sets up a minimal menu bar.</p>
<p><code>GLFW_USE_RETINA</code> determines whether windows will use the full resolution of Retina displays.</p>
<h3><a class="anchor" id="compile_options_win32"></a>
Windows specific CMake options</h3>
<p><code>USE_MSVC_RUNTIME_LIBRARY_DLL</code> determines whether to use the DLL version or the static library version of the Visual C++ runtime library. If set to <code>ON</code>, the DLL version of the Visual C++ library is used.</p>
<p><code>GLFW_USE_HYBRID_HPG</code> determines whether to export the <code>NvOptimusEnablement</code> and <code>AmdPowerXpressRequestHighPerformance</code> symbols, which force the use of the high-performance GPU on Nvidia Optimus and AMD PowerXpress systems. These symbols need to be exported by the EXE to be detected by the driver, so the override will not work if GLFW is built as a DLL.</p>
<h1><a class="anchor" id="compile_manual"></a>
Compiling GLFW manually</h1>
<p>If you wish to compile GLFW without its CMake build environment then you will have to do at least some of the platform detection yourself. GLFW needs a configuration macro to be defined in order to know what window system it's being compiled for and also has optional, platform-specific ones for various features.</p>
<p>When building with CMake, the <code>glfw_config.h</code> configuration header is generated based on the current platform and CMake options. The GLFW CMake environment defines <code>_GLFW_USE_CONFIG_H</code>, which causes this header to be included by <code>internal.h</code>. Without this macro, GLFW will expect the necessary configuration macros to be defined on the command-line.</p>
<p>The window creation API is used to create windows, handle input, monitors, gamma ramps and clipboard. The options are:</p>
<ul>
<li><code>_GLFW_COCOA</code> to use the Cocoa frameworks</li>
<li><code>_GLFW_WIN32</code> to use the Win32 API</li>
<li><code>_GLFW_X11</code> to use the X Window System</li>
<li><code>_GLFW_WAYLAND</code> to use the Wayland API (experimental and incomplete)</li>
<li><code>_GLFW_MIR</code> to use the Mir API (experimental and incomplete)</li>
</ul>
<p>If you are building GLFW as a shared library / dynamic library / DLL then you must also define <code>_GLFW_BUILD_DLL</code>. Otherwise, you must not define it.</p>
<p>If you are linking the Vulkan loader statically into your application then you must also define <code>_GLFW_VULKAN_STATIC</code>. Otherwise, GLFW will attempt to use the external version.</p>
<p>For the EGL context creation API, the following options are available:</p>
<ul>
<li><code>_GLFW_USE_EGLPLATFORM_H</code> to use <code>EGL/eglplatform.h</code> for native handle definitions (fallback)</li>
</ul>
<p>If you are using the X11 window creation API, support for the following X11 extensions can be enabled:</p>
<ul>
<li><code>_GLFW_HAS_XF86VM</code> to use Xxf86vm as a fallback when RandR gamma is broken (recommended)</li>
</ul>
<p>If you are using the Cocoa window creation API, the following options are available:</p>
<ul>
<li><code>_GLFW_USE_CHDIR</code> to <code>chdir</code> to the <code>Resources</code> subdirectory of the application bundle during <a class="el" href="group__init.html#ga317aac130a235ab08c6db0834907d85e">glfwInit</a> (recommended)</li>
<li><code>_GLFW_USE_MENUBAR</code> to create and populate the menu bar when the first window is created (recommended)</li>
<li><code>_GLFW_USE_RETINA</code> to have windows use the full resolution of Retina displays (recommended)</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>None of the <a class="el" href="build_guide.html#build_macros">GLFW header option macros</a> may be defined during the compilation of GLFW. If you define any of these in your build files, make sure they are not applied to the GLFW sources. </dd></dl>
</div></div><!-- contents -->
<address class="footer">
<p>
Last update on Thu Aug 18 2016 for GLFW 3.2.1
</p>
</address>
</body>
</html>
