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/rules/protobuf/proto.lua | |
| parent | ff067fda68bf431a4d46ce0149d425c7665aa2e7 (diff) | |
add protobuf rules
Diffstat (limited to 'xmake/rules/protobuf/proto.lua')
| -rw-r--r-- | xmake/rules/protobuf/proto.lua | 28 |
1 files changed, 25 insertions, 3 deletions
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 |
