一冻晤、使用CMAKE+NMAKE 法
使用VC BUILD 2015編譯grpc_1.6.6
環(huán)境:
win7_x64洲炊,VC BUILD TOOLS2015
開始:
(一)吨悍、安裝工具
1.安裝Visual C++ Build Tools2015.3(典型安裝定拟,在path中加入C:\Program Files (x86)\Windows Kits\10\bin\x64\ucrt)
2.安裝cmake:3.8.2
3.安裝ActivePerl:ActivePerl-5.26.0.2600
4.安裝golang:go1.9.1 windows/amd64
5.安裝nasm:2.13.01
驗(yàn)證安裝是否安裝成功:
cmake -version
perl -version
go version
nasm -v
如果出現(xiàn)錯誤于微,請檢查是否安裝成功;若安裝成功青自,則需要檢查安裝目錄是否添加到環(huán)境變量path中株依。
(二)、下載源碼
1.grpc-1.6.6.zip解壓到D:/grpc-1.6.6
2.benchmark-1.2.0.zip解壓到D:/grpc-1.6.6/third_party/benchmark
3.boringssl-master.zip解壓到D:/grpc-1.6.6/third_party/boringssl
4.c-ares-cares-1_12_0.zip解壓到D:/grpc-1.6.6/third_party/cares/cares
5.gflags-2.2.1.zip解壓到D:/grpc-1.6.6/third_party/gflags
6.protobuf-3.4.1.zip解壓到D:grpc-1.6.6/third_party/protobuf
6.zlib-1.2.11.zip解壓到D:/grpc-1.6.6/third_party/zlib
除grpc外性穿,只要按照上面的路徑解壓到相應(yīng)的目錄即可勺三。注意一定要將c-ares-cares-1_12_0.zip(grpc1.6.x貌似與c-ares-cares-1_13_0不兼容)解壓到D:/grpc-1.6.6/third_party/cares/cares目錄,否是編譯會報錯需曾。
(三)吗坚、編譯
1.編寫腳本do_build.bat
@echo off
::Release,Debug,RelWithDebInfo
set CMAKE_BUILD_TYPE=%1%
::x86,x64
set PLATFORM=%2%
set OUTPUT_PATH=%3%
set CMAKE_PATH=%4%
if not exist %PLATFORM% (
mkdir %PLATFORM%
)
cd %PLATFORM%
if %PLATFORM% == x86 (
call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x86
)
if %PLATFORM% == x64 (
call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" amd64
)
echo cmake -G "NMake Makefiles" -D CMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% -D EXECUTABLE_OUTPUT_PATH=%OUTPUT_PATH% -D LIBRARY_OUTPUT_PATH=%OUTPUT_PATH% -D CMAKE_C_FLAGS_RELEASE="/MT /WX-" -D CMAKE_CXX_FLAGS_RELEASE="/MT /WX-" -D BUILD_SHARED_LIBS=0 %CMAKE_PATH%
::CMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE%構(gòu)建類型(Release,Debug,RelWithDebInfo)
::EXECUTABLE_OUTPUT_PATH=%OUTPUT_PATH%可執(zhí)行程序的路徑
::LIBRARY_OUTPUT_PATH=%OUTPUT_PATH%靜態(tài)庫的路徑
::CMAKE_C_FLAGS_RELEASE="/MT /WX-"使用靜態(tài)運(yùn)行時庫,禁止將警告視為錯誤
::CMAKE_CXX_FLAGS_RELEASE="/MT /WX-"使用靜態(tài)運(yùn)行時庫,禁止將警告視為錯誤
::BUILD_SHARED_LIBS=0生成靜態(tài)庫
cmake -G "NMake Makefiles" -D CMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% -D EXECUTABLE_OUTPUT_PATH=%OUTPUT_PATH% -D LIBRARY_OUTPUT_PATH=%OUTPUT_PATH% -D CMAKE_C_FLAGS_RELEASE="/MT /WX-" -D CMAKE_CXX_FLAGS_RELEASE="/MT /WX-" -D BUILD_SHARED_LIBS=0 %CMAKE_PATH%
nmake grpc grpc++ grpc_cpp_plugin protoc
主要作用是根據(jù)傳入的參數(shù)生成nmake文件,其中"/MT /WX-"是傳遞給cl編譯器的參數(shù)呆万,分別為"使用靜態(tài)運(yùn)行時庫"和"禁止將警告視為錯誤"商源。這個有個技巧如果想要將其他的參數(shù)傳遞給編譯器,只需要在后面添加即可谋减。
2.編寫腳本build_x64.bat
@echo off
set CURRENT_DIR=%~dp0
set CMAKE_BUILD_TYPE=Release
set PLATFORM=x64
set OUTPUT_PATH=%CURRENT_DIR%/x64/bin
set CMAKE_PATH=%CURRENT_DIR%/../
call do_build.bat %CMAKE_BUILD_TYPE% %PLATFORM% %OUTPUT_PATH% %CMAKE_PATH%
@pause
生成Release x64平臺庫文件
3.開始編譯
將build_x64.bat和do_build.bat腳本牡彻,拷貝到D:/grpc-1.6.6/cmake目錄下
運(yùn)行build_x64.bat進(jìn)行編譯
===============================================================
二、使用CMAKE+NINJA
Windows7
Vc2017/VC build tools 2015.3
SDK8.1
1出爹、fork官方grpc
2庄吼、修改v1.7.x中的.gitmodules:
[submodule "third_party/boringssl-with-bazel"]
path = third_party/boringssl-with-bazel
url =https://boringssl.googlesource.com/boringssl
===>
[submodule "third_party/boringssl-with-bazel"]
path = third_party/boringssl-with-bazel
url =https://github.com/google/boringssl.git
3、git clone --recursive -b v1.7.xhttps://github.com/topillar/grpc.gitgrpc-v1.7.x
4严就、編譯
方法1总寻、
> md .build
> cd .build
> call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
> cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release
> cmake --build .
方法2(VC BUILD TOOL 2015.3):
1. 編寫腳本do_build.bat
@echo off
::Release,Debug,RelWithDebInfo
set CMAKE_BUILD_TYPE=%1%
::x86,x64
set PLATFORM=%2%
set OUTPUT_PATH=%3%
set CMAKE_PATH=%4%
if not exist %PLATFORM% (
mkdir %PLATFORM%
)
cd %PLATFORM%
if %PLATFORM% == x86 (
call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x86
)
if %PLATFORM% == x64 (
call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" amd64
)
echo cmake -G "Ninja" -D CMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% -D EXECUTABLE_OUTPUT_PATH=%OUTPUT_PATH% -D LIBRARY_OUTPUT_PATH=%OUTPUT_PATH% -D CMAKE_C_FLAGS_RELEASE="/MT /WX-" -D CMAKE_CXX_FLAGS_RELEASE="/MT /WX-" -D BUILD_SHARED_LIBS=0 %CMAKE_PATH%
cmake -G Ninja -D CMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% -D EXECUTABLE_OUTPUT_PATH=%OUTPUT_PATH% -D LIBRARY_OUTPUT_PATH=%OUTPUT_PATH% -D CMAKE_C_FLAGS_RELEASE="/MT /WX-" -D CMAKE_CXX_FLAGS_RELEASE="/MT /WX-" -D BUILD_SHARED_LIBS=0 %CMAKE_PATH%
2. 編寫腳本build_x64.bat
@echo off
set CURRENT_DIR=%~dp0
set CMAKE_BUILD_TYPE=Release
set PLATFORM=x64
set OUTPUT_PATH=%CURRENT_DIR%/x64/bin
set CMAKE_PATH=%CURRENT_DIR%/../
call do_build.bat %CMAKE_BUILD_TYPE% %PLATFORM% %OUTPUT_PATH% %CMAKE_PATH%
@pause
3、編譯:將build_x64.bat和do_build.bat腳本梢为,拷貝到D:/grpc-v1.7.x/cmake目錄下渐行,運(yùn)行build_x64.bat,完畢后運(yùn)行cmake --build .
本文主要來自:http://www.cnblogs.com/dongc/p/6876362.html 铸董, 感謝祟印!