From 50c540180eed1fe190f75abf3c538256209a2c3c Mon Sep 17 00:00:00 2001 From: Nick Logozzo Date: Wed, 12 Jun 2024 10:34:54 -0400 Subject: [PATCH] macOS - Generate GUID with uuidgen --- README.md | 21 +++++++++++++++++---- src/helpers/stringhelpers.cpp | 14 ++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 27eebbb..1b7f79f 100644 --- a/README.md +++ b/README.md @@ -24,14 +24,21 @@ The following are a list of dependencies used by libnick. The above dependencies must be installed, plus the following for Windows systems: - sqlcipher -### Linux/macOS Only -The above dependencies must be installed, plus the following for Linux/macOS systems: +### Linux +The above dependencies must be installed, plus the following for Linux systems: - glib - libsecret - libuuid - openssl - Used for sqlcipher, as libnick manually builds sqlcipher on Linux as the vcpkg port is broken. +### macOS +The above dependencies must be installed, plus the following for macOS systems: +- glib +- libsecret +- openssl + - Used for sqlcipher, as libnick manually builds sqlcipher on macOS as the vcpkg port is broken. + ## Consuming libnick via vcpkg libnick is available through `vcpkg`. @@ -62,7 +69,7 @@ A C++20 compiler is also required to build libnick. 1. Run `vcpkg install curl gettext-libintl glib gtest jsoncpp libsecret libuuid maddy openssl` #### macOS 1. Set the `VCPKG_DEFAULT_TRIPLET` environment variable to `x64-osx` -1. Run `vcpkg install curl gettext-libintl glib gtest jsoncpp libsecret libuuid maddy openssl` +1. Run `vcpkg install curl gettext-libintl glib gtest jsoncpp libsecret maddy openssl` ### Building 1. First, clone/download the repo. @@ -74,7 +81,13 @@ A C++20 compiler is also required to build libnick. - If you plan to install libnick, add `-DCMAKE_INSTALL_PREFIX=PATH_TO_INSTALL_DIR` to the end of the command, replacing `PATH_TO_INSTALL_DIR` with the path of where you'd like libnick to install to. 1. From the `build` folder, run `cmake --build . --config Release`. 1. After these commands complete, libnick will be successfully built and its binaries can be found in the `Release` folder of the `build` folder. -#### Linux/macOS +#### Linux +1. From the `build` folder, run `cmake .. -DCMAKE_BUILD_TYPE=Release`. + - To skip building libnick's test suite, add `-DBUILD_TESTING="OFF"` to the end of the command. + - If you plan to install libnick, add `-DCMAKE_INSTALL_PREFIX=PATH_TO_INSTALL_DIR` to the end of the command, replacing `PATH_TO_INSTALL_DIR` with the path of where you'd like libnick to install to. +1. From the `build` folder, run `cmake --build .`. +1. After these commands complete, libnick will be successfully built and its binaries can be found in the `build` folder. +#### macOS 1. From the `build` folder, run `cmake .. -DCMAKE_BUILD_TYPE=Release`. - To skip building libnick's test suite, add `-DBUILD_TESTING="OFF"` to the end of the command. - If you plan to install libnick, add `-DCMAKE_INSTALL_PREFIX=PATH_TO_INSTALL_DIR` to the end of the command, replacing `PATH_TO_INSTALL_DIR` with the path of where you'd like libnick to install to. diff --git a/src/helpers/stringhelpers.cpp b/src/helpers/stringhelpers.cpp index 10bbd17..4ee3665 100644 --- a/src/helpers/stringhelpers.cpp +++ b/src/helpers/stringhelpers.cpp @@ -9,8 +9,10 @@ #include #ifdef _WIN32 #include -#else +#elif defined(__linux__) #include +#elif defined(__APPLE__) +#include "system/environment.h" #endif namespace Nickvision::Helpers @@ -125,8 +127,9 @@ namespace Nickvision::Helpers std::string StringHelpers::newGuid() { +#ifndef __APPLE__ std::array guid; - #ifdef _WIN32 +#ifdef _WIN32 GUID win; CoInitializeEx(nullptr, COINIT_MULTITHREADED); if (CoCreateGuid(&win) != S_OK) @@ -154,9 +157,9 @@ namespace Nickvision::Helpers (unsigned char)win.Data4[6], (unsigned char)win.Data4[7] }; - #else +#elif defined(__linux__) uuid_generate(guid.data()); - #endif +#endif std::ostringstream out; out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[0]); out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[1]); @@ -179,6 +182,9 @@ namespace Nickvision::Helpers out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[14]); out << std::setfill('0') << std::setw(2) << std::hex << static_cast(guid[15]); return out.str(); +#else + return System::Environment::exec("uuidgen"); +#endif } std::string StringHelpers::replace(std::string s, const std::string& toReplace, const std::string& replace)