1、创建工作目录:c:/path/to
2、下载CMake:https://cmake.org/download/
设置CMake环境变量:set PATH=%PATH%;C:\Users\Administrator\Desktop\cmake-3.16.0-win32-x86\bin
3、下载安装git,一路默认选项: https://git-scm.com/download/win
设置git环境变量:set PATH=%PATH%;C:\Program Files\Git\cmd
4、下载protobuf源码:
C:\Path\to> git clone -b master https://github.com/protocolbuffers/protobuf.git
5、更新子模块:
C:\Path\to>protobuf> git submodule update --init --recursive
6、进入源码cmake目录:
C:\Path\to\protobuf>cd cmake
7、创建临时编译目录
C:\Path\to\protobuf\cmake>mkdir build & cd build
8、根据个人需要,创建release或者debug目录:
release:
C:\Path\to\protobuf\cmake\build>mkdir release & cd release
C:\Path\to\protobuf\cmake\build\release>cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../../../install ../..
debug:
C:\Path\to\protobuf\cmake\build>mkdir debug & cd debug
C:\Path\to\protobuf\cmake\build\debug>cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../../../install ../..
9、创建Visual Studio solution(sln)文件:
C:\Path\to\protobuf\cmake\build>mkdir solution & cd solution
C:\Path\to\protobuf\cmake\build\solution>cmake -G "Visual Studio 15 2017" -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=../../../../install ../..
10、编译:
C:\Path\to\protobuf\cmake\build\release>nmake
或者
C:\Path\to\protobuf\cmake\build\debug>nmake
或者
用vs打开 sln 文件进行编译