Skip to content

Commit af232c1

Browse files
authored
Merge pull request #1819 from compnerd/uuid
Use bundled UUID
2 parents 550b56c + ea0017c commit af232c1

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

CMakeLists.txt

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ option(FOUNDATION_PATH_TO_XCTEST_BUILD "Path to XCTest build" "")
1919
find_package(CURL REQUIRED)
2020
find_package(ICU COMPONENTS uc i18n REQUIRED)
2121
find_package(LibXml2 REQUIRED)
22-
find_package(UUID REQUIRED)
2322

2423
include(SwiftSupport)
2524
include(GNUInstallDirs)
@@ -57,6 +56,27 @@ ExternalProject_Add(CoreFoundation
5756
${CMAKE_COMMAND} -E env --unset=DESTDIR ${CMAKE_COMMAND} --build . --target install)
5857
ExternalProject_Get_Property(CoreFoundation install_dir)
5958

59+
add_library(uuid
60+
STATIC
61+
uuid/uuid.h
62+
uuid/uuid.c)
63+
set_target_properties(uuid
64+
PROPERTIES
65+
POSITION_INDEPENDENT_CODE YES)
66+
# Add an include directory for the CoreFoundation framework headers to satisfy
67+
# the dependency on TargetConditionals.h
68+
target_compile_options(uuid
69+
PUBLIC
70+
-I${install_dir}/System/Library/Frameworks/CoreFoundation.framework/Headers)
71+
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
72+
target_compile_definitions(uuid
73+
PRIVATE
74+
_CRT_NONSTDC_NO_WARNINGS
75+
_CRT_SECURE_NO_DEPRECATE
76+
_CRT_SECURE_NO_WARNINGS)
77+
endif()
78+
add_dependencies(uuid CoreFoundation)
79+
6080
set(swift_optimization_flags)
6181
if(CMAKE_BUILD_TYPE MATCHES Release)
6282
set(swift_optimization_flags -O)
@@ -262,7 +282,8 @@ add_swift_library(Foundation
262282
${ICU_UC_LIBRARY} ${ICU_I18N_LIBRARY}
263283
${LIBXML2_LIBRARIES}
264284
${libdispatch_ldflags}
265-
${uuid_LIBRARIES}
285+
-L${CMAKE_CURRENT_BINARY_DIR}
286+
-luuid
266287
-Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN"
267288
SWIFT_FLAGS
268289
-DDEPLOYMENT_RUNTIME_SWIFT
@@ -278,11 +299,12 @@ if(NOT BUILD_SHARED_LIBS)
278299
set(Foundation_INTERFACE_LIBRARIES
279300
-L${install_dir}/usr/lib
280301
-lCoreFoundation
302+
-L${CMAKE_CURRENT_BINARY_DIR}
303+
-luuid
281304
${CURL_LIBRARIES}
282305
${ICU_UC_LIBRARY}
283306
${ICU_I18N_LIBRARY}
284-
${LIBXML2_LIBRARIES}
285-
${uuid_LIBRARIES})
307+
${LIBXML2_LIBRARIES})
286308
endif()
287309

288310
add_swift_executable(plutil
@@ -293,8 +315,8 @@ add_swift_executable(plutil
293315
${deployment_enable_libdispatch}
294316
-F${install_dir}/System/Library/Frameworks
295317
LINK_FLAGS
296-
-L${CMAKE_CURRENT_BINARY_DIR}
297318
${libdispatch_ldflags}
319+
-L${CMAKE_CURRENT_BINARY_DIR}
298320
-lFoundation
299321
${Foundation_INTERFACE_LIBRARIES}
300322
-Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN/../lib/swift/${swift_os}"
@@ -307,6 +329,7 @@ add_swift_executable(plutil
307329
${swift_enable_testing}
308330
${swift_optimization_flags}
309331
DEPENDS
332+
uuid
310333
Foundation
311334
CoreFoundation)
312335

@@ -328,6 +351,7 @@ if(ENABLE_TESTING)
328351
-I;${ICU_INCLUDE_DIR}
329352
${libdispatch_cflags}
330353
DEPENDS
354+
uuid
331355
Foundation
332356
CoreFoundation)
333357

uuid/uuid.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535
#include <stdint.h>
3636
#include <string.h>
3737
#include <fcntl.h>
38+
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
3839
#include <unistd.h>
40+
#elif defined(_WIN32)
41+
#include <io.h>
42+
#endif
3943
#include <stdio.h>
4044

4145
#if TARGET_OS_MAC
@@ -61,9 +65,25 @@ static inline void nanotime(struct timespec *tv) {
6165
clock_gettime(CLOCK_MONOTONIC, tv);
6266
}
6367

68+
#elif TARGET_OS_WINDOWS
69+
#include <time.h>
70+
71+
#define WIN32_LEAN_AND_MEAN
72+
#include <windows.h>
73+
74+
static inline void nanotime(struct timespec *tv) {
75+
FILETIME ftTime;
76+
77+
GetSystemTimePreciseAsFileTime(&ftTime);
78+
79+
uint64_t Value = (((uint64_t)ftTime.dwHighDateTime << 32) | ftTime.dwLowDateTime);
80+
81+
tv->tv_sec = Value / 1000000000;
82+
tv->tv_nsec = Value - (tv->tv_sec * 1000000000);
83+
}
6484
#endif
6585

66-
static inline void read_random(void *buffer, u_int numBytes) {
86+
static inline void read_random(void *buffer, unsigned numBytes) {
6787
int fd = open("/dev/urandom", O_RDONLY);
6888
read(fd, buffer, numBytes);
6989
close(fd);
@@ -227,4 +247,4 @@ void
227247
uuid_unparse(const uuid_t uu, uuid_string_t out)
228248
{
229249
uuid_unparse_upper(uu, out);
230-
}
250+
}

0 commit comments

Comments
 (0)