rigtorp /
awesome-modern-cpp
A collection of resources on modern C++
85/100 healthLoading repository data…
puppetlabs / repository
A collection of C++ and CMake utility libraries.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
This repository is archived and Perforce will no longer be updating this repository. For more information, see this Puppet blog post.
Table of Contents generated with DocToc
Leatherman can be used in one of two ways: It can be installed as a
regular library, and included using the normal CMake find_package
syntax, or it can be setup as a submodule. The recommended method is
to install Leatherman and use it as a regular system library.
Leatherman is broken up into a number of focused component libraries. Both methods of using Leatherman allow you to control which components are built and used.
Library install locations can be controlled using the LIB_SUFFIX
variable, which results in installing libraries to lib${LIB_SUFFIX}.
The recommended way to use Leatherman is as a library built and installed on your system.
Leatherman is built like any other cmake project:
mkdir build
cd build
cmake ..
make
sudo make install
By default, all of the component libraries are built when Leatherman
is used standalone. To disable a component, you can set
LEATHERMAN_ENABLE_<LIBRARY> to any of CMake's falsy values.
Leatherman's make install deploys a standard CMake config file to
lib/cmake/leatherman. This allows the normal CMake find_package
workflow to be used.
find_package(Leatherman COMPONENTS foo bar baz REQUIRED)
If Leatherman is not installed to a standard system prefix, or on
Windows where there is no standard prefix, you can set
CMAKE_PREFIX_PATH to the location of Leatherman's install.
Leatherman can be included as a git submodule and added as a CMake subdirectory. Consider the following:
CMakeLists.txt
lib/
CMakeLists.txt
vendor/
leatherman/
In this setup, your CMakeLists.txt would need to contain the following:
...
add_subdirectory(vendor/leatherman)
...
To enable individual Leatherman components, you must set
LEATHERMAN_ENABLE_<LIBRARY>. Any libraries not explicitly enabled
will not be built or available to the containing project.
...
set(LEATHERMAN_ENABLE_LOCALE TRUE)
add_subdirectory(vendor/leatherman)
...
Leatherman sets two top-level CMake variables:
LEATHERMAN_INCLUDE_DIRS The include paths of all enabled
leatherman librariesLEATHERMAN_LIBRARIES The library names of all enabled leatherman
libraries, as well as their dependencies.In addition, each enabled library sets a number of library-specific variables:
LEATHERMAN_<LIBRARY>_INCLUDE The include directory or directories
for the given leatherman library.LEATHERMAN_<LIBRARY>_LIB The library name as used by CMake. In the
case of header-only leatherman libraries, this will be set to the
empty string.LEATHERMAN_<LIBRARY>_DEPS Any dependency libraries needed by the
given library. This could include other leatherman libraries or
3rd-party libraries found via CMake.LEATHERMAN_<LIBRARY>_LIBS The contents of both
LEATHERMAN_<LIBRARY>_LIB and LEATHERMAN_<LIBRARY>_DEPSIn addition to the C++ library components, Leatherman provides a few
CMake helpers. These will be automatically added to your
CMAKE_MODULE_PATH when find_package is processed.
options: Common CMake options for leatherman features. Should
almost always be used.
cflags: Sets a LEATHERMAN_CXX_FLAGS variable containing the
Puppet Labs standard CXXFLAGS for your compiler and platform.
leatherman: Additional functionality provided by Leatherman for
consumers. Includes:
cpplint and cppcheck configurationpod2man: Adds a pod2man macro to generate man files from source.
Leatherman and its components provide support for generating and using
gettext-based message catalogs.
Two helpers are provided for generating message catalogs:
gettext_templates <dir> <sources>: creates a ${PROJECT_NAME}.pot
target (used by all) that (re)generates the .pot file from specified
source files. If the project is configured with LEATHERMAN_LOCALES
containing a list of language codes, it will add a target
${PROJECT_NAME}-${LANG}.po to create or update translation (.po)
files matching those codes. Files are put in dir. To avoid make clean deleting these files, look at how the locales directory is
structured.gettext_compile <dir> <inst>: creates a translation target (also
used by all) to generate the binary message catalogs (.mo files) and
configure installing them to the specified install location (inst).LEATHERMAN_LOCALES expects a quoted semi-colon separated list, as
in LEATHERMAN_LOCALES="en;fr;ja".
Normal use of cmake/make should ensure the translation files are up-to-
date. Translations can be tested by setting the LC_CTYPE environment
variable.
By default i18n support is disabled. To enable it, define LEATHERMAN_I18N
when compiling your project. To do so, add these two lines to your projects
CMakeLists.txt file below where you have find_package(LEATHERMAN ...) and
also below where you do include(cflags).
add_definitions(${LEATHERMAN_DEFINITIONS})
add_definitions(-DLEATHERMAN_I18N)
By default locale files are installed to ${CMAKE_INSTALL_PREFIX}/share/locale.
This behavior can be changed to use environment variables for the prefix
instead by defining LEATHERMAN_LOCALE_VAR and LEATHERMAN_LOCALE_INSTALL.
LEATHERMAN_LOCALE_VAR should refer to an environment variable pointing to the
root of the Leatherman install, while LEATHERMAN_LOCALE_INSTALL should contain
a path relative to that location, where locale files should be installed and searched
for at run time.
For example, if Leatherman is installed to C:/tools, and you would like
to install translation files to C:/languages/leatherman, you can create an environment
variable (e.g. $LEATHERMAN_LOCATION) containing C:\tools, then set
LEATHERMAN_LOCALE_VAR=LEATHERMAN_LOCATION and
LEATHERMAN_LOCALE_INSTALL=../languages/leatherman. Then locale files will be installed to
C:/tools/../languages/leatherman and at runtime Leatherman will search for locale
files there.
To ensure that consuming projects also install their locale files to the right location,
it is recommended to set LEATHERMAN_LOCALE_INSTALL for all projects attempting to use
Leatherman's i18n tooling.
The format strings in logging (the first argument) will automatically be extracted for the translation template file and translated. Substitution arguments will not, and must be explicitly translated.
To translate strings outside of logging, use the leatherman::locale::translate
and leatherman::locale::format helpers. Strings passed to the helpers will be
extracted to .po files. There are several versions of these helpers:
translate, format) for most standard translations.translate("Apple");
translate_n, format_n) when translation depends on number of items.// Note the parameter duplication: The first count value `2` selects the appropriate
// translated message, and the second `2` fills in the `{1}` substitution token.
format_n("{1} Apple", "{1} Apples", 2, 2);
translate_p, format_p) when a word or phrase has multiple meanings.translate_p("Fruit", "Apple")
translate_np, format_np)format_np("Fruit", "{1} Apple", "{1} Apples", 3, 3);
leatherman::locale::format is a replacement for
boost::locale::format,
which adds locale-aware formatting to boost::format, but requires
different substitution tokens. To support transparently enabling
LEATHERMAN_I18N for only some platforms in a project,
leatherman::locale::format falls-back to using boost::format, and
will convert substitution tokens using the regex {(\d+)} to %\1%.
To be safe, assume both formats are special when using format, and
use {N} in as the substitution token for your strings. If you need to
support both modes and use advanced substitution strings, you'll have
to use an #ifdef LEATHERMAN_I18N block to use the correct string.
To use leatherman::locale::translate or leatherman::locale::format
in your project, add an include to the top of your cpp file:
#include <leatherman/locale/locale.hpp>
Next, if you would like to use any of the functions, you could do so by following this example:
std::cout << leatherman::locale::translate("This is translated") << std::endl;
std::cout << leatherman::locale::format("This is {1} translated message", 1) << std::endl;
Leatherman also provides format helpers with short names: (), n(), p_(), np_(). These reduce code disruption when adding i18n support, and naming is consistent with macros from other i18n libraries.
using namespace leatherman::locale;
std::cout << _("This is translated") << std::endl;
std::cout << _("This is {1} translated message", 1) << std::endl;
Note that on Windows when building Leatherman.Locale as a DLL and Boost.Locale statically, you can get some weird behavior from Boost.Locale. Avoid using it directly, and ensure all translation operations happen as part of the Leatherman.Locale DLL memory space (i.e. in source files).
Translation isn't supported on AIX or Solaris, as GCC on those platforms
doesn't support std::locale. In fact std::locale is buggy, so avoid
using get_locale as well. The CMake option LEATHERMAN_USE_LOCALES
can be used to enable or disable building with Boost.Locale and using
std::locale.
If output strings are not being translated, gettext's FAQ has some suggestions for debugging.
(maint) Add debugging i18n to README
Each .cc file that uses logging (or includes a header which uses
logging) needs to know its logging name
Selected from shared topics, language and repository description—not editorial ratings.
rigtorp /
A collection of resources on modern C++
85/100 healthfacebook /
A collection of C++ HTTP libraries including an easy to use HTTP server.
78/100 healthNJHu /
iOS project comprising a collection of demos for iOS Apps, developed in Objective-C;iOSProject iOSdemo iOSdemos ocdemo ocdemos
shaojiankui /
JKCategories(iOS-Categories,Category), a collection of useful Objective-C Categories extending iOS Frameworks such as Foundation,UIKit,CoreData,QuartzCore,CoreLocation,MapKit Etc.
90/100 healthsrdja /
A library of generic data structures for the C language.
92/100 healthFlangvik /
Nightly builds of common C# offensive tools, fresh from their respective master branches built and released in a CDI fashion using Azure DevOps release pipelines.
76/100 health