diff options
| author | ruki <[email protected]> | 2019-07-01 22:35:50 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-07-01 09:35:01 +0800 |
| commit | a40920e82e60b7a87731ba60b848b9bafa8cf937 (patch) | |
| tree | 772b961a8ac0c107142ae0f743b73b332afa2140 /xmake | |
| parent | ff067fda68bf431a4d46ce0149d425c7665aa2e7 (diff) | |
add protobuf rules
Diffstat (limited to 'xmake')
| -rw-r--r-- | xmake/actions/require/impl/action/patch.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/protobuf/proto.lua | 28 | ||||
| -rw-r--r-- | xmake/rules/protobuf/xmake.lua | 28 |
3 files changed, 28 insertions, 30 deletions
diff --git a/xmake/actions/require/impl/action/patch.lua b/xmake/actions/require/impl/action/patch.lua index bab50f9c5..cde52ec12 100644 --- a/xmake/actions/require/impl/action/patch.lua +++ b/xmake/actions/require/impl/action/patch.lua @@ -30,7 +30,7 @@ function _patch(package, patch_url, patch_hash) vprint("patching %s to %s-%s ..", patch_url, package:name(), package:version_str()) -- get the patch file - local patch_file = path.join(os.tmpdir(), "patches", package:name(), package:version_str(), path.filename(patch_url)) + local patch_file = path.join(os.tmpdir(), "patches", package:name(), package:version_str(), (path.filename(patch_url):gsub("%?.+$", ""))) -- the package file have been downloaded? local cached = true diff --git a/xmake/rules/protobuf/proto.lua b/xmake/rules/protobuf/proto.lua index cc00d3b35..41ae6a388 100644 --- a/xmake/rules/protobuf/proto.lua +++ b/xmake/rules/protobuf/proto.lua @@ -24,17 +24,39 @@ import("core.theme.theme") import("core.project.config") import("core.project.depend") import("core.tool.compiler") +import("lib.detect.find_tool") -- build protobuf file function main(target, sourcekind, sourcefile_proto, opt) + -- find protoc + local protoc = target:data("protobuf.protoc") + if not protoc and sourcekind == "cxx" then + protoc = find_tool("protoc") + if protoc and protoc.program then + target:data_set("protobuf.protoc", protoc.program) + end + end + + -- find protoc-c + local protoc_c = target:data("protobuf.protoc-c") + if not protoc_c and sourcekind == "cc" then + protoc_c = find_tool("protoc-c") or protoc + if protoc_c and protoc_c.program then + target:data_set("protobuf.protoc-c", protoc_c.program) + end + end + -- get protoc - local protoc = assert(target:data("protobuf.protoc"), "protoc not found!") + protoc = assert(target:data(sourcekind == "cxx" and "protobuf.protoc" or "protobuf.protoc-c"), "protoc not found!") -- get c/c++ source file for protobuf - local sourcefile_cx = path.join(target:autogendir(), "rules", "protobuf", "src", path.basename(sourcefile_proto) .. ".pb" .. (sourcekind == "cxx" and ".cc" or ".c")) + local sourcefile_cx = path.join(target:autogendir(), "rules", "protobuf", path.basename(sourcefile_proto) .. ".pb" .. (sourcekind == "cxx" and ".cc" or "-c.c")) local sourcefile_dir = path.directory(sourcefile_cx) + -- add includedirs + target:add("includedirs", sourcefile_dir) + -- get object file local objectfile = target:objectfile(sourcefile_cx) @@ -75,7 +97,7 @@ function main(target, sourcekind, sourcefile_proto, opt) end -- compile protobuf - os.vrunv(protoc, {sourcefile_proto, (sourcekind == "cxx" and "--cpp_out=" or "--c_out=") .. sourcefile_dir}) + os.vrunv(protoc, {sourcefile_proto, "-I" .. os.args(path.directory(sourcefile_proto)), (sourcekind == "cxx" and "--cpp_out=" or "--c_out=") .. sourcefile_dir}) -- trace if option.get("verbose") then diff --git a/xmake/rules/protobuf/xmake.lua b/xmake/rules/protobuf/xmake.lua index 3907a4c2d..1447e2b05 100644 --- a/xmake/rules/protobuf/xmake.lua +++ b/xmake/rules/protobuf/xmake.lua @@ -18,35 +18,14 @@ -- @file xmake.lua -- - --- define rule: protobuf-cpp -rule("protobuf.env") - - -- load protoc - before_load(function (target) - import("lib.detect.find_tool") - local protoc = target:data("protobuf.protoc") - if not protoc then - protoc = find_tool("protoc") - if protoc and protoc.program then - target:data_set("protobuf.protoc", protoc.program) - else - raise("protoc not found!") - end - end - end) - -- define rule: protobuf.cpp rule("protobuf.cpp") - -- add deps - add_deps("protobuf.env") - -- set extension set_extensions(".proto") -- build protobuf file - on_build_file(function (target, sourcefile_proto, opt) + before_build_file(function (target, sourcefile_proto, opt) import("proto")(target, "cxx", sourcefile_proto, opt) end) @@ -54,13 +33,10 @@ rule("protobuf.cpp") -- define rule: protobuf.c rule("protobuf.c") - -- add deps - add_deps("protobuf.env") - -- set extension set_extensions(".proto") -- build protobuf file - on_build_file(function (target, sourcefile_proto, opt) + before_build_file(function (target, sourcefile_proto, opt) import("proto")(target, "cc", sourcefile_proto, opt) end) |
