Skip to content

build(cmake): Modernize target-scoped CMake configuration#3377

Merged
chenBright merged 2 commits into
apache:masterfrom
darion-yaphet:update-cmake-minimum
Jul 11, 2026
Merged

build(cmake): Modernize target-scoped CMake configuration#3377
chenBright merged 2 commits into
apache:masterfrom
darion-yaphet:update-cmake-minimum

Conversation

@darion-yaphet

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: N/A

Problem Summary:
The CMake build files still rely on legacy global include directories, compile flags, and duplicated per-example configuration. This makes target behavior harder to
reason about and causes standalone examples/tests to drift from the main build configuration.

What is changed and the side effects?

Changed:

  • Modernize top-level, src, tools, and test CMake targets with target-scoped configuration.
  • Add shared brpc_common_config for common compile definitions, include paths, options, and features.
  • Refactor standalone example CMake files to use example/cmake/BrpcExample.cmake.
  • Update the gtest download helper to use CMake 3.16...3.28.
  • Ensure downloaded gtest headers take priority over Homebrew's C++17-only gtest headers during unit-test builds.

Side effects:

  • Standalone examples now consistently require CMake 3.16 or newer, matching the main project requirement.

  • DOWNLOAD_GTEST=ON creates a copied gtest include directory in the test build tree to avoid header conflicts with system-installed gtest.

  • Performance effects:
    No runtime performance impact expected. This is a build-system-only change.

  • Breaking backward compatibility:
    No source/API compatibility break expected. Users building standalone examples with CMake older than 3.16 will need to upgrade CMake.


Check List:

Verification

Passed:

  • cmake -S . -B build -DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl@3
  • cmake --build build -j6
  • cmake -S . -B build-tests -DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl@3 -DBUILD_UNIT_TESTS=ON -DDOWNLOAD_GTEST=ON
  • cmake --build build-tests -j6
  • Standalone example smoke builds for echo_c++, http_c++, and memcache_c++

Known macOS arm64 test issues:

  • test_butil fails in StackTraceTest.find_symbol
  • bthread_fd_unittest fails in FDTest.ping_pong
  • rdma_performance standalone example was not tested because ibverbs is unavailable on macOS

Raise the minimum CMake version range to 3.16...3.28 so CMake 4.x no longer treats the project as relying on removed pre-3.5 policy compatibility. The range preserves a conservative 3.16 runtime floor while documenting policy validation through 3.28.
Move shared compile definitions, include paths, options, and link dependencies onto interface targets so top-level, src, tools, tests, and standalone examples consume consistent build settings without relying on global directory state.

Examples now share a small CMake helper, and the gtest download path is updated to configure with modern CMake while keeping downloaded gtest headers ahead of Homebrew's C++17-only installation.
Comment thread CMakeLists.txt

@chenBright chenBright left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chenBright chenBright merged commit 82a6819 into apache:master Jul 11, 2026
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants