2014-10-16 18:12:43 +04:00
|
|
|
*****
|
|
|
|
Usage
|
|
|
|
*****
|
|
|
|
|
2019-01-30 17:07:59 +03:00
|
|
|
To use the {fmt} library, add :file:`fmt/core.h`, :file:`fmt/format.h`,
|
|
|
|
:file:`fmt/format-inl.h`, :file:`src/format.cc` and optionally other headers
|
|
|
|
from a `release archive <https://github.com/fmtlib/fmt/releases/latest>`_ or
|
|
|
|
the `Git repository <https://github.com/fmtlib/fmt>`_ to your project.
|
2014-12-19 18:37:49 +03:00
|
|
|
Alternatively, you can :ref:`build the library with CMake <building>`.
|
2014-10-16 18:12:43 +04:00
|
|
|
|
|
|
|
If you are using Visual C++ with precompiled headers, you might need to add
|
2014-11-05 18:39:34 +03:00
|
|
|
the line ::
|
2014-10-16 18:12:43 +04:00
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
2014-12-19 18:37:49 +03:00
|
|
|
before other includes in :file:`format.cc`.
|
|
|
|
|
|
|
|
.. _building:
|
|
|
|
|
|
|
|
Building the library
|
|
|
|
====================
|
|
|
|
|
2016-04-27 18:35:59 +03:00
|
|
|
The included `CMake build script`__ can be used to build the fmt
|
2014-12-19 18:37:49 +03:00
|
|
|
library on a wide range of platforms. CMake is freely available for
|
|
|
|
download from http://www.cmake.org/download/.
|
|
|
|
|
2016-04-27 18:35:59 +03:00
|
|
|
__ https://github.com/fmtlib/fmt/blob/master/CMakeLists.txt
|
2014-12-19 18:37:49 +03:00
|
|
|
|
|
|
|
CMake works by generating native makefiles or project files that can
|
|
|
|
be used in the compiler environment of your choice. The typical
|
|
|
|
workflow starts with::
|
|
|
|
|
2016-04-27 18:35:59 +03:00
|
|
|
mkdir build # Create a directory to hold the build output.
|
2014-12-19 18:37:49 +03:00
|
|
|
cd build
|
2016-04-27 18:35:59 +03:00
|
|
|
cmake <path/to/fmt> # Generate native build scripts.
|
2014-12-19 18:37:49 +03:00
|
|
|
|
2016-04-27 18:35:59 +03:00
|
|
|
where :file:`{<path/to/fmt>}` is a path to the ``fmt`` repository.
|
2014-12-19 18:37:49 +03:00
|
|
|
|
|
|
|
If you are on a \*nix system, you should now see a Makefile in the
|
2016-04-27 18:35:59 +03:00
|
|
|
current directory. Now you can build the library by running :command:`make`.
|
2014-12-19 18:37:49 +03:00
|
|
|
|
|
|
|
Once the library has been built you can invoke :command:`make test` to run
|
|
|
|
the tests.
|
|
|
|
|
2018-02-10 17:54:26 +03:00
|
|
|
You can control generation of the make ``test`` target with the ``FMT_TEST``
|
|
|
|
CMake option. This can be useful if you include fmt as a subdirectory in
|
|
|
|
your project but don't want to add fmt's tests to your ``test`` target.
|
|
|
|
|
2018-12-14 06:58:32 +03:00
|
|
|
If you use Windows and have Visual Studio installed, a :file:`FMT.sln`
|
2014-12-19 18:37:49 +03:00
|
|
|
file and several :file:`.vcproj` files will be created. You can then build them
|
|
|
|
using Visual Studio or msbuild.
|
|
|
|
|
|
|
|
On Mac OS X with Xcode installed, an :file:`.xcodeproj` file will be generated.
|
|
|
|
|
|
|
|
To build a `shared library`__ set the ``BUILD_SHARED_LIBS`` CMake variable to
|
|
|
|
``TRUE``::
|
|
|
|
|
|
|
|
cmake -DBUILD_SHARED_LIBS=TRUE ...
|
|
|
|
|
|
|
|
__ http://en.wikipedia.org/wiki/Library_%28computing%29#Shared_libraries
|
2015-02-16 18:09:25 +03:00
|
|
|
|
2018-12-29 02:05:42 +03:00
|
|
|
Installing the library
|
|
|
|
====================
|
|
|
|
|
|
|
|
After building the library you can install it on a Unix-like system by running
|
|
|
|
:command:`sudo make install`.
|
|
|
|
|
|
|
|
Usage with CMake
|
|
|
|
================
|
2018-02-02 03:42:53 +03:00
|
|
|
|
|
|
|
You can add the ``fmt`` library directory into your project and include it in
|
|
|
|
your ``CMakeLists.txt`` file::
|
|
|
|
|
|
|
|
add_subdirectory(fmt)
|
|
|
|
|
|
|
|
or
|
2018-05-13 18:04:39 +03:00
|
|
|
|
2018-02-02 03:42:53 +03:00
|
|
|
::
|
|
|
|
|
|
|
|
add_subdirectory(fmt EXCLUDE_FROM_ALL)
|
|
|
|
|
|
|
|
to exclude it from ``make``, ``make all``, or ``cmake --build .``.
|
|
|
|
|
2018-10-27 22:59:51 +03:00
|
|
|
You can detect and use an installed version of {fmt} as follows::
|
|
|
|
|
|
|
|
find_package(fmt)
|
|
|
|
target_link_libraries(<your-target> fmt::fmt)
|
|
|
|
|
|
|
|
Setting up your target to use a header-only version of ``fmt`` is equaly easy::
|
2018-02-02 03:42:53 +03:00
|
|
|
|
|
|
|
target_link_libraries(<your-target> PRIVATE fmt-header-only)
|
|
|
|
|
2015-10-17 18:17:32 +03:00
|
|
|
Building the documentation
|
|
|
|
==========================
|
|
|
|
|
|
|
|
To build the documentation you need the following software installed on your
|
|
|
|
system:
|
|
|
|
|
2015-10-17 18:21:23 +03:00
|
|
|
* `Python <https://www.python.org/>`_ with pip and virtualenv
|
|
|
|
* `Doxygen <http://www.stack.nl/~dimitri/doxygen/>`_
|
2016-06-22 17:01:43 +03:00
|
|
|
* `Less <http://lesscss.org/>`_ with ``less-plugin-clean-css``.
|
|
|
|
Ubuntu doesn't package the ``clean-css`` plugin so you should use ``npm``
|
|
|
|
instead of ``apt`` to install both ``less`` and the plugin::
|
|
|
|
|
|
|
|
sudo npm install -g less less-plugin-clean-css.
|
2015-10-17 18:17:32 +03:00
|
|
|
|
|
|
|
First generate makefiles or project files using CMake as described in
|
2015-10-17 18:34:58 +03:00
|
|
|
the previous section. Then compile the ``doc`` target/project, for example::
|
2015-10-17 18:17:32 +03:00
|
|
|
|
|
|
|
make doc
|
|
|
|
|
2016-05-01 13:29:21 +03:00
|
|
|
This will generate the HTML documentation in ``doc/html``.
|
2015-10-17 18:17:32 +03:00
|
|
|
|
2015-02-16 18:09:25 +03:00
|
|
|
Android NDK
|
|
|
|
===========
|
|
|
|
|
2016-04-27 18:35:59 +03:00
|
|
|
fmt provides `Android.mk file`__ that can be used to build the library
|
2015-02-16 18:25:45 +03:00
|
|
|
with `Android NDK <https://developer.android.com/tools/sdk/ndk/index.html>`_.
|
2016-04-27 18:35:59 +03:00
|
|
|
For an example of using fmt with Android NDK, see the
|
|
|
|
`android-ndk-example <https://github.com/fmtlib/android-ndk-example>`_
|
2015-02-16 18:09:25 +03:00
|
|
|
repository.
|
|
|
|
|
2016-04-27 18:35:59 +03:00
|
|
|
__ https://github.com/fmtlib/fmt/blob/master/Android.mk
|
2015-05-08 18:19:15 +03:00
|
|
|
|
|
|
|
Homebrew
|
|
|
|
========
|
|
|
|
|
2016-04-27 18:35:59 +03:00
|
|
|
fmt can be installed on OS X using `Homebrew <http://brew.sh/>`_::
|
2015-05-08 18:19:15 +03:00
|
|
|
|
2016-07-20 01:34:21 +03:00
|
|
|
brew install fmt
|