build(cmake): Modernize target-scoped CMake configuration#3377
build(cmake): Modernize target-scoped CMake configuration#3377darion-yaphet wants to merge 2 commits into
Conversation
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.
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| cmake_minimum_required(VERSION 2.8.12) |
There was a problem hiding this comment.
The upgraded version seems too high, is it necessary?
There was a problem hiding this comment.
The upgraded version seems too high, is it necessary?
I understand the concern about compatibility, but CMake 3.16 is actually not very radical. CMake 2.x was quite an old era. The main line has moved to 4.x now, and CMake 3 is the mainstream baseline for many years past.
The main benefits of upgrading to CMake 3 are not "keeping up with the latest trends", but rather the ability to use modern CMake syntax: target-based configuration, target_compile_features, target_link_options, generator expressions, better dependency discovery and cross-platform behavior. These features can avoid the pollution of global CFLAGS/LDFLAGS, allowing includes, macro definitions, and link parameters to be propagated by target. This makes the project easier to maintain and less likely to fail due to differences in the local environment.
Overall, 3.16 represents a relatively conservative modern baseline, not a radical upgrade.
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:
src,tools, andtestCMake targets with target-scoped configuration.brpc_common_configfor common compile definitions, include paths, options, and features.example/cmake/BrpcExample.cmake.3.16...3.28.Side effects:
Standalone examples now consistently require CMake 3.16 or newer, matching the main project requirement.
DOWNLOAD_GTEST=ONcreates 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@3cmake --build build -j6cmake -S . -B build-tests -DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl@3 -DBUILD_UNIT_TESTS=ON -DDOWNLOAD_GTEST=ONcmake --build build-tests -j6echo_c++,http_c++, andmemcache_c++Known macOS arm64 test issues:
test_butilfails inStackTraceTest.find_symbolbthread_fd_unittestfails inFDTest.ping_pongrdma_performancestandalone example was not tested becauseibverbsis unavailable on macOS