You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by li...@apache.org on 2022/07/28 02:57:20 UTC

[rocketmq-clients] branch master updated: Polish readme and build examples with cmake (#78)

This is an automated email from the ASF dual-hosted git repository.

lizhanhui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git


The following commit(s) were added to refs/heads/master by this push:
     new 13c1426  Polish readme and build examples with cmake (#78)
13c1426 is described below

commit 13c14264d45b8ae5b96ff3d89995c880181613b7
Author: Zhanhui Li <li...@gmail.com>
AuthorDate: Thu Jul 28 10:57:15 2022 +0800

    Polish readme and build examples with cmake (#78)
---
 cpp/README.md               | 29 +++++++++++++++++++++++++++++
 cpp/examples/CMakeLists.txt | 18 ++++++++++++------
 cpp/source/CMakeLists.txt   | 30 +++++++++++++++++++++++++++++-
 3 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/cpp/README.md b/cpp/README.md
index be1a1d0..a0a04c4 100644
--- a/cpp/README.md
+++ b/cpp/README.md
@@ -44,6 +44,8 @@ if "com_google_googletest" not in native.existing_rules():
 ```
 
 ### How To Build
+
+#### Build with Bazel
 [Google Bazel](https://bazel.build/) is the primary build tool we supported, Please follow [bazel installation guide](https://docs.bazel.build/versions/main/install.html).
 
 
@@ -58,7 +60,34 @@ if "com_google_googletest" not in native.existing_rules():
    bazel test //...
    ```
 
+#### Build with CMake
+1. Make sure you have installed a modern CMake 3.13+ and C++ compilation toolchain that at least supports C++11;
+
+2. Following [gRPC installation instructions](https://grpc.io/docs/languages/cpp/quickstart/) to install grpc.
+
+   Note: Remember to `export MY_INSTALL_DIR=$HOME/grpc` as our primary CMakeLists.txt hints 
+   ```cmake
+   list(APPEND CMAKE_PREFIX_PATH $ENV{HOME}/grpc)
+   ```
+   If your grpc is installed somewhere else yet non-standard, please adjust accordingly.
+
+3. Example programs uses [gflags](https://github.com/gflags/gflags) to parse command arguments. Please install it to $HOME/gflags
+   as CMakeLists.txt has the following find package statements
+   ```cmake
+    # Assume gflags is install in $HOME/gflags
+    list(APPEND CMAKE_PREFIX_PATH $ENV{HOME}/gflags)
+    find_package(gflags REQUIRED)
+   ```
+   
+4. OpenSSL development package is also required. 
 
+5. Run the following commands to build from ${YOUR_GIT_REPOSITORY}/cpp directory
+   ```shell
+   mkdir build && cd build
+   cmake -DOPENSSL_ROOT_DIR=/usr/local/Cellar/openssl@1.1/1.1.1q ..
+   make -j $(nproc)
+   ```
+6. Static archive and dynamic linked libraries are found in the build directory.
 
 ### Run Examples
 
diff --git a/cpp/examples/CMakeLists.txt b/cpp/examples/CMakeLists.txt
index 16e3ef3..b19c65e 100644
--- a/cpp/examples/CMakeLists.txt
+++ b/cpp/examples/CMakeLists.txt
@@ -1,6 +1,12 @@
-add_executable(example_producer ExampleProducer.cpp)
-target_link_libraries(example_producer
-        PRIVATE
-            api
-            gflags
-            rocketmq)
\ No newline at end of file
+function(add_example name file)
+    add_executable(${name} ${file})
+    target_link_libraries(${name} PRIVATE api gflags rocketmq)
+endfunction()
+
+add_example(example_producer ExampleProducer.cpp)
+add_example(example_producer_with_async ExampleProducerWithAsync.cpp)
+add_example(example_producer_with_fifo_message ExampleProducerWithFifoMessage.cpp)
+add_example(example_producer_with_timed_message ExampleProducerWithTimedMessage.cpp)
+add_example(example_producer_with_transactional_message ExampleProducerWithTransactionalMessage.cpp)
+add_example(example_push_consumer ExamplePushConsumer.cpp)
+add_example(example_simple_consumer ExampleSimpleConsumer.cpp)
\ No newline at end of file
diff --git a/cpp/source/CMakeLists.txt b/cpp/source/CMakeLists.txt
index bb855b6..d42c6a1 100644
--- a/cpp/source/CMakeLists.txt
+++ b/cpp/source/CMakeLists.txt
@@ -28,4 +28,32 @@ target_link_libraries(rocketmq
             opencensus::trace
             opencensus::stats
             opencensus_proto
-            spdlog)
\ No newline at end of file
+            spdlog)
+set_target_properties(rocketmq PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
+
+
+add_library(rocketmq_shared SHARED
+        $<TARGET_OBJECTS:admin>
+        $<TARGET_OBJECTS:base>
+        $<TARGET_OBJECTS:client>
+        $<TARGET_OBJECTS:concurrent>
+        $<TARGET_OBJECTS:log>
+        $<TARGET_OBJECTS:rocketmq_stats>
+        $<TARGET_OBJECTS:rocketmq_trace>
+        $<TARGET_OBJECTS:impl>
+        $<TARGET_OBJECTS:scheduler>)
+
+target_link_libraries(rocketmq_shared
+        PUBLIC
+            absl::base
+            gRPC::grpc++
+            fmt
+            proto
+            opencensus::trace
+            opencensus::stats
+            opencensus_proto
+            spdlog)
+set_target_properties(rocketmq_shared
+        PROPERTIES
+            LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
+            LIBRARY_OUTPUT_NAME rocketmq)
\ No newline at end of file