Skip to content

Commit 7a6c904

Browse files
committed
Problem: Examples are not compiled
Solution: Compile the examples when tests are compiled and using C++11 or greater.
1 parent 03243ad commit 7a6c904

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,7 @@ option(CPPZMQ_BUILD_TESTS "Whether or not to build the tests" ON)
101101
if (CPPZMQ_BUILD_TESTS)
102102
enable_testing()
103103
add_subdirectory(tests)
104+
if (CMAKE_CXX_STANDARD AND NOT CMAKE_CXX_STANDARD EQUAL 98 AND CMAKE_CXX_STANDARD GREATER_EQUAL 11)
105+
add_subdirectory(examples)
106+
endif()
104107
endif()

examples/CMakeLists.txt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
2+
3+
project(cppzmq-examples CXX)
4+
5+
# place binaries and libraries according to GNU standards
6+
7+
include(GNUInstallDirs)
8+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
9+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
10+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
11+
12+
find_package(Threads)
13+
14+
add_executable(
15+
pubsub_multithread_inproc
16+
pubsub_multithread_inproc.cpp
17+
)
18+
19+
target_link_libraries(
20+
pubsub_multithread_inproc
21+
PRIVATE cppzmq
22+
PRIVATE ${CMAKE_THREAD_LIBS_INIT}
23+
)

examples/pubsub_multithread_inproc.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ void SubscriberThread1(zmq::context_t *ctx) {
4040
zmq::recv_result_t result =
4141
zmq::recv_multipart(subscriber, std::back_inserter(recv_msgs));
4242
assert(result && "recv failed");
43+
assert(*result == 2);
4344

44-
std::cout << "Thread2: [" << recv_msgs[0].to_string_view() << "] "
45-
<< recv_msgs[1].to_string_view() << std::endl;
45+
std::cout << "Thread2: [" << recv_msgs[0].to_string() << "] "
46+
<< recv_msgs[1].to_string() << std::endl;
4647
}
4748
}
4849

@@ -60,9 +61,10 @@ void SubscriberThread2(zmq::context_t *ctx) {
6061
zmq::recv_result_t result =
6162
zmq::recv_multipart(subscriber, std::back_inserter(recv_msgs));
6263
assert(result && "recv failed");
64+
assert(*result == 2);
6365

64-
std::cout << "Thread3: [" << recv_msgs[0].to_string_view() << "] "
65-
<< recv_msgs[1].to_string_view() << std::endl;
66+
std::cout << "Thread3: [" << recv_msgs[0].to_string() << "] "
67+
<< recv_msgs[1].to_string() << std::endl;
6668
}
6769
}
6870

0 commit comments

Comments
 (0)