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