From a39eb06554a662dedf14967fc83912cb376959ea Mon Sep 17 00:00:00 2001 From: David Feltell Date: Tue, 5 Sep 2023 14:08:55 +0100 Subject: [PATCH] [Core] Add fmtlib dependency 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 --- RELEASE_NOTES.md | 8 ++++++++ cmake/ThirdParty.cmake | 7 +++++++ resources/build/conanfile.py | 4 ++++ src/openassetio-core/CMakeLists.txt | 8 ++++++-- src/openassetio-core/src/hostApi/Manager.cpp | 13 +++++++------ 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index cc0a36194..b8bfbb85f 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -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 --------------- diff --git a/cmake/ThirdParty.cmake b/cmake/ThirdParty.cmake index b5d4c900b..8714fbc44 100644 --- a/cmake/ThirdParty.cmake +++ b/cmake/ThirdParty.cmake @@ -3,6 +3,13 @@ find_package(tomlplusplus REQUIRED) + +#----------------------------------------------------------------------- +# String formatting + +find_package(fmt REQUIRED) + + #----------------------------------------------------------------------- # Python diff --git a/resources/build/conanfile.py b/resources/build/conanfile.py index 08f48deb5..5348b12d7 100644 --- a/resources/build/conanfile.py +++ b/resources/build/conanfile.py @@ -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 diff --git a/src/openassetio-core/CMakeLists.txt b/src/openassetio-core/CMakeLists.txt index f5e69fc19..65a0637b2 100644 --- a/src/openassetio-core/CMakeLists.txt +++ b/src/openassetio-core/CMakeLists.txt @@ -90,9 +90,13 @@ target_include_directories(openassetio-core # Use includes from install tree for installed lib. "$") -target_link_libraries(openassetio-core +target_link_libraries( + openassetio-core PRIVATE - $) + # Header-only private dependencies: + $ + $ +) #----------------------------------------------------------------------- # API export header diff --git a/src/openassetio-core/src/hostApi/Manager.cpp b/src/openassetio-core/src/hostApi/Manager.cpp index 7896e7444..b1fc6b2f8 100644 --- a/src/openassetio-core/src/hostApi/Manager.cpp +++ b/src/openassetio-core/src/hostApi/Manager.cpp @@ -3,6 +3,8 @@ #include #include +#include + #include #include #include @@ -53,12 +55,11 @@ std::optional entityReferencePrefixFromInfo(const log::LoggerInterfacePtr & if (auto iter = info.find(Str{constants::kInfoKey_EntityReferencesMatchPrefix}); iter != info.end()) { if (const auto *prefixPtr = std::get_if(&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; }