浏览代码

Use auto-detection for clock_gettime() function on Apple platforms.
Fix #1692 [ci only: OSX]

Yao Wei Tjong 姚伟忠 9 年之前
父节点
当前提交
9290ebf6e0

+ 6 - 0
Source/ThirdParty/Civetweb/CMakeLists.txt

@@ -34,6 +34,12 @@ if (WIN32)
             add_definitions (-D_TIMESPEC_DEFINED)
         endif ()
     endif ()
+elseif (APPLE)
+    include (CheckLibraryExists)
+    check_library_exists (c clock_gettime "" FOUND_CLOCK_GETTIME_IN_C)
+    if (FOUND_CLOCK_GETTIME_IN_C)
+        add_definitions (-DHAVE_CLOCK_GETTIME)
+    endif()
 endif ()
 
 # Define source files

+ 3 - 3
Source/ThirdParty/Civetweb/src/civetweb.c

@@ -123,9 +123,6 @@ mg_static_assert(sizeof(void *) >= sizeof(int), "data type size check");
 
 #ifdef __MACH__
 
-// Urho3D: prefer own implementation of clock_gettime regardless of XCode / SDK version
-#define _DARWIN_FEATURE_CLOCK_GETTIME 0
-
 #define CLOCK_MONOTONIC (1)
 #define CLOCK_REALTIME (2)
 
@@ -135,6 +132,8 @@ mg_static_assert(sizeof(void *) >= sizeof(int), "data type size check");
 #include <mach/mach_time.h>
 #include <assert.h>
 
+// Urho3D - On Apple platform, use its clock_gettime() when it is available
+#ifndef HAVE_CLOCK_GETTIME
 int clock_gettime(int clk_id, struct timespec *t)
 {
 	if (clk_id == CLOCK_REALTIME) {
@@ -174,6 +173,7 @@ int clock_gettime(int clk_id, struct timespec *t)
 	}
 	return -1; /* EINVAL - Clock ID is unknown */
 }
+#endif  // HAVE_CLOCK_GETTIME
 #endif
 
 // Urho3D: Prevent inclusion of pthread_time.h on MinGW, instead prefer own implementation of clock_gettime()

+ 2 - 2
Source/ThirdParty/SDL/CMakeLists.txt

@@ -285,8 +285,8 @@ dep_option(NAS_SHARED          "Dynamically load NAS audio API" ON NAS OFF)
 dep_option(SNDIO               "Support the Roar audio API" ON UNIX_SYS OFF)
 # Urho3D - commented out RPATH as an option because Urho3D is configured to always use RPATH, so init the variable to always TRUE
 set (RPATH TRUE)
-# Urho3D - prefer clock_gettime() when it is available (hide the option for Windows and Apple)
-dep_option(CLOCK_GETTIME       "Use clock_gettime() instead of gettimeofday()" ON "NOT WINDOWS AND NOT APPLE" OFF)
+# Urho3D - prefer clock_gettime() when it is available (hide the option for Windows)
+dep_option(CLOCK_GETTIME       "Use clock_gettime() instead of gettimeofday()" ON "NOT WINDOWS" OFF)
 set_option(INPUT_TSLIB         "Use the Touchscreen library for input" ${UNIX_SYS})
 dep_option(VIDEO_WAYLAND       "Use Wayland video driver" ON UNIX_SYS OFF)
 dep_option(WAYLAND_SHARED      "Dynamically load Wayland support" ON VIDEO_WAYLAND OFF)