From d288acf1750522c71553ec9141859865b61612d3 Mon Sep 17 00:00:00 2001 From: "paul.bristow" Date: Wed, 27 Dec 2017 07:56:41 +0000 Subject: [PATCH] Add support for Cygwin Add UNITTEST_CYGWIN directive and use it to: include Posix/TimeHelpers.h for Cygwin, exclude the signal handling in SignalTranslator.h/.cpp as Cygwin does not have the necessary Posix signal handling support, i.e. sigjmp_buf or siglongjmp. Reimplement SleepMs in TimeHelpers.cpp using C++11 rather than usleep as that is not present on Cygwin. Update CMakeLists.txt to exclude SignalTranslator.h/.cpp from the build. --- CMakeLists.txt | 4 ++++ UnitTest++/Config.h | 6 ++++++ UnitTest++/Posix/TimeHelpers.cpp | 4 +++- UnitTest++/TimeHelpers.h | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a683ea1..26623c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,10 @@ endif(WIN32) file(GLOB platformHeaders_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/${platformDir_}/*.h) file(GLOB platformSources_ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} UnitTest++/${platformDir_}/*.cpp) +if(CYGWIN) + list(REMOVE_ITEM platformHeaders_ UnitTest++/${platformDir_}/SignalTranslator.h) + list(REMOVE_ITEM platformSources_ UnitTest++/${platformDir_}/SignalTranslator.cpp) +endif() source_group(${platformDir_} FILES ${platformHeaders_} ${platformSources_}) # create the lib diff --git a/UnitTest++/Config.h b/UnitTest++/Config.h index 4bebf1a..7a93114 100644 --- a/UnitTest++/Config.h +++ b/UnitTest++/Config.h @@ -20,11 +20,17 @@ #define UNITTEST_WIN32 #endif +#ifndef __CYGWIN__ #if defined(unix) || defined(__unix__) || defined(__unix) || defined(linux) || \ defined(__APPLE__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) \ || defined (__HAIKU__) #define UNITTEST_POSIX #endif +#endif + +#if defined(__CYGWIN__) + #define UNITTEST_CYGWIN +#endif #if defined(__MINGW32__) #define UNITTEST_MINGW diff --git a/UnitTest++/Posix/TimeHelpers.cpp b/UnitTest++/Posix/TimeHelpers.cpp index d9a78eb..f3d26c4 100644 --- a/UnitTest++/Posix/TimeHelpers.cpp +++ b/UnitTest++/Posix/TimeHelpers.cpp @@ -1,4 +1,6 @@ #include "TimeHelpers.h" +#include +#include #include namespace UnitTest { @@ -27,7 +29,7 @@ namespace UnitTest { void TimeHelpers::SleepMs(int ms) { - usleep(static_cast(ms * 1000)); + std::this_thread::sleep_for(std::chrono::microseconds(ms * 1000)); } } diff --git a/UnitTest++/TimeHelpers.h b/UnitTest++/TimeHelpers.h index 2f186ff..1c9f4b5 100644 --- a/UnitTest++/TimeHelpers.h +++ b/UnitTest++/TimeHelpers.h @@ -1,6 +1,6 @@ #include "Config.h" -#if defined UNITTEST_POSIX +#if defined(UNITTEST_POSIX) || defined(UNITTEST_CYGWIN) #include "Posix/TimeHelpers.h" #else #include "Win32/TimeHelpers.h"