shithub: cstory

ref: af837edda43873c1435e3ca1a54034ad7ee11893
dir: /external/glfw/docs/html/compile_guide.html/

View raw version
<!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.16"/>
<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>
<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="https://www.glfw.org/" id="glfwhome">GLFW</a>
		<ul class="glfwnavbar">
			<li><a href="https://www.glfw.org/documentation.html">Documentation</a></li>
			<li><a href="https://www.glfw.org/download.html">Download</a></li>
			<li><a href="https://www.glfw.org/community.html">Community</a></li>
		</ul>
	</div>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.16 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></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="PageDoc"><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 macOS</a></li>
<li class="level3"><a href="#compile_deps_x11">Dependencies for Linux and X11</a></li>
<li class="level3"><a href="#compile_deps_wayland">Dependencies for Linux and Wayland</a></li>
</ul>
</li>
<li class="level2"><a href="#compile_deps_osmesa">Dependencies for Linux and OSMesa</a></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_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="https://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 install its CMake package. If not, you can download installers for Windows and macOS from the <a href="https://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 Windows SDK bundled 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 set up cross-compilation of Windows binaries. To use these files you add an option when running <code>cmake</code> to generate the project files or makefiles:</p>
<div class="fragment"><div class="line">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">cmake -DCMAKE_TOOLCHAIN_FILE=CMake/x86_64-w64-mingw32.cmake .</div>
</div><!-- fragment --><p>For more details see the article <a href="https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/CrossCompiling">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 macOS</h3>
<p>Xcode comes with all necessary tools except for CMake. The required headers and libraries are included in the core macOS 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>
<h3><a class="anchor" id="compile_deps_wayland"></a>
Dependencies for Linux and Wayland</h3>
<p>To compile GLFW for Wayland, you need to have the Wayland 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>libwayland-dev</code> package, which contains all Wayland headers and pulls in wayland-scanner, as well as the <code>wayland-protocols</code> and <code>extra-cmake-modules</code> 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_deps_osmesa"></a>
Dependencies for Linux and OSMesa</h2>
<p>To compile GLFW for OSMesa, you need to install the OSMesa library and header packages. For example, on Ubuntu and other distributions based on Debian GNU/Linux, you need to install the <code>libosmesa6-dev</code> package. The OSMesa library is required at runtime for context creation and is loaded on demand.</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">cd &lt;glfw-root-dir&gt;</div>
<div class="line">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">mkdir glfw-build</div>
<div class="line">cd glfw-build</div>
<div class="line">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">cmake -DBUILD_SHARED_LIBS=ON .</div>
</div><!-- fragment --><h3><a class="anchor" id="compile_options_shared"></a>
Shared CMake options</h3>
<p><a class="anchor" id="BUILD_SHARED_LIBS"></a><b>BUILD_SHARED_LIBS</b> determines whether GLFW is built as a static library or as a DLL / shared library / dynamic library.</p>
<p><a class="anchor" id="GLFW_BUILD_EXAMPLES"></a><b>GLFW_BUILD_EXAMPLES</b> determines whether the GLFW examples are built along with the library.</p>
<p><a class="anchor" id="GLFW_BUILD_TESTS"></a><b>GLFW_BUILD_TESTS</b> determines whether the GLFW test programs are built along with the library.</p>
<p><a class="anchor" id="GLFW_BUILD_DOCS"></a><b>GLFW_BUILD_DOCS</b> determines whether the GLFW documentation is built along with the library.</p>
<p><a class="anchor" id="GLFW_VULKAN_STATIC"></a><b>GLFW_VULKAN_STATIC</b> determines whether to use the Vulkan loader linked directly with the application.</p>
<h3><a class="anchor" id="compile_options_win32"></a>
Windows specific CMake options</h3>
<p><a class="anchor" id="USE_MSVC_RUNTIME_LIBRARY_DLL"></a><b>USE_MSVC_RUNTIME_LIBRARY_DLL</b> 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><a class="anchor" id="GLFW_USE_HYBRID_HPG"></a><b>GLFW_USE_HYBRID_HPG</b> 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 <b>GLFW_USE_CONFIG_H</b>, 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><b>_GLFW_COCOA</b> to use the Cocoa frameworks</li>
<li><b>_GLFW_WIN32</b> to use the Win32 API</li>
<li><b>_GLFW_X11</b> to use the X Window System</li>
<li><b>_GLFW_WAYLAND</b> to use the Wayland API (experimental and incomplete)</li>
<li><b>_GLFW_OSMESA</b> to use the OSMesa API (headless and non-interactive)</li>
</ul>
<p>If you are building GLFW as a shared library / dynamic library / DLL then you must also define <b>_GLFW_BUILD_DLL</b>. Otherwise, you must not define it.</p>
<p>If you are linking the Vulkan loader directly with your application then you must also define <b>_GLFW_VULKAN_STATIC</b>. Otherwise, GLFW will attempt to use the external version.</p>
<p>If you are using a custom name for the Vulkan, EGL, GLX, OSMesa, OpenGL, GLESv1 or GLESv2 library, you can override the default names by defining those you need of <b>_GLFW_VULKAN_LIBRARY</b>, <b>_GLFW_EGL_LIBRARY</b>, <b>_GLFW_GLX_LIBRARY</b>, <b>_GLFW_OSMESA_LIBRARY</b>, <b>_GLFW_OPENGL_LIBRARY</b>, <b>_GLFW_GLESV1_LIBRARY</b> and <b>_GLFW_GLESV2_LIBRARY</b>. Otherwise, GLFW will use the built-in default names.</p>
<p>For the EGL context creation API, the following options are available:</p>
<ul>
<li><b>_GLFW_USE_EGLPLATFORM_H</b> to use an existing <code>EGL/eglplatform.h</code> header file for native handle types (fallback)</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 -->
</div><!-- PageDoc -->
<address class="footer">
<p>
Last update on Mon Jan 20 2020 for GLFW 3.3.2
</p>
</address>
</body>
</html>