Skip to content

Commit 62e59ef

Browse files
yujun411522kiviyu
authored andcommitted
Docs: add cmake install
1 parent daa9de2 commit 62e59ef

File tree

3 files changed

+142
-1
lines changed

3 files changed

+142
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Test
1919
run: |
2020
./clean.sh
21-
bazel coverage //trpc/... --test_output=all --coverage_report_generator="@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main" --combined_report=lcov --nocache_test_results
21+
bazel coverage //trpc/... --test_output=errors --coverage_report_generator="@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main" --combined_report=lcov --nocache_test_results
2222
- name: Upload coverage reports to Codecov
2323
uses: codecov/codecov-action@v3
2424
env:

docs/en/setup_env.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,72 @@ Since the FetchContent feature of CMake is required for fetching third-party dep
8282
./run_examples_cmake.sh
8383
```
8484

85+
3. **How to use tRPC-Cpp**
86+
87+
a. (Recommend) Use as external source code
88+
89+
We recommend this as it can easily switch tRPC-Cpp version to the lastest and the libs framework depends on can also be imported via a simple SDK target named `trpc`.
90+
91+
For example, you can import in CMakeLists.txt in this way:
92+
93+
```shell
94+
# Fetch tRPC-Cpp and add as library
95+
include(FetchContent)
96+
FetchContent_Declare(
97+
trpc-cpp
98+
GIT_REPOSITORY https://git.woa.com/trpc-cpp/open-source/trpc-cpp.git
99+
GIT_TAG recommanded_always_use_latest_tag
100+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake_third_party/trpc-cpp
101+
)
102+
FetchContent_MakeAvailable(trpc-cpp)
103+
104+
# Set path of stub code genretated tool(PROTOBUF_PROTOC_EXECUTABLE/TRPC_TO_CPP_PLUGIN will be filled after you import tRPC-Cpp)
105+
set(PB_PROTOC ${PROTOBUF_PROTOC_EXECUTABLE})
106+
set(TRPC_CPP_PLUGIN ${TRPC_TO_CPP_PLUGIN})
107+
108+
# link lib trpc to your target
109+
target_link_libraries(your_cmake_target trpc)
110+
```
111+
112+
b. Use via make install
113+
114+
Execute below commands, install tRPC-Cpp to your machine first:
115+
116+
```shell
117+
# You can install the lastest verion by: git checkout tags/vx.x.x
118+
git clone https://github.com/trpc-group/trpc-cpp.git
119+
cd trpc-cpp
120+
mkdir build && cd build
121+
122+
# By default, tRPC-Cpp will build as static lib. If you need dynamic lib, add cmake option: -DTRPC_BUILD_SHARED=ON
123+
cmake ..
124+
make -j8
125+
make install # install at /usr/local/trpc-cpp/trpc
126+
```
127+
128+
Then, import trpc lib in your CMakeLists.txt as below:
129+
130+
```shell
131+
# set install path of tRPC-Cpp
132+
set(TRPC_INSTALL_PATH /usr/local/trpc-cpp/trpc)
133+
134+
# Load hearders and libs
135+
include(${TRPC_INSTALL_PATH}/cmake/config/trpc_config.cmake)
136+
include_directories(${INCLUDE_INSTALL_PATHS})
137+
link_directories(${LIBRARY_INSTALL_PATHS})
138+
139+
# Set path of stub code genretated tool
140+
include(${TRPC_INSTALL_PATH}/cmake/tools/trpc_utils.cmake)
141+
set(PB_PROTOC ${TRPC_INSTALL_PATH}/bin/protoc)
142+
set(TRPC_CPP_PLUGIN ${TRPC_INSTALL_PATH}/bin/trpc_cpp_plugin)
143+
144+
# add trpc and it's dependent libs
145+
set(LIBRARY trpc ${LIBS_BASIC})
146+
147+
# link lib trpc to your target
148+
target_link_libraries(your_cmake_target trpc)
149+
```
150+
85151
## Ubuntu
86152

87153
It recommend using **Ubuntu version 20.04 LTS or above** for compiling and running tRPC-Cpp.
@@ -145,6 +211,10 @@ Since the FetchContent feature of CMake is required for fetching third-party dep
145211
./run_examples_cmake.sh
146212
```
147213

214+
3. **How to use tRPC-Cpp**
215+
216+
Same as CentOS section
217+
148218
# FAQ
149219

150220
## bazel --version" shows a "command not found" error?

docs/zh/setup_env.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,72 @@ bazel 推荐使用 3.5.1及以后版本。
8585
./run_examples_cmake.sh
8686
```
8787

88+
3. **如何引入tRPC-Cpp**
89+
90+
a. (推荐)以外部库形式源码引入
91+
92+
推荐使用这种方式,因为能很方便切换框架的版本,同时,框架相关依赖可随构建的SDK目标引入。
93+
94+
参考如下示例,在您项目的 CMakeLists.txt 以外部库源码方式引入:
95+
96+
```shell
97+
# 拉取并以库的形式添加tRPC-Cpp
98+
include(FetchContent)
99+
FetchContent_Declare(
100+
trpc-cpp
101+
GIT_REPOSITORY https://git.woa.com/trpc-cpp/open-source/trpc-cpp.git
102+
GIT_TAG recommanded_always_use_latest_tag
103+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake_third_party/trpc-cpp
104+
)
105+
FetchContent_MakeAvailable(trpc-cpp)
106+
107+
# 设置proto文件桩代码生成工具的路径(PROTOBUF_PROTOC_EXECUTABLE/TRPC_TO_CPP_PLUGIN将会在tRPC-Cpp被引入后自动填充)
108+
set(PB_PROTOC ${PROTOBUF_PROTOC_EXECUTABLE})
109+
set(TRPC_CPP_PLUGIN ${TRPC_TO_CPP_PLUGIN})
110+
111+
# 在您的构建目标里link trpc库
112+
target_link_libraries(your_cmake_target trpc)
113+
```
114+
115+
b. 通过make install引入
116+
117+
参考如下命令,先安装trpc到系统里:
118+
119+
```shell
120+
# 可checkout切换到最新的版本
121+
git clone https://github.com/trpc-group/trpc-cpp.git
122+
cd trpc-cpp
123+
mkdir build && cd build
124+
125+
# 默认编译静态库,可以通过cmake选项编译动态库: -DTRPC_BUILD_SHARED=ON
126+
cmake ..
127+
make -j8
128+
make install
129+
```
130+
131+
然后,参考如下步骤,在您项目的 CMakeLists.txt 里,引入trpc库:
132+
133+
```shell
134+
# 设置tRPC-Cpp的安装位置
135+
set(TRPC_INSTALL_PATH /usr/local/trpc-cpp/trpc)
136+
137+
# 加载tRPC-Cpp头文件及库路径
138+
include(${TRPC_INSTALL_PATH}/cmake/config/trpc_config.cmake)
139+
include_directories(${INCLUDE_INSTALL_PATHS})
140+
link_directories(${LIBRARY_INSTALL_PATHS})
141+
142+
# 设置proto文件桩代码生成工具的路径 - 具体使用方式见相关章节
143+
include(${TRPC_INSTALL_PATH}/cmake/tools/trpc_utils.cmake)
144+
set(PB_PROTOC ${TRPC_INSTALL_PATH}/bin/protoc)
145+
set(TRPC_CPP_PLUGIN ${TRPC_INSTALL_PATH}/bin/trpc_cpp_plugin)
146+
147+
# 添加trpc库及其依赖的三方
148+
set(LIBRARY trpc ${LIBS_BASIC})
149+
150+
# 在您的构建目标里link trpc库
151+
target_link_libraries(your_cmake_target trpc)
152+
```
153+
88154
## Ubuntu
89155

90156
推荐**Ubuntu 版本在 20.04 LTS 及以上版本**
@@ -155,6 +221,11 @@ bazel 推荐使用3.5.1及以后版本。
155221
./run_examples_cmake.sh
156222
```
157223

224+
3. **安装及使用**
225+
226+
同CentOS 部分。
227+
228+
158229
# FAQ
159230

160231
## bazel --version 出现找不到 bazel 命令?

0 commit comments

Comments
 (0)