INCLUDE(CheckIncludeFiles)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckLibraryExists)
INCLUDE(CheckSymbolExists)
INCLUDE(CheckTypeSize)
INCLUDE(CheckCSourceCompiles)
INCLUDE(CheckCXXSourceCompiles)


CHECK_TYPE_SIZE(size_t SIZEOF_SIZE_T)
IF (NOT SIZEOF_SIZE_T)
	ADD_DEFINITIONS(-Dsize_t=unsigned int)
ENDIF()
CHECK_TYPE_SIZE(ssize_t SIZEOF_SSIZE_T)
IF (NOT SIZEOF_SSIZE_T)
ADD_DEFINITIONS(-Dssize_t=int)
ENDIF()


CHECK_CXX_SOURCE_COMPILES (
	"int main()
	{
	static thread_local int i;
	return 0;
	}"
	HAVE_CXX11_THREAD_LOCAL
	)

IF (NOT HAVE_CXX11_THREAD_LOCAL)
	CHECK_CXX_SOURCE_COMPILES (
		"int main()
		{
		static __thread int i;
		return 0;
		}"
		HAVE_GNU_THREAD_LOCAL
		)
	ADD_DEFINITIONS(-Dthread_local=__thread)
ENDIF()

IF (NOT HAVE_CXX11_THREAD_LOCAL AND NOTHAVE_GNU_THREAD_LOCAL)
	MESSAGE (FATAL_ERROR "you compiler doesn't support thread_local or thread")
ENDIF()

CHECK_INCLUDE_FILES(sys/epoll.h HAVE_EPOLL_H)
CHECK_INCLUDE_FILES(sys/timerfd.h HAVE_TIMERFD)
CHECK_INCLUDE_FILES(sys/eventfd.h HAVE_EVENTFD)
CHECK_INCLUDE_FILES(sys/event.h HAVE_KQUEUE_H)
CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILES(netdb.h HAVE_NETDB_H)

CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILES(netdb.h HAVE_NETDB_H)
CHECK_INCLUDE_FILES(arpa/inet.h HAVE_ARPA_INET_H)
CHECK_INCLUDE_FILES(netinet/in.h HAVE_NETINET_IN_H)
CHECK_INCLUDE_FILES(sys/uio.h HAVE_SYS_UIO_H)
CHECK_INCLUDE_FILES(sys/time.h HAVE_SYS_TIME_H)
CHECK_INCLUDE_FILES(WinSock2.h HAVE_WIN_SOCK2_H)
CHECK_INCLUDE_FILES(sys/socket.h HAVE_SYS_SOCKET_H)
CHECK_INCLUDE_FILES(WS2tcpip.h HAVE_WS2_TCPIP_H)
CONFIGURE_FILE (${CMAKE_SOURCE_DIR}/src/config.h.in ${CMAKE_BINARY_DIR}/deps/include/config.h)
