From 448f0c2124d10e83ee41844d5102435ec116a8ed Mon Sep 17 00:00:00 2001 From: Jordon Brooks Date: Sun, 7 Apr 2024 01:29:06 +0100 Subject: [PATCH] Replace std::format with oss fmt library --- HarmonyLinkLib/CMakeLists.txt | 20 +++++++++++++++++++ .../src/Platform/IPlatformUtilities.cpp | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/HarmonyLinkLib/CMakeLists.txt b/HarmonyLinkLib/CMakeLists.txt index 76b4ccf..e551e6c 100644 --- a/HarmonyLinkLib/CMakeLists.txt +++ b/HarmonyLinkLib/CMakeLists.txt @@ -1,6 +1,23 @@ cmake_minimum_required(VERSION 3.10) project(HarmonyLinkLib VERSION 2.0.0) +include(FetchContent) + +FetchContent_Declare( + fmt + GIT_REPOSITORY https://github.com/fmtlib/fmt.git + GIT_TAG 10.2.1 # Specify the desired version of {fmt} +) + +FetchContent_MakeAvailable(fmt) +if(NOT fmt_POPULATED) + FetchContent_Populate(fmt) + # Add fmt but exclude it from the ALL target, reducing IDE clutter + add_subdirectory(${fmt_SOURCE_DIR} ${fmt_BINARY_DIR} EXCLUDE_FROM_ALL) +endif() + +set_target_properties(fmt PROPERTIES FOLDER External) + # Find the current Git branch and the last commit timestamp find_package(Git QUIET) if(GIT_FOUND) @@ -127,3 +144,6 @@ foreach(TYPE IN ITEMS DEBUG RELEASE) ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/${PROJECT_NAME}" ) endforeach() + +# Link fmt library +target_link_libraries(${PROJECT_NAME} PRIVATE fmt::fmt) diff --git a/HarmonyLinkLib/src/Platform/IPlatformUtilities.cpp b/HarmonyLinkLib/src/Platform/IPlatformUtilities.cpp index 90bd62a..ecfb670 100644 --- a/HarmonyLinkLib/src/Platform/IPlatformUtilities.cpp +++ b/HarmonyLinkLib/src/Platform/IPlatformUtilities.cpp @@ -14,7 +14,7 @@ #include "IPlatformUtilities.h" -#include +#include #include #include "Utilities.h" @@ -140,7 +140,7 @@ namespace HarmonyLinkLib score += CONTROLLER_DETECTION_SCORE; } - Utilities::DebugPrint(std::format("Score: {}/{}", score, FINAL_TARGET_DETECTION_SCORE).c_str()); + Utilities::DebugPrint(fmt::format("Score: {}/{}", score, FINAL_TARGET_DETECTION_SCORE).c_str()); return score >= FINAL_TARGET_DETECTION_SCORE; }