xmake.lua 3.2 KB

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