compile.dox 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*!
  2. @page compile_guide Compiling GLFW
  3. @tableofcontents
  4. This is about compiling the GLFW library itself. For information on how to
  5. build applications that use GLFW, see @ref build_guide.
  6. @section compile_cmake Using CMake
  7. GLFW uses [CMake](http://www.cmake.org/) to generate project files or makefiles
  8. for a particular development environment. If you are on a Unix-like system such
  9. as Linux or FreeBSD or have a package system like Fink, MacPorts, Cygwin or
  10. Homebrew, you can simply install its CMake package. If not, you can download
  11. installers for Windows and macOS from the
  12. [CMake website](http://www.cmake.org/).
  13. @note CMake only generates project files or makefiles. It does not compile the
  14. actual GLFW library. To compile GLFW, first generate these files for your
  15. chosen development environment and then use them to compile the actual GLFW
  16. library.
  17. @subsection compile_deps Dependencies
  18. Once you have installed CMake, make sure that all other dependencies are
  19. available. On some platforms, GLFW needs a few additional packages to be
  20. installed. See the section for your chosen platform and development environment
  21. below.
  22. @subsubsection compile_deps_msvc Dependencies for Visual C++ on Windows
  23. The Microsoft Platform SDK that is installed along with Visual C++ already
  24. contains all the necessary headers, link libraries and tools except for CMake.
  25. Move on to @ref compile_generate.
  26. @subsubsection compile_deps_mingw Dependencies for MinGW or MinGW-w64 on Windows
  27. Both the MinGW and the MinGW-w64 packages already contain all the necessary
  28. headers, link libraries and tools except for CMake. Move on to @ref
  29. compile_generate.
  30. @subsubsection compile_deps_mingw_cross Dependencies for MinGW or MinGW-w64 cross-compilation
  31. Both Cygwin and many Linux distributions have MinGW or MinGW-w64 packages. For
  32. example, Cygwin has the `mingw64-i686-gcc` and `mingw64-x86_64-gcc` packages
  33. for 32- and 64-bit version of MinGW-w64, while Debian GNU/Linux and derivatives
  34. like Ubuntu have the `mingw-w64` package for both.
  35. GLFW has CMake toolchain files in the `CMake/` directory that allow for easy
  36. cross-compilation of Windows binaries. To use these files you need to add a
  37. special parameter when generating the project files or makefiles:
  38. @code{.sh}
  39. cmake -DCMAKE_TOOLCHAIN_FILE=<toolchain-file> .
  40. @endcode
  41. The exact toolchain file to use depends on the prefix used by the MinGW or
  42. MinGW-w64 binaries on your system. You can usually see this in the /usr
  43. directory. For example, both the Debian/Ubuntu and Cygwin MinGW-w64 packages
  44. have `/usr/x86_64-w64-mingw32` for the 64-bit compilers, so the correct
  45. invocation would be:
  46. @code{.sh}
  47. cmake -DCMAKE_TOOLCHAIN_FILE=CMake/x86_64-w64-mingw32.cmake .
  48. @endcode
  49. For more details see the article
  50. [CMake Cross Compiling](http://www.paraview.org/Wiki/CMake_Cross_Compiling) on
  51. the CMake wiki.
  52. Once you have this set up, move on to @ref compile_generate.
  53. @subsubsection compile_deps_xcode Dependencies for Xcode on macOS
  54. Xcode comes with all necessary tools except for CMake. The required headers
  55. and libraries are included in the core macOS frameworks. Xcode can be
  56. downloaded from the Mac App Store or from the ADC Member Center.
  57. Once you have Xcode installed, move on to @ref compile_generate.
  58. @subsubsection compile_deps_x11 Dependencies for Linux and X11
  59. To compile GLFW for X11, you need to have the X11 packages installed, as well as
  60. the basic development tools like GCC and make. For example, on Ubuntu and other
  61. distributions based on Debian GNU/Linux, you need to install the `xorg-dev`
  62. package, which pulls in all X.org header packages.
  63. Once you have installed the necessary packages, move on to @ref
  64. compile_generate.
  65. @subsection compile_deps_osmesa Dependencies for Linux and OSMesa
  66. To compile GLFW for OSMesa, you need to install the OSMesa library and header
  67. packages. For example, on Ubuntu and other distributions based on Debian
  68. GNU/Linux, you need to install the `libosmesa6-dev` package. The OSMesa library
  69. is required at runtime for context creation and is loaded on demand.
  70. Once you have installed the necessary packages, move on to @ref
  71. compile_generate.
  72. @subsection compile_generate Generating build files with CMake
  73. Once you have all necessary dependencies it is time to generate the project
  74. files or makefiles for your development environment. CMake needs to know two
  75. paths for this: the path to the _root_ directory of the GLFW source tree (i.e.
  76. _not_ the `src` subdirectory) and the target path for the generated files and
  77. compiled binaries. If these are the same, it is called an in-tree build,
  78. otherwise it is called an out-of-tree build.
  79. One of several advantages of out-of-tree builds is that you can generate files
  80. and compile for different development environments using a single source tree.
  81. @note This section is about generating the project files or makefiles necessary
  82. to compile the GLFW library, not about compiling the actual library.
  83. @subsubsection compile_generate_cli Generating files with the CMake command-line tool
  84. To make an in-tree build, enter the _root_ directory of the GLFW source tree
  85. (i.e. _not_ the `src` subdirectory) and run CMake. The current directory is
  86. used as target path, while the path provided as an argument is used to find the
  87. source tree.
  88. @code{.sh}
  89. cd <glfw-root-dir>
  90. cmake .
  91. @endcode
  92. To make an out-of-tree build, make a directory outside of the source tree, enter
  93. it and run CMake with the (relative or absolute) path to the root of the source
  94. tree as an argument.
  95. @code{.sh}
  96. mkdir glfw-build
  97. cd glfw-build
  98. cmake <glfw-root-dir>
  99. @endcode
  100. Once you have generated the project files or makefiles for your chosen
  101. development environment, move on to @ref compile_compile.
  102. @subsubsection compile_generate_gui Generating files with the CMake GUI
  103. If you are using the GUI version, choose the root of the GLFW source tree as
  104. source location and the same directory or another, empty directory as the
  105. destination for binaries. Choose _Configure_, change any options you wish to,
  106. _Configure_ again to let the changes take effect and then _Generate_.
  107. Once you have generated the project files or makefiles for your chosen
  108. development environment, move on to @ref compile_compile.
  109. @subsection compile_compile Compiling the library
  110. You should now have all required dependencies and the project files or makefiles
  111. necessary to compile GLFW. Go ahead and compile the actual GLFW library with
  112. these files, as you would with any other project.
  113. Once the GLFW library is compiled, you are ready to build your applications,
  114. linking it to the GLFW library. See @ref build_guide for more information.
  115. @subsection compile_options CMake options
  116. The CMake files for GLFW provide a number of options, although not all are
  117. available on all supported platforms. Some of these are de facto standards
  118. among projects using CMake and so have no `GLFW_` prefix.
  119. If you are using the GUI version of CMake, these are listed and can be changed
  120. from there. If you are using the command-line version of CMake you can use the
  121. `ccmake` ncurses GUI to set options. Some package systems like Ubuntu and other
  122. distributions based on Debian GNU/Linux have this tool in a separate
  123. `cmake-curses-gui` package.
  124. Finally, if you don't want to use any GUI, you can set options from the `cmake`
  125. command-line with the `-D` flag.
  126. @code{.sh}
  127. cmake -DBUILD_SHARED_LIBS=ON .
  128. @endcode
  129. @subsubsection compile_options_shared Shared CMake options
  130. @anchor BUILD_SHARED_LIBS
  131. __BUILD_SHARED_LIBS__ determines whether GLFW is built as a static
  132. library or as a DLL / shared library / dynamic library.
  133. @anchor LIB_SUFFIX
  134. __LIB_SUFFIX__ affects where the GLFW shared /dynamic library is installed. If
  135. it is empty, it is installed to `${CMAKE_INSTALL_PREFIX}/lib`. If it is set to
  136. `64`, it is installed to `${CMAKE_INSTALL_PREFIX}/lib64`.
  137. @anchor GLFW_BUILD_EXAMPLES
  138. __GLFW_BUILD_EXAMPLES__ determines whether the GLFW examples are built
  139. along with the library.
  140. @anchor GLFW_BUILD_TESTS
  141. __GLFW_BUILD_TESTS__ determines whether the GLFW test programs are
  142. built along with the library.
  143. @anchor GLFW_BUILD_DOCS
  144. __GLFW_BUILD_DOCS__ determines whether the GLFW documentation is built along
  145. with the library.
  146. @anchor GLFW_VULKAN_STATIC
  147. __GLFW_VULKAN_STATIC__ determines whether to use the Vulkan loader linked
  148. statically into the application.
  149. @subsubsection compile_options_win32 Windows specific CMake options
  150. @anchor USE_MSVC_RUNTIME_LIBRARY_DLL
  151. __USE_MSVC_RUNTIME_LIBRARY_DLL__ determines whether to use the DLL version or the
  152. static library version of the Visual C++ runtime library. If set to `ON`, the
  153. DLL version of the Visual C++ library is used.
  154. @anchor GLFW_USE_HYBRID_HPG
  155. __GLFW_USE_HYBRID_HPG__ determines whether to export the `NvOptimusEnablement` and
  156. `AmdPowerXpressRequestHighPerformance` symbols, which force the use of the
  157. high-performance GPU on Nvidia Optimus and AMD PowerXpress systems. These symbols
  158. need to be exported by the EXE to be detected by the driver, so the override
  159. will not work if GLFW is built as a DLL.
  160. @section compile_manual Compiling GLFW manually
  161. If you wish to compile GLFW without its CMake build environment then you will
  162. have to do at least some of the platform detection yourself. GLFW needs
  163. a configuration macro to be defined in order to know what window system it's
  164. being compiled for and also has optional, platform-specific ones for various
  165. features.
  166. When building with CMake, the `glfw_config.h` configuration header is generated
  167. based on the current platform and CMake options. The GLFW CMake environment
  168. defines @b GLFW_USE_CONFIG_H, which causes this header to be included by
  169. `internal.h`. Without this macro, GLFW will expect the necessary configuration
  170. macros to be defined on the command-line.
  171. The window creation API is used to create windows, handle input, monitors, gamma
  172. ramps and clipboard. The options are:
  173. - @b _GLFW_COCOA to use the Cocoa frameworks
  174. - @b _GLFW_WIN32 to use the Win32 API
  175. - @b _GLFW_X11 to use the X Window System
  176. - @b _GLFW_WAYLAND to use the Wayland API (experimental and incomplete)
  177. - @b _GLFW_MIR to use the Mir API (experimental and incomplete)
  178. - @b _GLFW_OSMESA to use the OSMesa API (headless and non-interactive)
  179. If you are building GLFW as a shared library / dynamic library / DLL then you
  180. must also define @b _GLFW_BUILD_DLL. Otherwise, you must not define it.
  181. If you are linking the Vulkan loader statically into your application then you
  182. must also define @b _GLFW_VULKAN_STATIC. Otherwise, GLFW will attempt to use the
  183. external version.
  184. For the EGL context creation API, the following options are available:
  185. - @b _GLFW_USE_EGLPLATFORM_H to use `EGL/eglplatform.h` for native handle
  186. definitions (fallback)
  187. @note None of the @ref build_macros may be defined during the compilation of
  188. GLFW. If you define any of these in your build files, make sure they are not
  189. applied to the GLFW sources.
  190. */