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/27 13:16:29 UTC
[rocketmq-clients] branch cpp_cmake updated: Support build with cmake
This is an automated email from the ASF dual-hosted git repository.
lizhanhui pushed a commit to branch cpp_cmake
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git
The following commit(s) were added to refs/heads/cpp_cmake by this push:
new 62440cc Support build with cmake
62440cc is described below
commit 62440ccb56e14ebd80e378fda5a31182b55709e5
Author: Li Zhanhui <li...@gmail.com>
AuthorDate: Wed Jul 27 21:16:20 2022 +0800
Support build with cmake
---
cpp/CMakeLists.txt | 12 +++++++++++-
cpp/examples/CMakeLists.txt | 6 ++++++
cpp/source/CMakeLists.txt | 15 +++++++++++++--
cpp/third_party/fmt/9.0.0/CMakeLists.txt | 3 ++-
4 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index 7ee3d4a..031130c 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.19)
project(rocketmq)
set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(gRPC_DEBUG ON)
@@ -20,4 +21,13 @@ target_include_directories(api INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_subdirectory(third_party)
-add_subdirectory(source)
\ No newline at end of file
+add_subdirectory(source)
+
+option(BUILD_EXAMPLES "Build example programs or not" ON)
+if (BUILD_EXAMPLES)
+ message("Would build examples")
+ # Assume gflags is install in $HOME/gflags
+ list(APPEND CMAKE_PREFIX_PATH $ENV{HOME}/gflags)
+ find_package(gflags REQUIRED)
+ add_subdirectory(examples)
+endif ()
\ No newline at end of file
diff --git a/cpp/examples/CMakeLists.txt b/cpp/examples/CMakeLists.txt
new file mode 100644
index 0000000..16e3ef3
--- /dev/null
+++ b/cpp/examples/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_executable(example_producer ExampleProducer.cpp)
+target_link_libraries(example_producer
+ PRIVATE
+ api
+ gflags
+ rocketmq)
\ No newline at end of file
diff --git a/cpp/source/CMakeLists.txt b/cpp/source/CMakeLists.txt
index 8973fb4..bb855b6 100644
--- a/cpp/source/CMakeLists.txt
+++ b/cpp/source/CMakeLists.txt
@@ -8,7 +8,7 @@ add_subdirectory(stats)
add_subdirectory(trace)
add_subdirectory(rocketmq)
-add_library(rocketmq
+add_library(rocketmq STATIC
$<TARGET_OBJECTS:admin>
$<TARGET_OBJECTS:base>
$<TARGET_OBJECTS:client>
@@ -17,4 +17,15 @@ add_library(rocketmq
$<TARGET_OBJECTS:rocketmq_stats>
$<TARGET_OBJECTS:rocketmq_trace>
$<TARGET_OBJECTS:impl>
- $<TARGET_OBJECTS:scheduler>)
\ No newline at end of file
+ $<TARGET_OBJECTS:scheduler>)
+
+target_link_libraries(rocketmq
+ PUBLIC
+ absl::base
+ gRPC::grpc++
+ fmt
+ proto
+ opencensus::trace
+ opencensus::stats
+ opencensus_proto
+ spdlog)
\ No newline at end of file
diff --git a/cpp/third_party/fmt/9.0.0/CMakeLists.txt b/cpp/third_party/fmt/9.0.0/CMakeLists.txt
index b0afeb6..e1caf37 100644
--- a/cpp/third_party/fmt/9.0.0/CMakeLists.txt
+++ b/cpp/third_party/fmt/9.0.0/CMakeLists.txt
@@ -1,4 +1,5 @@
add_library(fmt INTERFACE)
target_include_directories(fmt
INTERFACE
- ${CMAKE_CURRENT_SOURCE_DIR}/include)
\ No newline at end of file
+ ${CMAKE_CURRENT_SOURCE_DIR}/include)
+target_compile_definitions(fmt INTERFACE FMT_HEADER_ONLY)
\ No newline at end of file