Skip to content

Commit 624073a

Browse files
authored
Merge pull request #6460 from hughbe/libuuid-windows
Fix linking libuuid on Windows
2 parents fa8f308 + beafffb commit 624073a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/Basic/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
44
set(UUID_INCLUDE "")
55
set(UUID_LIBRARIES "")
6+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
7+
set(UUID_INCLUDE "")
8+
set(UUID_LIBRARIES "ole32.lib")
69
else()
710
find_package(UUID REQUIRED)
811
set(UUID_INCLUDE "-I${UUID_INCLUDE_DIRS}")

lib/Basic/UUID.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
// WIN32 doesn't natively support <uuid/uuid.h>. Instead, we use Win32 APIs.
2121
#if defined(_WIN32)
2222
#define WIN32_LEAN_AND_MEAN
23-
#include <rpc.h>
23+
#define NOMINMAX
24+
#include <objbase.h>
2425
#include <string>
2526
#else
2627
#include <uuid/uuid.h>
@@ -31,7 +32,7 @@ using namespace swift;
3132
swift::UUID::UUID(FromRandom_t) {
3233
#if defined(_WIN32)
3334
::UUID uuid;
34-
UuidCreate(&uuid);
35+
::CoCreateGuid(&uuid);
3536

3637
memcpy(Value, &uuid, Size);
3738
#else
@@ -42,7 +43,7 @@ swift::UUID::UUID(FromRandom_t) {
4243
swift::UUID::UUID(FromTime_t) {
4344
#if defined(_WIN32)
4445
::UUID uuid;
45-
UuidCreate(&uuid);
46+
::CoCreateGuid(&uuid);
4647

4748
memcpy(Value, &uuid, Size);
4849
#else

0 commit comments

Comments
 (0)