diff --git a/lib/monkey/CMakeLists.txt b/lib/monkey/CMakeLists.txt index e0709c4239b..95d8cc1e618 100644 --- a/lib/monkey/CMakeLists.txt +++ b/lib/monkey/CMakeLists.txt @@ -292,7 +292,16 @@ include_directories(include/monkey/) include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/) include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/monkey/) -if (MK_EVENT_LOOP_LIBEVENT) +# Check if we need to build libevent by using auto discovery mechanism +if (CMAKE_SYSTEM_NAME MATCHES "Windows" AND + ( + NOT MK_EVENT_LOOP_SELECT AND + NOT MK_EVENT_LOOP_POLL AND + NOT MK_EVENT_LOOP_KQUEUE AND + NOT MK_EVENT_LOOP_EPOLL + ) OR MK_EVENT_LOOP_LIBEVENT) + + set(MK_EVENT_LOOP_LIBEVENT Yes) include_directories(mk_core/deps/libevent/include) include_directories("${PROJECT_BINARY_DIR}/mk_core/deps/libevent/include/") endif() diff --git a/lib/monkey/include/monkey/mk_core/mk_event.h b/lib/monkey/include/monkey/mk_core/mk_event.h index 9bcc33dbdb4..c0c56f8ba98 100644 --- a/lib/monkey/include/monkey/mk_core/mk_event.h +++ b/lib/monkey/include/monkey/mk_core/mk_event.h @@ -70,28 +70,26 @@ #define MK_EVENT_IS_REGISTERED(event) ((event->status & MK_EVENT_REGISTERED) != 0) -#if defined(_WIN32) - #include "mk_event_libevent.c" +#if defined(MK_EVENT_LOOP_SELECT) + #include "mk_event_select.h" +#elif defined(MK_EVENT_LOOP_POLL) + #include "mk_event_poll.h" +#elif defined(MK_EVENT_LOOP_KQUEUE) + #include "mk_event_kqueue.h" +#elif defined(MK_EVENT_LOOP_EPOLL) + #include "mk_event_epoll.h" +#elif defined(MK_EVENT_LOOP_LIBEVENT) + #include "mk_event_libevent.h" #else - #if defined(MK_EVENT_LOOP_SELECT) - #include "mk_event_select.h" - #elif defined(MK_EVENT_LOOP_POLL) - #include "mk_event_poll.h" - #elif defined(MK_EVENT_LOOP_KQUEUE) - #include "mk_event_kqueue.h" - #elif defined(MK_EVENT_LOOP_EPOLL) + /* do our best based on the operating system */ + #if defined(__linux__) #include "mk_event_epoll.h" - #elif defined(MK_EVENT_LOOP_LIBEVENT) + #elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__) || defined(__OpenBSD__) + #include "mk_event_kqueue.h" + #elif defined(_WIN32) #include "mk_event_libevent.h" #else - /* do our best based on the operating system */ - #if defined(__linux__) - #include "mk_event_epoll.h" - #elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__) || defined(__OpenBSD__) - #include "mk_event_kqueue.h" - #else - #include "mk_event_select.h" - #endif + #include "mk_event_select.h" #endif #endif diff --git a/lib/monkey/mk_core/mk_event.c b/lib/monkey/mk_core/mk_event.c index 3241100b3e6..631efaa41e9 100644 --- a/lib/monkey/mk_core/mk_event.c +++ b/lib/monkey/mk_core/mk_event.c @@ -28,33 +28,29 @@ #include #include - -#if defined(_WIN32) +#if defined(MK_EVENT_LOOP_SELECT) + #include "mk_event_select.c" +#elif defined(MK_EVENT_LOOP_POLL) + #include "mk_event_poll.c" +#elif defined(MK_EVENT_LOOP_KQUEUE) + #include "mk_event_kqueue.c" +#elif defined(MK_EVENT_LOOP_EPOLL) + #include "mk_event_epoll.c" +#elif defined(MK_EVENT_LOOP_LIBEVENT) #include "mk_event_libevent.c" #else - #if defined(MK_EVENT_LOOP_SELECT) - #include "mk_event_select.c" - #elif defined(MK_EVENT_LOOP_POLL) - #include "mk_event_poll.c" - #elif defined(MK_EVENT_LOOP_KQUEUE) - #include "mk_event_kqueue.c" - #elif defined(MK_EVENT_LOOP_EPOLL) + /* do our best based on the operating system */ + #if defined(__linux__) #include "mk_event_epoll.c" - #elif defined(MK_EVENT_LOOP_LIBEVENT) + #elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__) || defined(__OpenBSD__) + #include "mk_event_kqueue.c" + #elif defined(_WIN32) #include "mk_event_libevent.c" #else - /* do our best based on the operating system */ - #if defined(__linux__) - #include "mk_event_epoll.c" - #elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__) || defined(__OpenBSD__) - #include "mk_event_kqueue.c" - #else - #include "mk_event_select.c" - #endif + #include "mk_event_select.c" #endif #endif - /* Initialize backend */ int mk_event_init() {