Skip to content

Commit

Permalink
[Core] Add fmtlib dependency
Browse files Browse the repository at this point in the history
Closes #1070. fmtlib allows for easy, safe string substitution in C++,
adding advanced formatting functionality (e.g. rounding), and reducing
bloat.

So add as a new private build-only header-only dependency.

Using header-only increases compile times, but subjectively it's not
noticeable, and has the benefit of avoiding a possible public library
dependency (if OpenAssetIO is built as a static library).

Tweak a single existing, tested, log string to make use of libfmt, to
ensure basic usage is validated.

Signed-off-by: David Feltell <david.feltell@foundry.com>
  • Loading branch information
feltech committed Sep 5, 2023
1 parent a592005 commit a39eb06
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
8 changes: 8 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Release Notes
=============

v1.0.0-alpha.x
---------------

### Breaking changes

- Added `fmtlib` as a new header-only private dependency.
[#1070](https://github.com/OpenAssetIO/OpenAssetIO/issues/1070)

v1.0.0-alpha.14
---------------

Expand Down
7 changes: 7 additions & 0 deletions cmake/ThirdParty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

find_package(tomlplusplus REQUIRED)


#-----------------------------------------------------------------------
# String formatting

find_package(fmt REQUIRED)


#-----------------------------------------------------------------------
# Python

Expand Down
4 changes: 4 additions & 0 deletions resources/build/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ def requirements(self):
self.requires("catch2/2.13.8")
# Mocking library
self.requires("trompeloeil/42")
self.requires("fmt/10.1.1")

def configure(self):
self.options["fmt"].header_only = True
8 changes: 6 additions & 2 deletions src/openassetio-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ target_include_directories(openassetio-core
# Use includes from install tree for installed lib.
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")

target_link_libraries(openassetio-core
target_link_libraries(
openassetio-core
PRIVATE
$<BUILD_INTERFACE:tomlplusplus::tomlplusplus>)
# Header-only private dependencies:
$<BUILD_INTERFACE:tomlplusplus::tomlplusplus>
$<BUILD_INTERFACE:fmt::fmt-header-only>
)

#-----------------------------------------------------------------------
# API export header
Expand Down
13 changes: 7 additions & 6 deletions src/openassetio-core/src/hostApi/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <stdexcept>
#include <utility>

#include <fmt/format.h>

#include <openassetio/Context.hpp>
#include <openassetio/TraitsData.hpp>
#include <openassetio/constants.hpp>
Expand Down Expand Up @@ -53,12 +55,11 @@ std::optional<Str> entityReferencePrefixFromInfo(const log::LoggerInterfacePtr &
if (auto iter = info.find(Str{constants::kInfoKey_EntityReferencesMatchPrefix});
iter != info.end()) {
if (const auto *prefixPtr = std::get_if<openassetio::Str>(&iter->second)) {
std::string msg = "Entity reference prefix '";
msg += *prefixPtr;
msg +=
"' provided by manager's info() dict. Subsequent calls to isEntityReferenceString will"
" use this prefix rather than call the manager's implementation.";
logger->debugApi(msg);
logger->debugApi(
fmt::format("Entity reference prefix '{}' provided by manager's info() dict. Subsequent"
" calls to isEntityReferenceString will use this prefix rather than call the"
" manager's implementation.",
*prefixPtr));

return *prefixPtr;
}
Expand Down

0 comments on commit a39eb06

Please sign in to comment.