Fix CMake protobuf include order by songgaoye · Pull Request #3612 · apache/brpc · GitHub
Skip to content

Fix CMake protobuf include order - #3612

Open
songgaoye wants to merge 5 commits into
apache:masterfrom
songgaoye:fix-cmake-protobuf-include-order
Open

songgaoye wants to merge 5 commits into
apache:masterfrom
songgaoye:fix-cmake-protobuf-include-order

Conversation

@songgaoye

@songgaoye songgaoye commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: resolve

Problem Summary:

CMake may select one Protobuf installation while a generic include prefix
(for example /usr/local/include) is searched first. If that prefix contains
headers from a different Protobuf version, brpc can compile against headers
that do not match the selected Protobuf libraries.

This PR makes the selected Protobuf include directories take precedence for
the module-owned build targets.

What is changed and the side effects?

Changed:

  • Add Protobuf_INCLUDE_DIRS to butil_build_config before generic dependency
    include directories.
  • Preserve the generated in-tree brpc headers as the highest-priority include
    directory.
  • Add a CMake regression test that verifies selected Protobuf include
    directories precede generic include directories.

Side effects:

  • Builds that expose conflicting Protobuf headers through generic prefixes now
    consistently use the Protobuf installation selected by find_package.
  • This does not make arbitrary mixed-version dependency prefixes safe; those
    still need to be managed by the build environment.

Breaking backward compatibility:

None.


@chenBright
chenBright requested a lite review from Copilot October 15, 2026 06:05

Copilot AI 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.

🟢 Approval recommended

The focused include-order change addresses the reported header mismatch without an identified issue.

0 open findings

What changed in this PR

This PR adjusts CMake header search order so builds use headers from the selected protobuf installation.

Changes:

  • Places generated headers first, followed by the selected protobuf headers and then general dependency headers.
File Description
CMakeLists.txt Updates brpc_common_config include order.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@darion-yaphet

Copy link
Copy Markdown
Contributor

Thanks, moving protobuf ahead of the generic dependency prefixes looks right. Two small things before merging:

  1. src/ now comes after protobuf. If protobuf sits in a shared prefix that also has an installed brpc, the installed butil//brpc/ headers will shadow the in-tree ones.

  2. The test targets aren't covered yet. test/CMakeLists.txt:29 adds GPERFTOOLS_INCLUDE_DIR directly to brpc_test_config, so /opt/homebrew/include is still searched before protobuf when building unit tests. macOS CI doesn't build the tests, so it won't catch this.

@songgaoye
songgaoye force-pushed the fix-cmake-protobuf-include-order branch 2 times, most recently from 68a556d to 187327f Compare October 16, 2026 09:25
@songgaoye

Copy link
Copy Markdown
Contributor Author

Thank you! @darion-yaphet

@songgaoye
songgaoye force-pushed the fix-cmake-protobuf-include-order branch from 187327f to 500c13a Compare October 18, 2026 01:00
@wwbmmm
wwbmmm requested a lite review from Copilot October 18, 2026 02:12

Copilot AI 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.

🟡 Changes recommended

Correct the test include ordering to ensure freshly generated headers take precedence.

1 open issue

Review effort: Lite

Comment thread test/CMakeLists.txt Outdated

Copilot AI 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.

🟢 Approval recommended

No unresolved issues were identified, and all assessments support approval.

No open issues 🎉

1 resolved since last review

Review effort: Lite

@wasphin

wasphin commented Oct 20, 2026

Copy link
Copy Markdown
Member

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.

4 participants