[Doc] Added C++17 cmake option (#38432)

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #38432

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/38432 from veblush:cpp17-doc 4c7dce0783
PiperOrigin-RevId: 714143397
This commit is contained in:
Esun Kim
2025-01-10 12:48:18 -08:00
committed by Copybara-Service
parent 4e5f413a43
commit 02fb4b5804
3 changed files with 27 additions and 6 deletions

View File

@@ -126,7 +126,7 @@ Run from the grpc directory after cloning the repo with --recursive or updating
```
$ mkdir -p cmake/build
$ cd cmake/build
$ cmake ../..
$ cmake -DCMAKE_CXX_STANDARD=17 ../..
$ make
```
@@ -143,7 +143,7 @@ you will be able to browse and build the code.
> @rem Run from grpc directory after cloning the repo with --recursive or updating submodules.
> md .build
> cd .build
> cmake .. -G "Visual Studio 17 2022"
> cmake -G "Visual Studio 17 2022" -DCMAKE_CXX_STANDARD=17 ..
> cmake --build . --config Release
```
@@ -159,7 +159,7 @@ installed to be able to compile the C/C++ sources.
> md build
> cd build
> call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x64
> cmake ..\.. -GNinja -DCMAKE_BUILD_TYPE=Release
> cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 ..\..
> cmake --build .
```
@@ -174,6 +174,15 @@ at your own risk.
- you've been warned that there are some important drawbacks and some things might not work at all or will be broken in interesting ways.
- we don't have extensive testing for DLL builds in place (to avoid maintenance costs, increased test duration etc.) so regressions / build breakages might occur
### Consistent standard C++ version
To avoid build errors when building gRPC and its dependencies (especially from gRPC C++ 1.70 onwards),
ensure all CMake builds use the same C++ standard (at least C++17).
This is crucial because gRPC C++ 1.70 requires at least C++17, and Abseil, a gRPC dependency,
provides different APIs based on the C++ version.
For instance, `absl::string_view` is implemented differently before and after C++17.
Using a consistent C++ version prevents inconsistencies and ensures compatibility across the project.
### Dependency management
gRPC's CMake build system has two options for handling dependencies.
@@ -217,6 +226,7 @@ how to install dependencies with cmake before proceeding to installing gRPC itse
# NOTE: all of gRPC's dependencies need to be already installed
$ cmake ../.. -DgRPC_INSTALL=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_STANDARD=17 \
-DgRPC_ABSL_PROVIDER=package \
-DgRPC_CARES_PROVIDER=package \
-DgRPC_PROTOBUF_PROVIDER=package \

View File

@@ -53,7 +53,7 @@ Once the prerequisites are satisfied, you can build with cmake:
```
$ mkdir -p cmake/build
$ cd cmake/build
$ cmake -DgRPC_BUILD_TESTS=ON ../..
$ cmake -DgRPC_BUILD_TESTS=ON -DCMAKE_CXX_STANDARD=17 ../..
$ make grpc_cli
```

View File

@@ -30,10 +30,10 @@ Therefore, gRPC supports several major build systems, which should satisfy most
| Operating System | Architectures | Versions | Support Level |
|------------------|---------------|----------|---------------|
| Linux - Debian, Ubuntu, CentOS | x86, x64 | clang 7+, GCC 7.3+ | Officially Supported |
| Linux - Debian, Ubuntu, CentOS | x86, x64 | clang 7+, GCC 7.5+ | Officially Supported |
| Windows 10+ | x86, x64 | Visual Studio 2022+ | Officially Supported |
| MacOS | x64, ARM64 | XCode 12+ | Officially Supported |
| Linux - Others | x86, x64 | clang 7+, GCC 7.3+ | Best Effort |
| Linux - Others | x86, x64 | clang 7+, GCC 7.5+ | Best Effort |
| Linux | ARM64 | | Best Effort |
| iOS | | | Best Effort |
| Android | | | Best Effort |
@@ -77,6 +77,17 @@ can be used for targeting the Android platform.
To build gRPC C++ from source, follow the [BUILDING guide](../../BUILDING.md).
To ensure all libraries in your CMake project compile with the same C++ version
(e.g., C++17), explicitly specify the standard:
```cmake
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
```
This configuration enforces the use of C++17 for all targets and avoids potential
inconsistencies or errors due to different C++ versions being used.
### find_package
The canonical way to discover dependencies in CMake is the