git repos / blockattack-game

blame: source/misc/embedded_libs/fmt-11.0.2/doc/get-started.md

normal view · raw

47fd5c32 Poul Sander 2024-10-05 08:44 1
# Get Started
47fd5c32 Poul Sander 2024-10-05 08:44 2
47fd5c32 Poul Sander 2024-10-05 08:44 3
Compile and run {fmt} examples online with [Compiler Explorer](
47fd5c32 Poul Sander 2024-10-05 08:44 4
https://godbolt.org/z/P7h6cd6o3).
47fd5c32 Poul Sander 2024-10-05 08:44 5
47fd5c32 Poul Sander 2024-10-05 08:44 6
{fmt} is compatible with any build system. The next section describes its usage
47fd5c32 Poul Sander 2024-10-05 08:44 7
with CMake, while the [Build Systems](#build-systems) section covers the rest.
47fd5c32 Poul Sander 2024-10-05 08:44 8
47fd5c32 Poul Sander 2024-10-05 08:44 9
## CMake
47fd5c32 Poul Sander 2024-10-05 08:44 10
47fd5c32 Poul Sander 2024-10-05 08:44 11
{fmt} provides two CMake targets: `fmt::fmt` for the compiled library and
47fd5c32 Poul Sander 2024-10-05 08:44 12
`fmt::fmt-header-only` for the header-only library. It is recommended to use
47fd5c32 Poul Sander 2024-10-05 08:44 13
the compiled library for improved build times.
47fd5c32 Poul Sander 2024-10-05 08:44 14
47fd5c32 Poul Sander 2024-10-05 08:44 15
There are three primary ways to use {fmt} with CMake:
47fd5c32 Poul Sander 2024-10-05 08:44 16
47fd5c32 Poul Sander 2024-10-05 08:44 17
* **FetchContent**: Starting from CMake 3.11, you can use [`FetchContent`](
47fd5c32 Poul Sander 2024-10-05 08:44 18
  https://cmake.org/cmake/help/v3.30/module/FetchContent.html) to automatically
47fd5c32 Poul Sander 2024-10-05 08:44 19
  download {fmt} as a dependency at configure time:
47fd5c32 Poul Sander 2024-10-05 08:44 20
47fd5c32 Poul Sander 2024-10-05 08:44 21
        include(FetchContent)
47fd5c32 Poul Sander 2024-10-05 08:44 22
47fd5c32 Poul Sander 2024-10-05 08:44 23
        FetchContent_Declare(
47fd5c32 Poul Sander 2024-10-05 08:44 24
          fmt
47fd5c32 Poul Sander 2024-10-05 08:44 25
          GIT_REPOSITORY https://github.com/fmtlib/fmt
47fd5c32 Poul Sander 2024-10-05 08:44 26
          GIT_TAG        e69e5f977d458f2650bb346dadf2ad30c5320281) # 10.2.1
47fd5c32 Poul Sander 2024-10-05 08:44 27
        FetchContent_MakeAvailable(fmt)
47fd5c32 Poul Sander 2024-10-05 08:44 28
47fd5c32 Poul Sander 2024-10-05 08:44 29
        target_link_libraries(<your-target> fmt::fmt)
47fd5c32 Poul Sander 2024-10-05 08:44 30
47fd5c32 Poul Sander 2024-10-05 08:44 31
* **Installed**: You can find and use an [installed](#installation) version of
47fd5c32 Poul Sander 2024-10-05 08:44 32
  {fmt} in your `CMakeLists.txt` file as follows:
47fd5c32 Poul Sander 2024-10-05 08:44 33
47fd5c32 Poul Sander 2024-10-05 08:44 34
        find_package(fmt)
47fd5c32 Poul Sander 2024-10-05 08:44 35
        target_link_libraries(<your-target> fmt::fmt)
47fd5c32 Poul Sander 2024-10-05 08:44 36
47fd5c32 Poul Sander 2024-10-05 08:44 37
* **Embedded**: You can add the {fmt} source tree to your project and include it
47fd5c32 Poul Sander 2024-10-05 08:44 38
  in your `CMakeLists.txt` file:
47fd5c32 Poul Sander 2024-10-05 08:44 39
47fd5c32 Poul Sander 2024-10-05 08:44 40
        add_subdirectory(fmt)
47fd5c32 Poul Sander 2024-10-05 08:44 41
        target_link_libraries(<your-target> fmt::fmt)
47fd5c32 Poul Sander 2024-10-05 08:44 42
47fd5c32 Poul Sander 2024-10-05 08:44 43
## Installation
47fd5c32 Poul Sander 2024-10-05 08:44 44
47fd5c32 Poul Sander 2024-10-05 08:44 45
### Debian/Ubuntu
47fd5c32 Poul Sander 2024-10-05 08:44 46
47fd5c32 Poul Sander 2024-10-05 08:44 47
To install {fmt} on Debian, Ubuntu, or any other Debian-based Linux
47fd5c32 Poul Sander 2024-10-05 08:44 48
distribution, use the following command:
47fd5c32 Poul Sander 2024-10-05 08:44 49
47fd5c32 Poul Sander 2024-10-05 08:44 50
    apt install libfmt-dev
47fd5c32 Poul Sander 2024-10-05 08:44 51
47fd5c32 Poul Sander 2024-10-05 08:44 52
### Homebrew
47fd5c32 Poul Sander 2024-10-05 08:44 53
47fd5c32 Poul Sander 2024-10-05 08:44 54
Install {fmt} on macOS using [Homebrew](https://brew.sh/):
47fd5c32 Poul Sander 2024-10-05 08:44 55
47fd5c32 Poul Sander 2024-10-05 08:44 56
    brew install fmt
47fd5c32 Poul Sander 2024-10-05 08:44 57
47fd5c32 Poul Sander 2024-10-05 08:44 58
### Conda
47fd5c32 Poul Sander 2024-10-05 08:44 59
47fd5c32 Poul Sander 2024-10-05 08:44 60
Install {fmt} on Linux, macOS, and Windows with [Conda](
47fd5c32 Poul Sander 2024-10-05 08:44 61
https://docs.conda.io/en/latest/), using its [conda-forge package](
47fd5c32 Poul Sander 2024-10-05 08:44 62
https://github.com/conda-forge/fmt-feedstock):
47fd5c32 Poul Sander 2024-10-05 08:44 63
47fd5c32 Poul Sander 2024-10-05 08:44 64
    conda install -c conda-forge fmt
47fd5c32 Poul Sander 2024-10-05 08:44 65
47fd5c32 Poul Sander 2024-10-05 08:44 66
### vcpkg
47fd5c32 Poul Sander 2024-10-05 08:44 67
47fd5c32 Poul Sander 2024-10-05 08:44 68
Download and install {fmt} using the vcpkg package manager:
47fd5c32 Poul Sander 2024-10-05 08:44 69
47fd5c32 Poul Sander 2024-10-05 08:44 70
    git clone https://github.com/Microsoft/vcpkg.git
47fd5c32 Poul Sander 2024-10-05 08:44 71
    cd vcpkg
47fd5c32 Poul Sander 2024-10-05 08:44 72
    ./bootstrap-vcpkg.sh
47fd5c32 Poul Sander 2024-10-05 08:44 73
    ./vcpkg integrate install
47fd5c32 Poul Sander 2024-10-05 08:44 74
    ./vcpkg install fmt
47fd5c32 Poul Sander 2024-10-05 08:44 75
47fd5c32 Poul Sander 2024-10-05 08:44 76
<!-- The fmt package in vcpkg is kept up to date by Microsoft team members and
47fd5c32 Poul Sander 2024-10-05 08:44 77
community contributors. If the version is out of date, please [create an
47fd5c32 Poul Sander 2024-10-05 08:44 78
issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg
47fd5c32 Poul Sander 2024-10-05 08:44 79
repository. -->
47fd5c32 Poul Sander 2024-10-05 08:44 80
47fd5c32 Poul Sander 2024-10-05 08:44 81
## Building from Source
47fd5c32 Poul Sander 2024-10-05 08:44 82
47fd5c32 Poul Sander 2024-10-05 08:44 83
CMake works by generating native makefiles or project files that can be
47fd5c32 Poul Sander 2024-10-05 08:44 84
used in the compiler environment of your choice. The typical workflow
47fd5c32 Poul Sander 2024-10-05 08:44 85
starts with:
47fd5c32 Poul Sander 2024-10-05 08:44 86
47fd5c32 Poul Sander 2024-10-05 08:44 87
    mkdir build  # Create a directory to hold the build output.
47fd5c32 Poul Sander 2024-10-05 08:44 88
    cd build
47fd5c32 Poul Sander 2024-10-05 08:44 89
    cmake ..     # Generate native build scripts.
47fd5c32 Poul Sander 2024-10-05 08:44 90
47fd5c32 Poul Sander 2024-10-05 08:44 91
run in the `fmt` repository.
47fd5c32 Poul Sander 2024-10-05 08:44 92
47fd5c32 Poul Sander 2024-10-05 08:44 93
If you are on a Unix-like system, you should now see a Makefile in the
47fd5c32 Poul Sander 2024-10-05 08:44 94
current directory. Now you can build the library by running `make`.
47fd5c32 Poul Sander 2024-10-05 08:44 95
47fd5c32 Poul Sander 2024-10-05 08:44 96
Once the library has been built you can invoke `make test` to run the tests.
47fd5c32 Poul Sander 2024-10-05 08:44 97
47fd5c32 Poul Sander 2024-10-05 08:44 98
You can control generation of the make `test` target with the `FMT_TEST`
47fd5c32 Poul Sander 2024-10-05 08:44 99
CMake option. This can be useful if you include fmt as a subdirectory in
47fd5c32 Poul Sander 2024-10-05 08:44 100
your project but don't want to add fmt's tests to your `test` target.
47fd5c32 Poul Sander 2024-10-05 08:44 101
47fd5c32 Poul Sander 2024-10-05 08:44 102
To build a shared library set the `BUILD_SHARED_LIBS` CMake variable to `TRUE`:
47fd5c32 Poul Sander 2024-10-05 08:44 103
47fd5c32 Poul Sander 2024-10-05 08:44 104
    cmake -DBUILD_SHARED_LIBS=TRUE ..
47fd5c32 Poul Sander 2024-10-05 08:44 105
47fd5c32 Poul Sander 2024-10-05 08:44 106
To build a static library with position-independent code (e.g. for
47fd5c32 Poul Sander 2024-10-05 08:44 107
linking it into another shared library such as a Python extension), set the
47fd5c32 Poul Sander 2024-10-05 08:44 108
`CMAKE_POSITION_INDEPENDENT_CODE` CMake variable to `TRUE`:
47fd5c32 Poul Sander 2024-10-05 08:44 109
47fd5c32 Poul Sander 2024-10-05 08:44 110
    cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ..
47fd5c32 Poul Sander 2024-10-05 08:44 111
47fd5c32 Poul Sander 2024-10-05 08:44 112
After building the library you can install it on a Unix-like system by
47fd5c32 Poul Sander 2024-10-05 08:44 113
running `sudo make install`.
47fd5c32 Poul Sander 2024-10-05 08:44 114
47fd5c32 Poul Sander 2024-10-05 08:44 115
### Building the Docs
47fd5c32 Poul Sander 2024-10-05 08:44 116
47fd5c32 Poul Sander 2024-10-05 08:44 117
To build the documentation you need the following software installed on
47fd5c32 Poul Sander 2024-10-05 08:44 118
your system:
47fd5c32 Poul Sander 2024-10-05 08:44 119
47fd5c32 Poul Sander 2024-10-05 08:44 120
- [Python](https://www.python.org/)
47fd5c32 Poul Sander 2024-10-05 08:44 121
- [Doxygen](http://www.stack.nl/~dimitri/doxygen/)
47fd5c32 Poul Sander 2024-10-05 08:44 122
- [MkDocs](https://www.mkdocs.org/) with `mkdocs-material`, `mkdocstrings`,
47fd5c32 Poul Sander 2024-10-05 08:44 123
  `pymdown-extensions` and `mike`
47fd5c32 Poul Sander 2024-10-05 08:44 124
47fd5c32 Poul Sander 2024-10-05 08:44 125
First generate makefiles or project files using CMake as described in
47fd5c32 Poul Sander 2024-10-05 08:44 126
the previous section. Then compile the `doc` target/project, for example:
47fd5c32 Poul Sander 2024-10-05 08:44 127
47fd5c32 Poul Sander 2024-10-05 08:44 128
    make doc
47fd5c32 Poul Sander 2024-10-05 08:44 129
47fd5c32 Poul Sander 2024-10-05 08:44 130
This will generate the HTML documentation in `doc/html`.
47fd5c32 Poul Sander 2024-10-05 08:44 131
47fd5c32 Poul Sander 2024-10-05 08:44 132
## Build Systems
47fd5c32 Poul Sander 2024-10-05 08:44 133
47fd5c32 Poul Sander 2024-10-05 08:44 134
### build2
47fd5c32 Poul Sander 2024-10-05 08:44 135
47fd5c32 Poul Sander 2024-10-05 08:44 136
You can use [build2](https://build2.org), a dependency manager and a build
47fd5c32 Poul Sander 2024-10-05 08:44 137
system, to use {fmt}.
47fd5c32 Poul Sander 2024-10-05 08:44 138
47fd5c32 Poul Sander 2024-10-05 08:44 139
Currently this package is available in these package repositories:
47fd5c32 Poul Sander 2024-10-05 08:44 140
47fd5c32 Poul Sander 2024-10-05 08:44 141
- <https://cppget.org/fmt/> for released and published versions.
47fd5c32 Poul Sander 2024-10-05 08:44 142
- <https://github.com/build2-packaging/fmt> for unreleased or custom versions.
47fd5c32 Poul Sander 2024-10-05 08:44 143
47fd5c32 Poul Sander 2024-10-05 08:44 144
**Usage:**
47fd5c32 Poul Sander 2024-10-05 08:44 145
47fd5c32 Poul Sander 2024-10-05 08:44 146
- `build2` package name: `fmt`
47fd5c32 Poul Sander 2024-10-05 08:44 147
- Library target name: `lib{fmt}`
47fd5c32 Poul Sander 2024-10-05 08:44 148
47fd5c32 Poul Sander 2024-10-05 08:44 149
To make your `build2` project depend on `fmt`:
47fd5c32 Poul Sander 2024-10-05 08:44 150
47fd5c32 Poul Sander 2024-10-05 08:44 151
- Add one of the repositories to your configurations, or in your
47fd5c32 Poul Sander 2024-10-05 08:44 152
  `repositories.manifest`, if not already there:
47fd5c32 Poul Sander 2024-10-05 08:44 153
47fd5c32 Poul Sander 2024-10-05 08:44 154
        :
47fd5c32 Poul Sander 2024-10-05 08:44 155
        role: prerequisite
47fd5c32 Poul Sander 2024-10-05 08:44 156
        location: https://pkg.cppget.org/1/stable
47fd5c32 Poul Sander 2024-10-05 08:44 157
47fd5c32 Poul Sander 2024-10-05 08:44 158
- Add this package as a dependency to your `manifest` file (example
47fd5c32 Poul Sander 2024-10-05 08:44 159
  for version 10):
47fd5c32 Poul Sander 2024-10-05 08:44 160
47fd5c32 Poul Sander 2024-10-05 08:44 161
        depends: fmt ~10.0.0
47fd5c32 Poul Sander 2024-10-05 08:44 162
47fd5c32 Poul Sander 2024-10-05 08:44 163
- Import the target and use it as a prerequisite to your own target
47fd5c32 Poul Sander 2024-10-05 08:44 164
  using `fmt` in the appropriate `buildfile`:
47fd5c32 Poul Sander 2024-10-05 08:44 165
47fd5c32 Poul Sander 2024-10-05 08:44 166
        import fmt = fmt%lib{fmt}
47fd5c32 Poul Sander 2024-10-05 08:44 167
        lib{mylib} : cxx{**} ... $fmt
47fd5c32 Poul Sander 2024-10-05 08:44 168
47fd5c32 Poul Sander 2024-10-05 08:44 169
Then build your project as usual with `b` or `bdep update`.
47fd5c32 Poul Sander 2024-10-05 08:44 170
47fd5c32 Poul Sander 2024-10-05 08:44 171
### Meson
47fd5c32 Poul Sander 2024-10-05 08:44 172
47fd5c32 Poul Sander 2024-10-05 08:44 173
[Meson WrapDB](https://mesonbuild.com/Wrapdb-projects.html) includes an `fmt`
47fd5c32 Poul Sander 2024-10-05 08:44 174
package.
47fd5c32 Poul Sander 2024-10-05 08:44 175
47fd5c32 Poul Sander 2024-10-05 08:44 176
**Usage:**
47fd5c32 Poul Sander 2024-10-05 08:44 177
47fd5c32 Poul Sander 2024-10-05 08:44 178
- Install the `fmt` subproject from the WrapDB by running:
47fd5c32 Poul Sander 2024-10-05 08:44 179
47fd5c32 Poul Sander 2024-10-05 08:44 180
        meson wrap install fmt
47fd5c32 Poul Sander 2024-10-05 08:44 181
47fd5c32 Poul Sander 2024-10-05 08:44 182
  from the root of your project.
47fd5c32 Poul Sander 2024-10-05 08:44 183
47fd5c32 Poul Sander 2024-10-05 08:44 184
- In your project's `meson.build` file, add an entry for the new subproject:
47fd5c32 Poul Sander 2024-10-05 08:44 185
47fd5c32 Poul Sander 2024-10-05 08:44 186
        fmt = subproject('fmt')
47fd5c32 Poul Sander 2024-10-05 08:44 187
        fmt_dep = fmt.get_variable('fmt_dep')
47fd5c32 Poul Sander 2024-10-05 08:44 188
47fd5c32 Poul Sander 2024-10-05 08:44 189
- Include the new dependency object to link with fmt:
47fd5c32 Poul Sander 2024-10-05 08:44 190
47fd5c32 Poul Sander 2024-10-05 08:44 191
        my_build_target = executable(
47fd5c32 Poul Sander 2024-10-05 08:44 192
          'name', 'src/main.cc', dependencies: [fmt_dep])
47fd5c32 Poul Sander 2024-10-05 08:44 193
47fd5c32 Poul Sander 2024-10-05 08:44 194
**Options:**
47fd5c32 Poul Sander 2024-10-05 08:44 195
47fd5c32 Poul Sander 2024-10-05 08:44 196
If desired, {fmt} can be built as a static library, or as a header-only library.
47fd5c32 Poul Sander 2024-10-05 08:44 197
47fd5c32 Poul Sander 2024-10-05 08:44 198
For a static build, use the following subproject definition:
47fd5c32 Poul Sander 2024-10-05 08:44 199
47fd5c32 Poul Sander 2024-10-05 08:44 200
    fmt = subproject('fmt', default_options: 'default_library=static')
47fd5c32 Poul Sander 2024-10-05 08:44 201
    fmt_dep = fmt.get_variable('fmt_dep')
47fd5c32 Poul Sander 2024-10-05 08:44 202
47fd5c32 Poul Sander 2024-10-05 08:44 203
For the header-only version, use:
47fd5c32 Poul Sander 2024-10-05 08:44 204
47fd5c32 Poul Sander 2024-10-05 08:44 205
    fmt = subproject('fmt')
47fd5c32 Poul Sander 2024-10-05 08:44 206
    fmt_dep = fmt.get_variable('fmt_header_only_dep')
47fd5c32 Poul Sander 2024-10-05 08:44 207
47fd5c32 Poul Sander 2024-10-05 08:44 208
### Android NDK
47fd5c32 Poul Sander 2024-10-05 08:44 209
47fd5c32 Poul Sander 2024-10-05 08:44 210
{fmt} provides [Android.mk file](
47fd5c32 Poul Sander 2024-10-05 08:44 211
https://github.com/fmtlib/fmt/blob/master/support/Android.mk) that can be used
47fd5c32 Poul Sander 2024-10-05 08:44 212
to build the library with [Android NDK](
47fd5c32 Poul Sander 2024-10-05 08:44 213
https://developer.android.com/tools/sdk/ndk/index.html).
47fd5c32 Poul Sander 2024-10-05 08:44 214
47fd5c32 Poul Sander 2024-10-05 08:44 215
### Other
47fd5c32 Poul Sander 2024-10-05 08:44 216
47fd5c32 Poul Sander 2024-10-05 08:44 217
To use the {fmt} library with any other build system, add
47fd5c32 Poul Sander 2024-10-05 08:44 218
`include/fmt/base.h`, `include/fmt/format.h`, `include/fmt/format-inl.h`,
47fd5c32 Poul Sander 2024-10-05 08:44 219
`src/format.cc` and optionally other headers from a [release archive](
47fd5c32 Poul Sander 2024-10-05 08:44 220
https://github.com/fmtlib/fmt/releases) or the [git repository](
47fd5c32 Poul Sander 2024-10-05 08:44 221
https://github.com/fmtlib/fmt) to your project, add `include` to include
47fd5c32 Poul Sander 2024-10-05 08:44 222
directories and make sure `src/format.cc` is compiled and linked with your code.
1970-01-01 00:00 223