premake5: Automatic compiling of protobuf definition files.

- Added custom rules for *.proto files to iw4x
- Added a workaround for protoc output not being automatically included
- Disable precompiled headers for protobuf generated sources
- Moved inclusion of node.pb.h out of STDInclude.hpp to only where it's necessary (WTF @momo5502)
- Removed protobuf-generated code from "protobuf" external project
- Removed protogen.bat as it is no longer needed
This commit is contained in:
/dev/urandom 2016-02-11 15:09:32 +01:00
parent ff6baf1e08
commit 22dbae3b67
No known key found for this signature in database
GPG Key ID: 41322B973E0F295E
5 changed files with 56 additions and 11 deletions

View File

@ -1,3 +1,6 @@
-- protoc tool
protocBinPath = path.translate(path.join(_MAIN_SCRIPT_DIR, "tools", "protoc.exe"))
-- Option to allow copying the DLL file to a custom folder after build -- Option to allow copying the DLL file to a custom folder after build
newoption { newoption {
trigger = "copy-to", trigger = "copy-to",
@ -90,13 +93,23 @@ workspace "iw4x"
project "iw4x" project "iw4x"
kind "SharedLib" kind "SharedLib"
language "C++" language "C++"
files { "./src/**.hpp", "./src/**.cpp" } files {
includedirs { "%{prj.location}/src", "./src" } "./src/**.hpp",
"./src/**.cpp",
"./src/**.proto",
}
includedirs {
"%{prj.location}/src",
"./src"
}
-- Pre-compiled header -- Pre-compiled header
pchheader "STDInclude.hpp" -- must be exactly same as used in #include directives pchheader "STDInclude.hpp" -- must be exactly same as used in #include directives
pchsource "src/STDInclude.cpp" -- real path pchsource "src/STDInclude.cpp" -- real path
buildoptions { "/Zm100" } buildoptions { "/Zm100" }
filter "files:**.pb.*"
flags { "NoPCH" }
filter {}
-- Dependency on zlib, json11 and asio -- Dependency on zlib, json11 and asio
links { "zlib", "json11", "pdcurses", "libtomcrypt", "libtommath", "protobuf" } links { "zlib", "json11", "pdcurses", "libtomcrypt", "libtommath", "protobuf" }
@ -116,7 +129,9 @@ workspace "iw4x"
if not _OPTIONS["no-new-structure"] then if not _OPTIONS["no-new-structure"] then
vpaths { vpaths {
["Headers/*"] = { "./src/**.hpp" }, ["Headers/*"] = { "./src/**.hpp" },
["Sources/*"] = { "./src/**.cpp" } ["Sources/*"] = { "./src/**.cpp" },
["Proto/Definitions/*"] = { "./src/Proto/**.proto" },
["Proto/Generated/*"] = { "**.pb.*" }, -- meh.
} }
end end
@ -143,6 +158,23 @@ workspace "iw4x"
configuration "Release*" configuration "Release*"
flags { "FatalCompileWarnings" } flags { "FatalCompileWarnings" }
configuration {}
-- Generate source code from protobuf definitions
rules { "ProtobufCompiler" }
-- Workaround: Consume protobuf generated source files
matches = os.matchfiles(path.join("src/Proto/**.proto"))
for i, srcPath in ipairs(matches) do
basename = path.getbasename(srcPath)
files {
string.format("%%{prj.location}/src/proto/%s.pb.h", basename),
string.format("%%{prj.location}/src/proto/%s.pb.cc", basename),
}
end
includedirs {
"%{prj.location}/src/proto"
}
group "External dependencies" group "External dependencies"
@ -262,9 +294,6 @@ workspace "iw4x"
-- default protobuf sources -- default protobuf sources
files { "./deps/protobuf/src/**.cc" } files { "./deps/protobuf/src/**.cc" }
-- our generated sources
files { "./%{prj.location}/src/proto/**.cc" }
-- remove unnecessary sources -- remove unnecessary sources
removefiles removefiles
{ {
@ -284,3 +313,19 @@ workspace "iw4x"
-- always build as static lib, as we include our custom classes and therefore can't perform shared linking -- always build as static lib, as we include our custom classes and therefore can't perform shared linking
kind "StaticLib" kind "StaticLib"
rule "ProtobufCompiler"
display "Protobuf compiler"
location "./build"
fileExtension ".proto"
buildmessage "Compiling %(Identity) with protoc..."
buildcommands {
'@echo off',
'path "$(SolutionDir)\\..\\tools"',
'if not exist "$(ProjectDir)\\src\\proto" mkdir "$(ProjectDir)\\src\\proto"',
'protoc --error_format=msvs -I=%(RootDir)%(Directory) "--cpp_out=$(ProjectDir)\\src\\proto" "%(FullPath)"',
}
buildoutputs {
'$(ProjectDir)\\src\\proto\\%(Filename).pb.cc',
'$(ProjectDir)\\src\\proto\\%(Filename).pb.h',
}

View File

@ -6,6 +6,9 @@
#define NODE_STORE_INTERVAL 1000 * 60* 1 // Store nodes every minute #define NODE_STORE_INTERVAL 1000 * 60* 1 // Store nodes every minute
#define SESSION_TIMEOUT 1000 * 10 // 10 seconds session timeout #define SESSION_TIMEOUT 1000 * 10 // 10 seconds session timeout
// Protobuf
#include "proto/node.pb.h"
namespace Components namespace Components
{ {
class Node : public Component class Node : public Component

View File

@ -61,9 +61,6 @@
#include <tomcrypt.h> #include <tomcrypt.h>
#include <wink/signal.hpp> #include <wink/signal.hpp>
// Protobuf
#include <proto/node.pb.h>
#pragma warning(pop) #pragma warning(pop)
// Version number // Version number

View File

@ -1,4 +1,4 @@
pushd "%~dp0" pushd "%~dp0"
mkdir "..\build\src\proto" 2>NUL mkdir "..\build\src\proto" 2>NUL
protoc.exe -I=proto --cpp_out=../build/src/proto/ proto/node.proto protoc.exe -I=../src/Proto --cpp_out=../build/src/proto/ ../src/Proto/node.proto
popd popd