Platformer in OpenGL
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

284 rader
11 KiB

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