From c64778e9499ad5b0113461a95143abd783743ecb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Guillem=20Aleny=C3=A0=20Ribas?= <galenya@iri.upc.edu>
Date: Sat, 16 Apr 2011 13:35:10 +0000
Subject: [PATCH] MACOS adaptation

---
 src/CMakeLists.txt          | 7 ++++++-
 src/examples/CMakeLists.txt | 6 +++++-
 src/time/ctime.cpp          | 9 ++++++++-
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4d0b7f1..7d8b71c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -11,7 +11,12 @@ INCLUDE_DIRECTORIES(./exceptions ./mutex ./events ./threads ./logs ./time)
 ADD_LIBRARY(iriutils SHARED ${sources})
 
 #edit the following line to add the necessary system libraries (if any)
-TARGET_LINK_LIBRARIES(iriutils pthread rt)
+IF(APPLE)
+  MESSAGE("APPLE SYSTEM FOUND")
+  TARGET_LINK_LIBRARIES(iriutils pthread)
+ELSE(APPLE)
+  TARGET_LINK_LIBRARIES(iriutils pthread rt)
+ENDIF(APPLE)
 
 INSTALL(TARGETS iriutils
   RUNTIME DESTINATION bin
diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt
index be21df5..55933e9 100644
--- a/src/examples/CMakeLists.txt
+++ b/src/examples/CMakeLists.txt
@@ -32,7 +32,11 @@ TARGET_LINK_LIBRARIES(test_both iriutils pthread)
 ADD_EXECUTABLE(test_time test_time.cpp)
 
 # edit the following line to add the necessary libraries
-TARGET_LINK_LIBRARIES(test_time iriutils pthread rt) 
+IF(APPLE)
+  TARGET_LINK_LIBRARIES(test_time iriutils pthread)
+ELSE(APPLE)
+  TARGET_LINK_LIBRARIES(test_time iriutils pthread rt)
+ENDIF(APPLE)
 
 # edit the following line to add the source code for the example and the name of the executable
 ADD_EXECUTABLE(test_logs test_logs.cpp)
diff --git a/src/time/ctime.cpp b/src/time/ctime.cpp
index bf1abf5..162d609 100644
--- a/src/time/ctime.cpp
+++ b/src/time/ctime.cpp
@@ -104,7 +104,14 @@ void CTime::set(double milliseconds)
 
   if(milliseconds<0.0)
   {
-    clock_gettime(CLOCK_REALTIME, &time_temp );
+#if defined __APPLE__
+	  struct timeval tv;
+	  gettimeofday(&tv, NULL);
+	  time_temp.tv_sec = tv.tv_sec;
+	  time_temp.tv_nsec = tv.tv_usec*1000; 
+#else
+	  clock_gettime(CLOCK_REALTIME, &time_temp );
+#endif
   }
   else
   {
-- 
GitLab