diff --git a/CMakeLists.txt b/CMakeLists.txt
index df1c857a..c2d8677e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -948,6 +948,11 @@ set (ZMQ_BUILD_TESTS ON CACHE BOOL "Build the tests for ZeroMQ")
if (ZMQ_BUILD_TESTS)
enable_testing () # Enable testing only works in root scope
ADD_SUBDIRECTORY (tests)
+ if (BUILD_STATIC)
+ add_subdirectory (unittests)
+ else ()
+ message (WARNING "Not building unit tests, since BUILD_STATIC is not enabled")
+ endif ()
endif ()
#-----------------------------------------------------------------------------
diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt
new file mode 100644
index 00000000..57ebdda7
--- /dev/null
+++ b/unittests/CMakeLists.txt
@@ -0,0 +1,64 @@
+# CMake build script for ZeroMQ unit tests
+cmake_minimum_required(VERSION "2.8.1")
+
+set(unittests
+ unittest_ypipe
+ unittest_poller
+)
+
+#IF (ENABLE_DRAFTS)
+# list(APPEND tests
+# )
+#ENDIF (ENABLE_DRAFTS)
+
+# add location of platform.hpp for Windows builds
+if(WIN32)
+ add_definitions(-DZMQ_CUSTOM_PLATFORM_HPP)
+ add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
+ # Same name on 64bit systems
+ link_libraries(ws2_32.lib)
+endif()
+
+include_directories("${CMAKE_SOURCE_DIR}/include" "${CMAKE_SOURCE_DIR}/src" "${CMAKE_BINARY_DIR}")
+
+foreach(test ${unittests})
+ # target_sources not supported before CMake 3.1
+ add_executable(${test} ${test}.cpp)
+
+ # per-test directories not generated on OS X / Darwin
+ if (NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang.*")
+ link_directories(${test} PRIVATE "${CMAKE_SOURCE_DIR}/../lib")
+ endif()
+
+ target_link_libraries(${test} libzmq-static ${OPTIONAL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} unity)
+
+ if(RT_LIBRARY)
+ target_link_libraries(${test} ${RT_LIBRARY})
+ endif()
+
+ if(WIN32)
+ add_test(NAME ${test} WORKING_DIRECTORY ${LIBRARY_OUTPUT_PATH} COMMAND ${test})
+ else()
+ add_test(NAME ${test} COMMAND ${test})
+ endif()
+
+ set_tests_properties(${test} PROPERTIES TIMEOUT 10)
+
+ # TODO prevent libzmq (non-static) being in the list of link libraries at all
+ get_target_property(LIBS ${test} LINK_LIBRARIES)
+ list(REMOVE_ITEM LIBS libzmq)
+ message("Link libraries of ${test}: ${LIBS}")
+ set_target_properties(${test} PROPERTIES LINK_LIBRARIES "${LIBS}")
+endforeach()
+
+#Check whether all tests in the current folder are present
+#TODO duplicated with tests/CMakeLists.txt, define as a function?
+file(READ "${CMAKE_CURRENT_LIST_FILE}" CURRENT_LIST_FILE_CONTENT)
+file(GLOB ALL_TEST_SOURCES "test_*.cpp")
+foreach(TEST_SOURCE ${ALL_TEST_SOURCES})
+ get_filename_component(TESTNAME "${TEST_SOURCE}" NAME_WE)
+ string(REGEX MATCH "${TESTNAME}" MATCH_TESTNAME "${CURRENT_LIST_FILE_CONTENT}")
+ if (NOT MATCH_TESTNAME)
+ message(AUTHOR_WARNING "Test '${TESTNAME}' is not known to CTest.")
+ endif()
+endforeach()
diff --git a/unittests/unittest_poller.cpp b/unittests/unittest_poller.cpp
new file mode 100644
index 00000000..4df2f9b8
--- /dev/null
+++ b/unittests/unittest_poller.cpp
@@ -0,0 +1,47 @@
+/*
+Copyright (c) 2018 Contributors as noted in the AUTHORS file
+
+This file is part of 0MQ.
+
+0MQ is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+0MQ is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this program. If not, see .
+*/
+
+#include "../tests/testutil.hpp"
+
+#include
+
+#include
+
+void setUp ()
+{
+}
+void tearDown ()
+{
+}
+
+void test_create ()
+{
+ zmq::thread_ctx_t thread_ctx;
+ zmq::poller_t poller (thread_ctx);
+}
+
+int main (void)
+{
+ setup_test_environment ();
+
+ UNITY_BEGIN ();
+ RUN_TEST (test_create);
+
+ return UNITY_END ();
+}
diff --git a/unittests/unittest_ypipe.cpp b/unittests/unittest_ypipe.cpp
new file mode 100644
index 00000000..75c91d23
--- /dev/null
+++ b/unittests/unittest_ypipe.cpp
@@ -0,0 +1,46 @@
+/*
+Copyright (c) 2018 Contributors as noted in the AUTHORS file
+
+This file is part of 0MQ.
+
+0MQ is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+0MQ is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this program. If not, see .
+*/
+
+#include "../tests/testutil.hpp"
+
+#include
+
+#include
+
+void setUp ()
+{
+}
+void tearDown ()
+{
+}
+
+void test_create ()
+{
+ zmq::ypipe_t ypipe;
+}
+
+int main (void)
+{
+ setup_test_environment ();
+
+ UNITY_BEGIN ();
+ RUN_TEST (test_create);
+
+ return UNITY_END ();
+}