This directory contains *CMake* files that can be used to build protobuf
with *MSVC* on *Windows*. You can build the project from *Command Prompt*
and using an *Visual Studio* IDE.
You need to have [CMake](http://www.cmake.org), [Visual Studio](https://www.visualstudio.com)
and optionally [Git](http://git-scm.com) installed on your computer before proceeding.
Most of the instructions will be given to the *小ommand Prompt*, but the same
actions can be performed using appropriate GUI tools.
Environment Setup
=================
Open the appropriate *Command Prompt* from the *Start* menu.
For example *x86 Native Tools Command Prompt for VS 2019*:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional>
Change to your working directory:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional>cd C:\Path\to
C:\Path\to>
Where *C:\Path\to* is path to your real working directory.
Create a folder where protobuf headers/libraries/binaries will be installed after built:
C:\Path\to>mkdir install
If *cmake* command is not available from *Command Prompt*, add it to system *PATH* variable:
C:\Path\to>set PATH=%PATH%;C:\Program Files (x86)\CMake\bin
If *git* command is not available from *Command Prompt*, add it to system *PATH* variable:
C:\Path\to>set PATH=%PATH%;C:\Program Files\Git\cmd
Optionally, you will want to download [ninja](https://ninja-build.org/) and add it to your *PATH* variable.
C:\Path\to>set PATH=%PATH%;C:\tools\ninja
Good. Now you are ready to continue.
Getting Sources
===============
You can get the latest stable source packages from the release page:
https://github.com/protocolbuffers/protobuf/releases/latest
For example: if you only need C++, download `protobuf-cpp-[VERSION].tar.gz`; if
you need C++ and Java, download `protobuf-java-[VERSION].tar.gz` (every package
contains C++ source already); if you need C++ and multiple other languages,
download `protobuf-all-[VERSION].tar.gz`.
Or you can use git to clone from protobuf git repository.
C:\Path\to> mkdir src & cd src
C:\Path\to\src> git clone -b [release_tag] https://github.com/protocolbuffers/protobuf.git
Where *[release_tag]* is a git tag like *v3.0.0-beta-1* or a branch name like *main*
if you want to get the latest code.
Go to the project folder:
C:\Path\to\src> cd protobuf
C:\Path\to\src\protobuf>
Remember to update any submodules if you are using git clone (you can skip this
step if you are using a release .tar.gz or .zip package):
```console
C:\Path\to\src\protobuf> git submodule update --init --recursive
```
Good. Now you are ready for *CMake* configuration.
CMake Configuration
===================
*CMake* supports a lot of different
[generators](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html)
for various native build systems.
Of most interest to Windows programmers are the following:
* [Makefile](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#makefile-generators).
This generates NMake Makefiles for Visual Studio. These work, but they are rather slow.
* [Visual Studio](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators)
This generates a Visual Studio solution for the project.
* [Ninja](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#ninja-generator)
This uses the external tool [Ninja](https://ninja-build.org/) to build. It is the fastest solution available.
Note that as of Visual Studio 2015, Visual Studio includes
[support for opening directly CMake-based projects](https://docs.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio).
It is considered good practice not to build CMake projects in the source tree but in a separate folder.
Create a temporary *build* folder and change your working directory to it:
mkdir C:\Path\to\build\protobuf
cd C:\Path\to\build\protobuf
C:\Path\to\build\protobuf>
The *Makefile* and *Ninja* generators can build the project in only one configuration, so you need to build
a separate folder for each configuration.
To start using a *Release* configuration via the *NMmake* generator:
C:\Path\to\build\protobuf>mkdir release & cd release
C:\Path\to\build\protobuf\release>cmake -G "NMake Makefiles" ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
C:\Path\to\src\protobuf
It will generate a *NMake* *Makefile* in the current directory.
To use *Debug* configuration using *Ninja*:
C:\Path\to\build\protobuf>mkdir debug & cd debug
C:\Path\to\build\protobuf\debug>cmake -G "Ninja" ^
-DCMAKE_BUILD_TYPE=Debug ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
C:\Path\to\src\protobuf
It will generate *Ninja* build scripts in current directory.
The *Visual Studio* generator is multi-configuration: it will generate a single *.sln* file that can be used for both *Debug* and *Release*:
C:\Path\to\build\protobuf>mkdir solution & cd solution
C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
C:\Path\to\src\protobuf
It will generate *Visual Studio* solution file *protobuf.sln* in current directory.
Unit Tests
----------
Unit tests are being built along with the rest of protobuf. The unit tests require Google Mock (now a part of Google Test).
A copy of [Google Test](https://github.com/google/googletest) is included as a Git submodule in the `third-party/googletest` folder.
(You do need to initialize the Git submodules as explained above.)
Alternately, you may want to use protobuf in a larger set-up, you may want to use that standard CMake approach where
you build and install a shared copy of Google Test.
After you've built and installed your Google Test copy, you need add the following definition to your *cmake* command line
during the configuration step: `-Dprotobuf_USE_EXTERNAL_GTEST=ON`.
This will cause the standard CMake `find_package(GTest REQUIRED)` to be used.
[find_package](https://cmake.org/cmake/help/latest/command/find_package.html) will search in a default location,
which on Windows is *C:\Program Files*. This is most likely not what you want. You will want instead to search for
Google Test in your project's root directory (i.e. the same directory you've passed to `CMAKE_INSTALL_PREFIX` when
building Google Test). For this, you need to set the `CMAKE_PREFIX_PATH` CMake variable. (There are other ways in CMake,
see the [manual](https://cmake.org/cmake/help/latest/command/find_package.html) for details.)
For example:
C:\Path\to\build\protobuf>mkdir solution & cd solution
C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
-DCMAKE_PREFIX_PATH=C:\Path\to\my_big_project ^
-Dprotobuf_USE_EXTERNAL_GTEST=ON ^
C:\Path\to\src\protobuf
In most cases, `CMAKE_PREFIX_PATH` and `CMAKE_INSTALL_PREFIX` will point to the same directory.
To disable testing completely, you need to add the following argument to you *cmake* command line: `-Dprotobuf_BUILD_TESTS=OFF`.
For example:
C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
-Dprotobuf_BUILD_TESTS=OFF ^
C:\Path\to\src\protobuf
Compiling
=========
The standard way to compile a *CMake* project is `cmake --build <directory>`.
Note that if your generator supports multiple configurations, you will probably want to specify which one to build:
cmake --build C:\Path\to\build\protobuf\solution --config Release
You can also run directly the build tool you've configured:
C:\Path\to\build\protobuf\release>nmake
or
C:\Path\to\build\protobuf\debug>ninja
And wait for the compilation to finish.
If you prefer to use the IDE:
* Open the generated protobuf.sln file in Microsoft Visual Studio.
* Choose "Debug" or "Release" configuration a
没有合适的资源?快使用搜索试试~ 我知道了~
protobuf-python-4.21.8.tar.gz
需积分: 10 1 下载量 95 浏览量
2022-10-27
09:34:48
上传
评论
收藏 4.98MB GZ 举报
温馨提示
共1159个文件
cc:384个
h:306个
proto:110个
alpha go相关工具
资源推荐
资源详情
资源评论
收起资源包目录
protobuf-python-4.21.8.tar.gz (1159个子文件)
configure.ac 8KB
configure.ac 6KB
configure.ac 3KB
configure.ac 461B
Makefile.am 95KB
Makefile.am 54KB
Makefile.am 42KB
Makefile.am 22KB
Makefile.am 11KB
Makefile.am 7KB
Makefile.am 315B
ar-lib 6KB
bad_utf8_string 3B
BUILD.bazel 46KB
BUILD.bazel 5KB
BUILD.bazel 4KB
BUILD.bazel 4KB
BUILD.bazel 4KB
BUILD.bazel 1013B
BUILD.bazel 950B
BUILD.bazel 887B
BUILD.bazel 851B
zlib.BUILD 2KB
protobuf.bzl 19KB
protobuf_deps.bzl 5KB
cpp_opts.bzl 2KB
protobuf_release.bzl 1KB
defs.bzl 1KB
cc_proto_blacklist_test.bzl 1000B
compiler_config_setting.bzl 964B
protobuf_version.bzl 92B
gtest.cbproj 10KB
gtest_unittest.cbproj 9KB
gtest_main.cbproj 8KB
gmock-gtest-all.cc 489KB
descriptor.pb.cc 449KB
gtest-all.cc 417KB
descriptor.cc 315KB
descriptor_unittest.cc 307KB
gtest_unittest.cc 248KB
gmock-matchers_test.cc 227KB
gtest.cc 216KB
message.cc 154KB
parser_unittest.cc 122KB
generated_message_reflection.cc 121KB
binary_json_conformance_suite.cc 119KB
message_differencer_unittest.cc 114KB
message.cc 104KB
command_line_interface_unittest.cc 99KB
text_format.cc 97KB
protostream_objectwriter_test.cc 92KB
command_line_interface.cc 92KB
test_util_lite.cc 90KB
strutil.cc 87KB
text_format_unittest.cc 84KB
parser.cc 84KB
message_differencer.cc 83KB
php_generator.cc 82KB
type.pb.cc 79KB
gtest_pred_impl_unittest.cc 76KB
extension_set.cc 75KB
gmock-spec-builders_test.cc 73KB
reflection_tester.cc 73KB
descriptor.cc 73KB
repeated_field_unittest.cc 72KB
wrappers.pb.cc 69KB
generated_message_tctable_lite.cc 68KB
objectivec_helpers.cc 67KB
wire_format.cc 67KB
plugin.pb.cc 64KB
parse_function_generator.cc 62KB
gtest-death-test.cc 60KB
message.cc 60KB
extension_set_unittest.cc 57KB
arena_unittest.cc 57KB
helpers.cc 54KB
message_field.cc 54KB
generator.cc 54KB
descriptor_containers.cc 52KB
generated_message_reflection_unittest.cc 52KB
googletest-printers-test.cc 52KB
api.pb.cc 49KB
string_field.cc 47KB
file.cc 47KB
protostream_objectwriter.cc 47KB
enum_field.cc 46KB
coded_stream_unittest.cc 46KB
gmock-actions_test.cc 46KB
googletest-death-test-test.cc 45KB
gtest-port.cc 43KB
lite_unittest.cc 43KB
gmock-generated-matchers_test.cc 43KB
tokenizer_unittest.cc 42KB
primitive_field.cc 42KB
tokenizer.cc 41KB
googletest-port-test.cc 39KB
protostream_objectsource.cc 39KB
enum_field_lite.cc 39KB
map_field_lite.cc 38KB
struct.pb.cc 37KB
共 1159 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
资源评论
candy8gh
- 粉丝: 1
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功