Skip to content

Commit

Permalink
macOS - Generate GUID with uuidgen
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Jun 12, 2024
1 parent 0c168e4 commit 50c5401
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
14 changes: 10 additions & 4 deletions src/helpers/stringhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#include <curl/curl.h>
#ifdef _WIN32
#include <windows.h>
#else
#elif defined(__linux__)
#include <uuid/uuid.h>
#elif defined(__APPLE__)
#include "system/environment.h"
#endif

namespace Nickvision::Helpers
Expand Down Expand Up @@ -125,8 +127,9 @@ namespace Nickvision::Helpers

std::string StringHelpers::newGuid()
{
#ifndef __APPLE__
std::array<unsigned char, 16> guid;
#ifdef _WIN32
#ifdef _WIN32
GUID win;
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if (CoCreateGuid(&win) != S_OK)
Expand Down Expand Up @@ -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<int>(guid[0]);
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[1]);
Expand All @@ -179,6 +182,9 @@ namespace Nickvision::Helpers
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(guid[14]);
out << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(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)
Expand Down

0 comments on commit 50c5401

Please sign in to comment.