xmake.lua 3.1 KB

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