From 7b2e817ed2e4a003e23801517ce533c8e5f4c302 Mon Sep 17 00:00:00 2001 From: James Eggleton Date: Sat, 11 Apr 2020 21:41:02 +0100 Subject: [PATCH] [Build] Update CMake to use C++11 and fix MacOS warnings (#313) --- src/CMakeLists.txt | 3 +++ src/tools/sys.cpp | 16 ++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 59c426ea4..ef9684695 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,4 +32,7 @@ endif() target_link_libraries(libocca ${LIBOCCA_LIBRARIES}) +target_compile_features(libocca PUBLIC cxx_std_11) +target_compile_options(libocca PRIVATE -Wall -Wextra -Wno-c++11-extensions -Wno-unused-parameter) + install(TARGETS libocca DESTINATION lib) diff --git a/src/tools/sys.cpp b/src/tools/sys.cpp index 1675a78f6..96c7ecff8 100644 --- a/src/tools/sys.cpp +++ b/src/tools/sys.cpp @@ -62,12 +62,9 @@ namespace occa { return (double) (ct.tv_sec + (1.0e-9 * ct.tv_nsec)); #elif (OCCA_OS == OCCA_MACOS_OS) # ifdef __clang__ - uint64_t ct; - ct = mach_absolute_time(); + uint64_t nanoseconds = clock_gettime_nsec_np(CLOCK_UPTIME_RAW); - const Nanoseconds ct2 = AbsoluteToNanoseconds(*(AbsoluteTime *) &ct); - - return ((double) 1.0e-9) * ((double) ( *((uint64_t*) &ct2) )); + return 1.0e-9 * nanoseconds; # else clock_serv_t cclock; host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); @@ -366,7 +363,14 @@ namespace occa { int getTID() { #if (OCCA_OS & (OCCA_LINUX_OS | OCCA_MACOS_OS)) - return syscall(SYS_gettid); + #if OCCA_OS == OCCA_MACOS_OS & (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12) + uint64_t tid64; + pthread_threadid_np(NULL, &tid64); + pid_t tid = (pid_t)tid64; + #else + pid_t tid = syscall(SYS_gettid); + #endif + return tid; #else return GetCurrentThreadId(); #endif