2
0

xmake.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package("protobuf-cpp")
  2. set_homepage("https://developers.google.com/protocol-buffers/")
  3. set_description("Google's data interchange format for cpp")
  4. add_urls("https://github.com/protocolbuffers/protobuf/releases/download/v$(version)", {version = function (version)
  5. if version:le("3.19.4") then
  6. return version .. "/protobuf-cpp-" .. version .. ".zip"
  7. else
  8. return version .. "/protobuf-" .. version .. ".zip"
  9. end
  10. end})
  11. add_versions("27.3", "a49147217f69e8d19aab0cc5c0059d6201261f5cb62145f8ab4ac8b94e7ffa86")
  12. add_versions("27.2", "7b4554f730a41f5c595cef3502038a69b8954c30d8ec9c62a167d5e1ebd8c210")
  13. add_versions("27.0", "3e1148db090ff21226c1888ef39fa7bc7790042be21ff4289fd21ce1735f3455")
  14. add_versions("26.1", "e15c272392df84ae95797759c685a9225fe5e88838bab3e0650c29239bdfccdd")
  15. add_versions("3.8.0", "91ea92a8c37825bd502d96af9054064694899c5c7ecea21b8d11b1b5e7e993b5")
  16. add_versions("3.12.0", "da826a3c48a9cae879928202d6fe06afb15aaee129e9035d6510cc776ddfa925")
  17. add_versions("3.12.3", "74da289e0d0c24b2cb097f30fdc09fa30754175fd5ebb34fae4032c6d95d4ce3")
  18. add_versions("3.13.0", "f7b99f47822b0363175a6751ab59ccaa4ee980bf1198f11a4c3cef162698dde3")
  19. add_versions("3.14.0", "87d6e96166cf5cafc16f2bcfa91c0b54f48bab38538285bee1b9331d992569fa")
  20. add_versions("3.15.5", "cdd7d3925240af541a95a4361ab100b703bee3a9df0d7e9e05c069cf2c76a039")
  21. add_versions("3.15.8", "093e0dca5277b377c36a48a3633325dca3d92d68ac17d5700a1f7e1c3eca2793")
  22. add_versions("3.17.3", "fe65f4bfbd6cbb8c23de052f218cbe4ebfeb72c630847e0cca63eb27616c952a")
  23. add_versions("3.19.4", "a11a262a395f999f9dca83e195cc15b6c23b6d5e74133f8e3250ad0950485da1")
  24. add_patches("3.17.3", path.join(os.scriptdir(), "patches", "3.17.3", "field_access_listener.patch"), "ac9bdf49611b01e563fe74b2aaf1398214129454c3e18f1198245549eb281e85")
  25. add_patches("3.19.4", path.join(os.scriptdir(), "patches", "3.19.4", "vs_runtime.patch"), "8e73e585d29f3b9dca3c279df0b11b3ee7651728c07f51381a69e5899b93c367")
  26. add_configs("zlib", {description = "Enable zlib", default = false, type = "boolean"})
  27. add_deps("cmake")
  28. if is_plat("windows") then
  29. add_links("libprotobuf", "libprotoc", "utf8_range", "utf8_validity")
  30. else
  31. add_links("protobuf", "protoc", "utf8_range", "utf8_validity")
  32. end
  33. if is_plat("linux") then
  34. add_syslinks("pthread")
  35. end
  36. on_load(function (package)
  37. package:addenv("PATH", "bin")
  38. if package:config("zlib") then
  39. package:add("deps", "zlib")
  40. end
  41. if package:version():ge("22.0") then
  42. package:add("deps", "abseil")
  43. end
  44. end)
  45. on_install("windows", "linux", "macosx", function (package)
  46. if package:version():le("3.19.4") then
  47. os.cd("cmake")
  48. end
  49. io.replace("CMakeLists.txt", "set(protobuf_DEBUG_POSTFIX \"d\"", "set(protobuf_DEBUG_POSTFIX \"\"", {plain = true})
  50. if package:version():ge("26.1") then
  51. io.replace("cmake/abseil-cpp.cmake", "BUILD_SHARED_LIBS AND MSVC", "FALSE", {plain = true})
  52. end
  53. local configs = {"-Dprotobuf_BUILD_TESTS=OFF", "-Dprotobuf_BUILD_PROTOC_BINARIES=ON"}
  54. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  55. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  56. local packagedeps = {}
  57. if package:version():ge("22.0") then
  58. table.insert(packagedeps, "abseil")
  59. table.insert(configs, "-Dprotobuf_ABSL_PROVIDER=package")
  60. end
  61. if package:is_plat("windows") then
  62. table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''")
  63. table.insert(configs, "-Dprotobuf_MSVC_STATIC_RUNTIME=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
  64. if package:config("shared") then
  65. package:add("defines", "PROTOBUF_USE_DLLS")
  66. end
  67. end
  68. if package:config("zlib") then
  69. table.insert(configs, "-Dprotobuf_WITH_ZLIB=ON")
  70. end
  71. import("package.tools.cmake").install(package, configs, {buildir = "build", packagedeps = packagedeps})
  72. os.trycp("build/Release/protoc.exe", package:installdir("bin"))
  73. end)
  74. on_test(function (package)
  75. if package:is_cross() then
  76. return
  77. end
  78. io.writefile("test.proto", [[
  79. syntax = "proto3";
  80. package test;
  81. message TestCase {
  82. string name = 4;
  83. }
  84. message Test {
  85. repeated TestCase case = 1;
  86. }
  87. ]])
  88. os.vrun("protoc test.proto --cpp_out=.")
  89. end)