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

lizhimins 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 9c9ce3c3 [C++] Add CMake install/uninstall support and enable tests in 
CI (#1297)
9c9ce3c3 is described below

commit 9c9ce3c3467ae6754228aac0bb3fc815dd00c506
Author: lizhimins <[email protected]>
AuthorDate: Thu Jul 9 20:54:54 2026 +0800

    [C++] Add CMake install/uninstall support and enable tests in CI (#1297)
---
 .github/workflows/cpp_build.yml    |  3 +-
 .github/workflows/cpp_coverage.yml |  3 +-
 .licenserc.yaml                    |  1 +
 cpp/.bazelignore                   |  1 +
 cpp/CMakeLists.txt                 | 66 +++++++++++++++++++++++++++++++++++---
 cpp/cmake/cmake_uninstall.cmake.in | 23 +++++++++++++
 cpp/cmake/rocketmq-config.cmake.in | 10 ++++++
 cpp/source/CMakeLists.txt          | 11 +++++--
 8 files changed, 109 insertions(+), 9 deletions(-)

diff --git a/.github/workflows/cpp_build.yml b/.github/workflows/cpp_build.yml
index ef3bfb32..066b4201 100644
--- a/.github/workflows/cpp_build.yml
+++ b/.github/workflows/cpp_build.yml
@@ -65,7 +65,8 @@ jobs:
             -DCMAKE_BUILD_TYPE=Release \
             -DCMAKE_PREFIX_PATH="$TEMP_DIR/grpc-install" \
             -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-            -DBUILD_EXAMPLES=OFF
+            -DBUILD_EXAMPLES=OFF \
+            -DBUILD_TESTS=ON
           cmake --build build --parallel 4 --config Release
 
       - name: Run Unit Tests
diff --git a/.github/workflows/cpp_coverage.yml 
b/.github/workflows/cpp_coverage.yml
index 41521112..9d3c65fa 100644
--- a/.github/workflows/cpp_coverage.yml
+++ b/.github/workflows/cpp_coverage.yml
@@ -45,7 +45,8 @@ jobs:
             -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
             -DCMAKE_C_FLAGS="--coverage" \
             -DCMAKE_CXX_FLAGS="--coverage" \
-            -DBUILD_EXAMPLES=OFF
+            -DBUILD_EXAMPLES=OFF \
+            -DBUILD_TESTS=ON
           cmake --build build --parallel 4
 
       - name: Run tests
diff --git a/.licenserc.yaml b/.licenserc.yaml
index a0c25620..1312dfc6 100644
--- a/.licenserc.yaml
+++ b/.licenserc.yaml
@@ -47,6 +47,7 @@ header:
     - 'cpp/.clang-tidy'
     - 'cpp/WORKSPACE'
     - 'cpp/.gitignore'
+    - 'cpp/.bazelignore'
     - 'cpp/third_party'
     - 'cpp/proto/**'
     - 'cpp/cmake'
diff --git a/cpp/.bazelignore b/cpp/.bazelignore
new file mode 100644
index 00000000..378eac25
--- /dev/null
+++ b/cpp/.bazelignore
@@ -0,0 +1 @@
+build
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index 444e2ceb..bbde66a3 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -1,13 +1,15 @@
 cmake_minimum_required(VERSION 3.16)
-project(rocketmq)
+project(rocketmq VERSION 5.1.0 LANGUAGES CXX)
 set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 
+include(GNUInstallDirs)
 list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
-find_package(protobuf CONFIG REQUIRED)
-find_package(gRPC CONFIG REQUIRED)
+# Minimum versions aligned with the gRPC 1.46.x dependency chain (gRPC 1.46 
bundles protobuf 3.19)
+find_package(protobuf 3.19 CONFIG REQUIRED)
+find_package(gRPC 1.46 CONFIG REQUIRED)
 find_package(absl REQUIRED)
-find_package(OpenSSL REQUIRED)
+find_package(OpenSSL 1.1 REQUIRED)
 
 if(NOT EXISTS 
"${CMAKE_CURRENT_SOURCE_DIR}/proto/apache/rocketmq/v2/definition.proto")
     message(FATAL_ERROR "Proto files not found. Run: git submodule update 
--init --recursive")
@@ -28,7 +30,7 @@ if (BUILD_EXAMPLES)
     add_subdirectory(examples)
 endif ()
 
-option(BUILD_TESTS "Build unit tests or not" ON)
+option(BUILD_TESTS "Build unit tests or not" OFF)
 if (BUILD_TESTS)
     enable_testing()
     include(FetchContent)
@@ -68,3 +70,57 @@ if (BUILD_TESTS)
     add_subdirectory(source/scheduler/tests)
     add_subdirectory(source/stats/tests)
 endif ()
+
+# Install targets
+
+include(CMakePackageConfigHelpers)
+
+# Shared library: self-contained, exported for downstream find_package()
+# Note: static library (rocketmq) is not installed — on Windows its .lib
+# would collide with the shared library's import library (also .lib).
+install(TARGETS rocketmq_shared
+    EXPORT rocketmq-targets
+    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+)
+
+install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/rocketmq
+    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
+    FILES_MATCHING PATTERN "*.h"
+    PATTERN "Tracing.h" EXCLUDE
+)
+
+install(EXPORT rocketmq-targets
+    FILE rocketmq-targets.cmake
+    NAMESPACE rocketmq::
+    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/rocketmq
+)
+
+configure_package_config_file(
+    ${CMAKE_CURRENT_SOURCE_DIR}/cmake/rocketmq-config.cmake.in
+    ${CMAKE_CURRENT_BINARY_DIR}/rocketmq-config.cmake
+    INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/rocketmq
+)
+write_basic_package_version_file(
+    ${CMAKE_CURRENT_BINARY_DIR}/rocketmq-config-version.cmake
+    VERSION ${PROJECT_VERSION}
+    COMPATIBILITY SameMajorVersion
+)
+install(FILES
+    ${CMAKE_CURRENT_BINARY_DIR}/rocketmq-config.cmake
+    ${CMAKE_CURRENT_BINARY_DIR}/rocketmq-config-version.cmake
+    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/rocketmq
+)
+
+# Uninstall target
+if(NOT TARGET uninstall)
+    configure_file(
+        "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
+        "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
+        IMMEDIATE @ONLY
+    )
+    add_custom_target(uninstall
+        COMMAND ${CMAKE_COMMAND} -P 
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
+    )
+endif()
diff --git a/cpp/cmake/cmake_uninstall.cmake.in 
b/cpp/cmake/cmake_uninstall.cmake.in
new file mode 100644
index 00000000..1bf01a33
--- /dev/null
+++ b/cpp/cmake/cmake_uninstall.cmake.in
@@ -0,0 +1,23 @@
+if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
+    message(FATAL_ERROR "Cannot find install manifest: 
@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
+endif()
+
+file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
+string(REGEX REPLACE "\n$" "" files "${files}")
+string(REGEX REPLACE "\n" ";" files "${files}")
+list(REVERSE files)
+foreach(file ${files})
+    message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
+    if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+        execute_process(
+            COMMAND "@CMAKE_COMMAND@" -E remove "$ENV{DESTDIR}${file}"
+            OUTPUT_VARIABLE rm_out
+            RESULT_VARIABLE rm_retval
+        )
+        if(NOT "${rm_retval}" STREQUAL 0)
+            message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
+        endif()
+    else()
+        message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
+    endif()
+endforeach()
diff --git a/cpp/cmake/rocketmq-config.cmake.in 
b/cpp/cmake/rocketmq-config.cmake.in
new file mode 100644
index 00000000..17619fa6
--- /dev/null
+++ b/cpp/cmake/rocketmq-config.cmake.in
@@ -0,0 +1,10 @@
+@PACKAGE_INIT@
+
+include(CMakeFindDependencyMacro)
+
+find_dependency(absl)
+find_dependency(gRPC)
+
+include("${CMAKE_CURRENT_LIST_DIR}/rocketmq-targets.cmake")
+
+check_required_components(rocketmq)
diff --git a/cpp/source/CMakeLists.txt b/cpp/source/CMakeLists.txt
index d860f8e4..dda06faa 100644
--- a/cpp/source/CMakeLists.txt
+++ b/cpp/source/CMakeLists.txt
@@ -47,12 +47,17 @@ target_link_libraries(rocketmq_shared
         PUBLIC
             absl::base
             gRPC::grpc++
+            $<BUILD_INTERFACE:opencensus::trace>
+        PRIVATE
             fmt
             proto
-            opencensus::trace
             opencensus::stats
             opencensus_proto
             spdlog)
+target_include_directories(rocketmq_shared
+        PUBLIC
+            $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
+            $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
     set(VERSION_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/exports.map)
     set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} 
-Wl,--version-script=${VERSION_SCRIPT}")
@@ -62,5 +67,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
 endif()
 set_target_properties(rocketmq_shared
         PROPERTIES
+            VERSION ${PROJECT_VERSION}
+            SOVERSION ${PROJECT_VERSION_MAJOR}
             LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
-            LIBRARY_OUTPUT_NAME rocketmq)
\ No newline at end of file
+            LIBRARY_OUTPUT_NAME rocketmq)

Reply via email to