Env:
- protobuf version is 3.12.2
- Native build command is nmake
- cmake version is 3.10
- Unreal Engine 4 version is 4.18
-
open
Native Tools Command Prompt
command, e.g.x64 Native Tools Command Prompt for VS 2017
. -
Address to directory
build_protobuf-lite/
(address to directorybuild_protobuf/
if you want to buildlibprotobuf
).cd build_protobuf-lite
-
Create directory
build
and navigate in it.mkdir build & cd build
-
Create directory
release
and navigate in it.mkdir release & cd release
-
Generate configuration using
CMakeList.txt
.cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DPROTOBUF_VERSION=3.12.2 ../..
If the version is lower then
3.12.x
, you need to append-Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF
. -
Build
libprotobuf
.nmake
then libprotobuf-lite.lib
would output to directory install/Release/
.
protobuf source has been modified. The build from original protobuf source with UE4 would fail if protobuf version is lower than 3.12
.
Source modification details:
version 3.5.x
: https://github.com/jashking/UE4Protobuf
version 3.9.x
: https://github.com/kingsoftgames/protobuf-ue4/blob/master/Fix-3.9.2.bat
-
Address to directory
test/
:cd test
-
execute
protoc_gen.bat
.
then test.pb.h
and test.pb.cc
would be outputed in directory test/
-
Address to directory
test/cmake/
:cd test/cmake/
-
Create directory
build
and navigate in it.mkdir build & cd build
-
Create directory
release
and navigate in it.mkdir release & cd release
-
Generate configuration using
CMakeList.txt
.cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DPROTOBUF_VERSION=3.12.2 ../..
-
Build your own library.
nmake
then libtest.lib
would output to directory test/install/Release/
Execute extract_includes.bat
, then protobuf headers would be saved in directory include
.
-
copy
ue4/MyProj.Build.cs
into your UE4 project:MyProj/Source/MyProj/
-
copy
libtest.lib
andlibprotobuf-lite.lib
into your UE4 project:MyProj/ThirdParty/Protobuf/Library/
-
copy google protobuf headers into your UE4 project:
MyProj/ThirdParty/Protobuf/Include/
-
copy
test.pb.h
into your UE4 project:MyProj/ThirdParty/Protobuf/Include/
-
Add
bEnableExceptions = true;
inside the {ProjectName}.Build.cs constructor.
then your can build your UE4 project with protoc C++ files.
More details can be saw in example: MyProj.Build.cs.
If want to build other version, modify parameter PROTOBUF_VERSION
to specified version (e.g. -DPROTOBUF_VERSION=3.5.1
), and also modify version in extract_includes.bat
, and replace protoc.exe
with matched version (3.12.2
in current repository).
-
execute
\ndk_build\build.bat
-
execute
test\ndk_build\build.bat
-
copy
ndk_build\obj\local\armeabi-v7a\libprotobuf-lite-ndk.a
andtest\ndk_build\obj\local\armeabi-v7a\libtest-ndk.a
into your UE4 project:MyProj/ThirdParty/Protobuf/Library/
-
copy headers which are in
test\src\
into your UE4 project:MyProj/ThirdParty/Protobuf/Include/
-
build your UE4 project.
libprotobuf-lite:
https://github.com/protocolbuffers/protobuf/blob/master/cmake/libprotobuf-lite.cmake
libprotobuf:
https://github.com/protocolbuffers/protobuf/blob/master/cmake/libprotobuf.cmake
Build Protobuf for Unreal Engine 4 with Jenkins Pipeline.
https://github.com/kingsoftgames/protobuf-ue4