build.rst 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. Building
  2. ========
  3. Dependencies & Getting the source
  4. ---------------------------------
  5. - https://github.com/bkaradzic/bx
  6. - https://github.com/bkaradzic/bimg
  7. The directories for `bx`, `bimg`, and `bgfx` should all be siblings of each other.
  8. So clone the repositories next to each other:
  9. ::
  10. git clone https://github.com/bkaradzic/bx.git
  11. git clone https://github.com/bkaradzic/bimg.git
  12. git clone https://github.com/bkaradzic/bgfx.git
  13. Quick Start for Windows
  14. -----------------------
  15. These are step for users who use Windows with Visual Studio.
  16. Enter bgfx directory:
  17. ::
  18. cd bgfx
  19. Generate Visual Studio 2019 project files:
  20. ::
  21. ..\bx\tools\bin\windows\genie --with-examples vs2022
  22. Open bgfx solution in Visual Studio 2019:
  23. ::
  24. start .build\projects\vs2022\bgfx.sln
  25. .. note:: For more detailed prerequisites and build steps on other platforms see below.
  26. Prerequisites
  27. -------------
  28. Android
  29. ~~~~~~~
  30. Download Android NDK (r23 or newer):
  31. - https://developer.android.com/tools/sdk/ndk/index.html
  32. Set following environment variables:
  33. ::
  34. setx ANDROID_NDK_ROOT <path to AndroidNDK directory>
  35. Linux
  36. ~~~~~
  37. ::
  38. sudo apt-get install libgl1-mesa-dev x11proto-core-dev libx11-dev
  39. Windows
  40. ~~~~~~~
  41. Windows users download GnuWin32 utilities:
  42. - http://gnuwin32.sourceforge.net/packages/make.htm
  43. - http://gnuwin32.sourceforge.net/packages/coreutils.htm
  44. - http://gnuwin32.sourceforge.net/packages/libiconv.htm
  45. - http://gnuwin32.sourceforge.net/packages/libintl.htm
  46. .. note:: **MSYS**, **Cygwin**, etc. shells are not supported!
  47. You must use use **cmd.exe** with provided makefiles.
  48. Build
  49. -----
  50. bgfx uses `GENie - Project generator tool <https://github.com/bkaradzic/genie#genie---project-generator-tool>`__
  51. to generate project files for various platforms. Binaries of GENie for Linux, macOS, and Windows are included in
  52. the bx repository. GENie can generate a useful list of options relevant to the project using the
  53. ``--help`` flag. Most platform-specific examples below do not explicitly use the ``genie`` executable, but a convenience
  54. makefile instead. For more control, you can directly use ``genie`` to generate the project files.
  55. General (Makefile wrapper)
  56. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  57. ::
  58. cd bgfx
  59. make
  60. After calling ``make``, some directories in ``.build/projects/\*`` will be generated.
  61. All intermediate files, libraries and executables generated by the compiler will be inside this
  62. ``.build`` directory structure. Deleting ``.build`` directory at any time is safe.
  63. ::
  64. make <configuration>
  65. Configuration is ``<platform>-<debug/release>[32/64]``. For example:
  66. ::
  67. linux-release64, wasm-debug, wasm-release, osx-debug, osx-release, android-arm64-release, etc.
  68. General (Directly with GENie)
  69. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  70. Inspect the available options by invoking GENie with the ``--help`` option (where ``<platform>`` is ``linux``, ``windows``, or ``darwin``):
  71. ::
  72. ../bx/tools/bin/<platform>/genie --help
  73. Select the options you want, such as:
  74. - ``--with-tools``
  75. - ``--with-amalgamated`` (see below)
  76. - ``--with-shared-lib``
  77. - ``--with-profiler`` (see https://bkaradzic.github.io/bgfx/bgfx.html#_CPPv4N4bgfx9CallbackIE)
  78. - ``--with-examples`` (see https://bkaradzic.github.io/bgfx/examples.html)
  79. - ``--with-sdl`` to use SDL2 for the examples.
  80. - ``--with-glfw`` to use GLFW3 for the examples.
  81. There are also many platform-specific options.
  82. .. note::
  83. If you wish to use the OpenGL backend, specifying a minimum API version is possible through setting
  84. the ``BGFX_CONFIG`` environment variable when running ``genie``. For example:
  85. ::
  86. # Unix:
  87. export BGFX_CONFIG=RENDERER_OPENGL_MIN_VERSION=40
  88. # Windows:
  89. set BGFX_CONFIG=RENDERER_OPENGL_MIN_VERSION=40
  90. ../bx/tools/bin/<platform>/genie <... your options ...>
  91. The same can be done for OpenGL ES.
  92. Then generate your project files with the options.
  93. Your project folder is in ``.build/projects/``.
  94. For more help on specific platforms, see below and read the ``makefile`` in the bgfx repository) for examples on how to use GENie.
  95. For gmake projects, specify compile using:
  96. ::
  97. make config=<config> -C .build/projects/<platform>-gmake
  98. Where ``<config>`` is something like ``release64``, ``debug64`` (or equivalent 32 bit), and
  99. ``<platform>`` is the platform you chose.
  100. Windows
  101. ~~~~~~~
  102. Visual Studio 2019 command line:
  103. ::
  104. make vs2022-release64
  105. Visual Studio 2019 IDE:
  106. ::
  107. start .build/projects/vs2022/bgfx.sln
  108. macOS
  109. ~~~~~
  110. There are two options when working on macOS: Xcode command-line builds, or within the XCode graphical development environment.
  111. For the Xcode command line:
  112. ::
  113. make osx-release
  114. cd examples/runtime
  115. ../../.build/osx64_clang/bin/examples.app/Contents/MacOS/examplesRelease
  116. Or for Xcode IDE:
  117. ::
  118. ../bx/tools/bin/darwin/genie --with-combined-examples --xcode=osx xcode9
  119. open .build/projects/xcode9-osx/bgfx.xcworkspace
  120. Due to the `inability <https://github.com/bkaradzic/genie/blob/master/docs/scripting-reference.md#debugdirpath>`__
  121. to set working directory for an Xcode project from `GENie <https://github.com/bkaradzic/genie#genie---project-generator-tool>`__
  122. configuration file, it has to be set manually for each example project:
  123. 1. Open *"Edit scheme..."* dialog for a given project.
  124. 2. Select *"Run"* settings.
  125. 3. Check *"Use custom working directory"* and enter following path:
  126. ``${PROJECT_DIR}/../../../examples/runtime``.
  127. Linux
  128. ~~~~~
  129. ::
  130. make linux-release64
  131. For more options, see `General (directly with GENie) <#general-directly-with-genie>`_.
  132. WinRT / UWP
  133. ~~~~~~~~~~~
  134. ::
  135. ..\bx\tools\bin\windows\genie --vs=winstore100 vs2022
  136. For more options, see `General (directly with GENie) <#general-directly-with-genie>`_.
  137. Build the resulting solution and deploy to device.
  138. .. note:: Shaders will need to be compiled with the appropriate target profile for your platform.
  139. Amalgamated Build
  140. -----------------
  141. For ease of integration with other build systems, the bgfx library can be built
  142. with a single .cpp file. It's only necessary to build
  143. `src/amalgamated.cpp <https://github.com/bkaradzic/bgfx/blob/master/src/amalgamated.cpp>`__
  144. (for macOS/iOS/iPadOS/tvOS use
  145. `src/amalgamated.mm <https://github.com/bkaradzic/bgfx/blob/master/src/amalgamated.mm>`__
  146. instead) inside a different build system.
  147. Tools
  148. -----
  149. To build bgfx project files for tools, use ``--with-tools`` option:
  150. ::
  151. ..\bx\tools\bin\windows\genie --with-tools vs2022
  152. Alternative build systems
  153. -------------------------
  154. **CMake**
  155. - https://github.com/bkaradzic/bgfx.cmake
  156. - https://github.com/JoshuaBrookover/bgfx.cmake#bgfxcmake
  157. - https://github.com/pr0g/sdl-bgfx-imgui-starter#sdl-bgfx-imgui-starter
  158. - https://github.com/yuki-koyama/hello-bgfx
  159. - https://github.com/ataulien/bgfx-cmake
  160. **fips** is a high-level build system wrapper written in Python for C/C++ projects.
  161. https://github.com/floooh/fips#fips
  162. **Conan** package
  163. https://github.com/firefalcom/bgfx-conan
  164. Minimal example without bgfx's example harness
  165. ----------------------------------------------
  166. This project demonstrates minimal amount of code needed to integrate bgfx with GLFW, but without
  167. any of existing bgfx example harness. It also demonstrates how to build bgfx with alternative build
  168. system.
  169. https://github.com/jpcy/bgfx-minimal-example