xmake.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package("protobuf-c")
  2. set_homepage("https://github.com/protobuf-c/protobuf-c")
  3. set_description("Google's data interchange format for c")
  4. add_urls("https://github.com/protobuf-c/protobuf-c/releases/download/v$(version)/protobuf-c-$(version).tar.gz")
  5. add_versions("1.5.1", "20d1dc257da96f8ddff8be4dd9779215bbd0a6069ed53bbe9de38fa7629be06b")
  6. add_versions("1.5.0", "7b404c63361ed35b3667aec75cc37b54298d56dd2bcf369de3373212cc06fd98")
  7. add_versions("1.3.1", "51472d3a191d6d7b425e32b612e477c06f73fe23e07f6a6a839b11808e9d2267")
  8. -- fix "error: no type named 'Reflection' in 'google::protobuf::Message'"
  9. -- see https://github.com/protobuf-c/protobuf-c/pull/342
  10. -- and https://github.com/protobuf-c/protobuf-c/issues/356
  11. add_patches("1.3.1", path.join(os.scriptdir(), "patches", "1.3.1", "342.patch"), "ab78f9eeff2840cacf5b6b143d284e50e43166ec2cbfa78cd47fd8db1e387c6d")
  12. add_deps("protobuf-cpp 3.19.4")
  13. if is_plat("windows") then
  14. add_deps("cmake", "abseil", "utf8_range")
  15. end
  16. add_links("protobuf-c")
  17. if is_plat("linux") then
  18. add_syslinks("pthread")
  19. end
  20. on_load(function (package)
  21. package:addenv("PATH", "bin")
  22. end)
  23. -- on_install("windows", function (package)
  24. -- -- fix run `protoc-c.exe` failed
  25. -- io.replace("protoc-c/main.cc", "invocation_basename == legacy_name", "1")
  26. -- os.cd("build-cmake")
  27. -- local cflags
  28. -- local shflags
  29. -- local configs = {}
  30. -- if package:config("shared") then
  31. -- table.insert(configs, "-DBUILD_SHARED_LIBS=ON")
  32. -- cflags = {"-DPROTOBUF_C_USE_SHARED_LIB", "-DPROTOBUF_C_EXPORT"}
  33. -- shflags = "/export:protobuf_c_empty_string"
  34. -- else
  35. -- table.insert(configs, "-DBUILD_SHARED_LIBS=OFF")
  36. -- end
  37. -- if package:config("vs_runtime"):startswith("MT") then
  38. -- table.insert(configs, "-DMSVC_STATIC_BUILD=ON")
  39. -- else
  40. -- table.insert(configs, "-DMSVC_STATIC_BUILD=OFF")
  41. -- end
  42. -- import("package.tools.cmake").install(package, configs, {cflags = cflags, shflags = shflags})
  43. -- os.cp("build_*/Release/protoc-gen-c.exe", path.join(package:installdir("bin"), "protoc-c.exe"))
  44. -- end)
  45. on_install("linux", "macosx", function (package)
  46. local configs = {}
  47. if package:config("pic") ~= false then
  48. table.insert(configs, "--with-pic")
  49. end
  50. if package:config("shared") then
  51. table.insert(configs, "--enable-shared=yes")
  52. table.insert(configs, "--enable-static=no")
  53. else
  54. table.insert(configs, "--enable-static=yes")
  55. table.insert(configs, "--enable-shared=no")
  56. end
  57. import("package.tools.autoconf").install(package, configs)
  58. end)
  59. on_test(function (package)
  60. if package:is_cross() then
  61. return
  62. end
  63. io.writefile("test.proto", [[
  64. syntax = "proto3";
  65. package test;
  66. message TestCase {
  67. string name = 4;
  68. }
  69. message Test {
  70. repeated TestCase case = 1;
  71. }
  72. ]])
  73. os.vrun("protoc-c test.proto -I. --c_out=.")
  74. assert(package:check_csnippets({test = io.readfile("test.pb-c.c")}, {configs = {includedirs = {".", package:installdir("include")}}}))
  75. end)