Fix problems with clock_gettime and OSX < 10.12 + XCode 8
[folly.git] / folly / portability / Time.h
index 708a5faf956c1dc4442015bda698bcd15982f527..0ed24a27f5522eb9cbcaeb719b265f91d3ac4067 100755 (executable)
 
 #include <folly/portability/Config.h>
 
+// OSX is a pain. The XCode 8 SDK always declares clock_gettime
+// even if the target OS version doesn't support it, so you get
+// an error at runtime because it can't resolve the symbol. We
+// solve that by pretending we have it here in the header and
+// then enable our implementation on the source side so that
+// gets linked in instead.
+#if __MACH__ && ( \
+      MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 || \
+      __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0)
+
+# ifdef FOLLY_HAVE_CLOCK_GETTIME
+# undef FOLLY_HAVE_CLOCK_GETTIME
+# endif
+
+# define FOLLY_HAVE_CLOCK_GETTIME 1
+# define FOLLY_FORCE_CLOCK_GETTIME_DEFINITION 1
+
+#endif
+
 // These aren't generic implementations, so we can only declare them on
 // platforms we support.
 #if !FOLLY_HAVE_CLOCK_GETTIME && (defined(__MACH__) || defined(_WIN32))