Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
NC-7801: Correctly generate UUIDs on linux
  • Loading branch information
martinweismann committed Apr 20, 2018
1 parent b649146 commit 48ea4c6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -376,6 +376,7 @@ elseif(UNIX)
# Uncomment the following to but the version info into the .so-file.
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION "${LIB3MF_VERSION_MAJOR}.${LIB3MF_VERSION_MINOR}.${LIB3MF_VERSION_MICRO}")
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION "${LIB3MF_VERSION_MAJOR}")
target_link_libraries(${PROJECT_NAME} uuid)
endif()


Expand Down
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -20,6 +20,11 @@ and ZIP compression). This will come when time passes.
The current code runs on Windows, Linux and Mac. To generate projects for Visual Studio or Unix
Makefiles use the scripts in the folder [cmake](cmake).

### Dependencies
* Unix: [uuid](https://linux.die.net/man/3/uuid)
* Linux (Ubuntu/Debian): sudo at-get install uuid-dev
* MAC: brew install ossp-uuid

Instead of building lib3MF from source, you can download the compiled shared libarary as part of a minimal SDK from the [official releases](https://github.com/3MFConsortium/lib3mf/releases),
or use the [nightly builds](https://github.com/3MFConsortium/lib3mf-binaries)

Expand Down
16 changes: 6 additions & 10 deletions Source/Common/NMR_UUID.cpp
Expand Up @@ -41,8 +41,7 @@ NMR_UUID.cpp implements a datatype and functions to handle UUIDs
#include <Objbase.h>
#include <iomanip>
#else
#include <random>
#include "Common/Platform/NMR_Time.h"
#include <uuid/uuid.h>
#endif

namespace NMR
Expand All @@ -58,14 +57,11 @@ namespace NMR
throw CNMRException(NMR_ERROR_UUIDGENERATIONFAILED);
set(str);
#else
static std::mt19937 rng(((unsigned int)std::random_device()()) ^ ((unsigned int)fnGetUnixTime()) );
std::uniform_int_distribution<std::mt19937::result_type> distHexaDec(0, 15);
const nfWChar* hexaDec = L"0123456789abcdef";
nfWChar string[33];
for (int i = 0; i < 32; i++)
string[i] = hexaDec[distHexaDec(rng)];
string[32] = 0;
set(string);
uuid_t uuid;
uuid_generate_random(uuid);
char s[37];
uuid_unparse(uuid, s);
set(std::string(s).c_str());
#endif
}

Expand Down

0 comments on commit 48ea4c6

Please sign in to comment.