From 379836f32cb3318711a12e84092c397bc86e0d85 Mon Sep 17 00:00:00 2001 From: Martin Plicht Date: Tue, 14 Feb 2012 16:25:23 +0100 Subject: [PATCH] cmake: mac: Don't require rt library --- CMakeLists.txt | 2 +- src/platform/GetTime.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ae90dd69..887cdfbe3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1007,7 +1007,7 @@ if(USE_CONSOLE) ${READLINE_LIBRARIES} ) endif() -if(UNIX) +if(UNIX AND NOT APPLE) target_link_libraries(c4group rt) target_link_libraries(c4script rt) target_link_libraries(netpuncher rt) diff --git a/src/platform/GetTime.cpp b/src/platform/GetTime.cpp index bb660df14..d64d7938d 100644 --- a/src/platform/GetTime.cpp +++ b/src/platform/GetTime.cpp @@ -30,14 +30,26 @@ unsigned int GetTime() #else +#ifdef __APPLE__ +#include +#else #include +#endif unsigned int GetTime() { +#ifdef __APPLE__ + static time_t sec_offset; + timeval tv; + gettimeofday(&tv, 0); + if (!sec_offset) sec_offset = tv.tv_sec; + return (tv.tv_sec - sec_offset) * 1000 + tv.tv_usec / 1000; +#else timespec tv; clock_gettime(CLOCK_MONOTONIC, &tv); static time_t sec_offset = tv.tv_sec; return (tv.tv_sec - sec_offset) * 1000 + tv.tv_nsec / 1000000; +#endif } #endif