add libzmq and cppzmq

This commit is contained in:
Tony Theodore 2018-03-13 03:37:34 +11:00
parent 6158792029
commit 90fc2216c2
6 changed files with 179 additions and 0 deletions

18
src/cppzmq-test.cmake Normal file
View File

@ -0,0 +1,18 @@
# This file is part of MXE. See LICENSE.md for licensing information.
# partial module - included by src/cmake/CMakeLists.txt
set(TGT test-${PKG}-cmake)
enable_language(CXX)
add_executable(${TGT} ${CMAKE_CURRENT_LIST_DIR}/${PKG}-test.cpp)
find_package(ZeroMQ REQUIRED)
if (BUILD_STATIC)
target_link_libraries(${TGT} libzmq-static)
else ()
target_link_libraries(${TGT} libzmq)
endif ()
install(TARGETS ${TGT} DESTINATION bin)

44
src/cppzmq-test.cpp Normal file
View File

@ -0,0 +1,44 @@
/*
* This file is part of MXE. See LICENSE.md for licensing information.
*/
// Taken from: http://zguide.zeromq.org/cpp:hwserver
// Hello World server in C++
// Binds REP socket to tcp://*:5555
// Expects "Hello" from client, replies with "World"
//
#include <zmq.hpp>
#include <string>
#include <iostream>
#ifndef _WIN32
#include <unistd.h>
#else
#include <windows.h>
#define sleep(n) Sleep(n)
#endif
int main () {
// Prepare our context and socket
zmq::context_t context (1);
zmq::socket_t socket (context, ZMQ_REP);
socket.bind ("tcp://*:5555");
while (true) {
zmq::message_t request;
// Wait for next request from client
socket.recv (&request);
std::cout << "Received Hello" << std::endl;
// Do some 'work'
sleep(1);
// Send reply back to client
zmq::message_t reply (5);
memcpy (reply.data (), "World", 5);
socket.send (reply);
}
return 0;
}

23
src/cppzmq.mk Normal file
View File

@ -0,0 +1,23 @@
# This file is part of MXE. See LICENSE.md for licensing information.
PKG := cppzmq
$(PKG)_WEBSITE := https://github.com/zeromq/cppzmq
$(PKG)_DESCR := C++ binding for 0MQ
$(PKG)_IGNORE :=
$(PKG)_VERSION := 4.2.2
$(PKG)_CHECKSUM := 3ef50070ac5877c06c6bb25091028465020e181bbfd08f110294ed6bc419737d
$(PKG)_GH_CONF := zeromq/cppzmq/tags,v
$(PKG)_DEPS := cc libzmq
define $(PKG)_BUILD
# install the headers only
$(INSTALL) -m644 '$(SOURCE_DIR)'/zmq*.hpp '$(PREFIX)/$(TARGET)/include'
# test cmake
mkdir '$(BUILD_DIR).test-cmake'
cd '$(BUILD_DIR).test-cmake' && '$(TARGET)-cmake' \
-DPKG=$(PKG) \
-DPKG_VERSION=$($(PKG)_VERSION) \
'$(PWD)/src/cmake/test'
$(MAKE) -C '$(BUILD_DIR).test-cmake' -j 1 install
endef

31
src/libzmq-test.c Normal file
View File

@ -0,0 +1,31 @@
/*
* This file is part of MXE. See LICENSE.md for licensing information.
*/
// Taken from: http://zguide.zeromq.org/c:hwserver
// Hello World server
#include <zmq.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
int main (void)
{
// Socket to talk to clients
void *context = zmq_ctx_new ();
void *responder = zmq_socket (context, ZMQ_REP);
int rc = zmq_bind (responder, "tcp://*:5555");
assert (rc == 0);
while (1) {
char buffer [10];
zmq_recv (responder, buffer, 10, 0);
printf ("Received Hello\n");
sleep (1); // Do some 'work'
zmq_send (responder, "World", 5, 0);
}
return 0;
}

18
src/libzmq-test.cmake Normal file
View File

@ -0,0 +1,18 @@
# This file is part of MXE. See LICENSE.md for licensing information.
# partial module - included by src/cmake/CMakeLists.txt
set(TGT test-${PKG}-cmake)
enable_language(C)
add_executable(${TGT} ${CMAKE_CURRENT_LIST_DIR}/${PKG}-test.c)
find_package(ZeroMQ REQUIRED)
if (BUILD_STATIC)
target_link_libraries(${TGT} libzmq-static)
else ()
target_link_libraries(${TGT} libzmq)
endif ()
install(TARGETS ${TGT} DESTINATION bin)

45
src/libzmq.mk Normal file
View File

@ -0,0 +1,45 @@
# This file is part of MXE. See LICENSE.md for licensing information.
PKG := libzmq
$(PKG)_WEBSITE := https://github.com/zeromq/libzmq
$(PKG)_DESCR := ZeroMQ core engine in C++, implements ZMTP/3.0
$(PKG)_IGNORE :=
$(PKG)_VERSION := d2293da
$(PKG)_CHECKSUM := 585176d3f560ba52d5e9d4bf60c8dc8bbe7345f4a0bb33d461d799bbb0014a98
$(PKG)_GH_CONF := zeromq/libzmq/master
$(PKG)_DEPS := cc libsodium
define $(PKG)_BUILD
# build and install the library
cd '$(BUILD_DIR)' && $(TARGET)-cmake '$(SOURCE_DIR)' \
-DBUILD_TESTS=OFF \
-DWITH_DOC=OFF \
-DWITH_LIBSODIUM=ON \
-DWITH_PERF_TOOL=OFF
$(MAKE) -C '$(BUILD_DIR)' -j '$(JOBS)'
$(MAKE) -C '$(BUILD_DIR)' -j 1 install
# create pkg-config file
$(INSTALL) -d '$(PREFIX)/$(TARGET)/lib/pkgconfig'
(echo 'Name: $(PKG)'; \
echo 'Version: $($(PKG)_VERSION)'; \
echo 'Description: $($(PKG)_DESCR)'; \
echo 'Requires: libsodium'; \
echo 'Libs: -lzmq -lws2_32 -lrpcrt4 -liphlpapi'; \
echo 'Cflags.private: -DZMQ_STATIC';) \
> '$(PREFIX)/$(TARGET)/lib/pkgconfig/$(PKG).pc'
# test pkg-config
'$(TARGET)-g++' \
-W -Wall -Werror -pedantic \
'$(SOURCE_DIR)/tools/curve_keygen.cpp' -o '$(PREFIX)/$(TARGET)/bin/test-$(PKG).exe' \
`'$(TARGET)-pkg-config' $(PKG) --cflags --libs`
# test cmake
mkdir '$(BUILD_DIR).test-cmake'
cd '$(BUILD_DIR).test-cmake' && '$(TARGET)-cmake' \
-DPKG=$(PKG) \
-DPKG_VERSION=$($(PKG)_VERSION) \
'$(PWD)/src/cmake/test'
$(MAKE) -C '$(BUILD_DIR).test-cmake' -j 1 install
endef