UE4Protobuf: UE4中編譯最新Protobuf 3.11.2的腳本 (gitee.com)
UE4Protobuf
UE4中編譯最新Protobuf 3.11.2的腳本
編譯環境
-
Windows下編譯Win64及Android庫
- Visual Studio
- Android NDK
- CMake 並將cmake.exe所在目錄加入系統變量
PATH
中
-
Mac機編譯IOS庫
- XCode
- CMake
使用說明
-
下載Google Protobuf最新版(protobuf-cpp-x.x.x.zip)。
-
解壓到
source
目錄下 -
修改源代碼
-
src/google/protobuf/compiler/cpp/cpp_file.cc
// 方法:FileGenerator::GenerateSourceIncludes format( "// Generated by the protocol buffer compiler. DO NOT EDIT!\n" "// source: $filename$\n" + "\n" + "// Disable UE4 VS warnings\n" + "#ifdef _MSC_VER\n" + "#\tpragma warning(disable: 4946)\n" + "#\tpragma warning(disable: 4125)\n" + "#\tpragma warning(disable: 4647)\n" + "#\tpragma warning(disable: 4668)\n" + "#\tpragma warning(disable: 4800)\n" + "#endif\n" + "\n" "#include $1$\n"
-
cmake/CMakeLists.txt
add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD) + add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI=1)
-
-
編譯
- 修改
BuildWindows.bat
中VC的路徑為自己安裝的路徑 - 修改
BuildAndroid.bat
中NDK的路徑 - Windows下運行
BuildWindows.bat
- Windows下運行
BuildAndroid.bat
- Mac下運行
BuildIOS.sh
- 修改
-
UE4集成
- 在項目
Source/ThirdParty
目錄下建立文件夾Protobuf
- 將
include
,lib
,Protobuf.Build.cs
拷貝到新建的目錄下 - 使用
bin
目錄下生成protoc.exe
生成*.pb.cc
及*.pb.h
文件 - 由於最新的Protobuf已經使用c++11重寫,所以不需要再引入
AllowWindowsPlatformTypes.h
等文件了,基本不需要改動
- 在項目