xmake.lua 3.4 KB

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