xmake.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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)/protobuf-cpp-$(version).zip")
  5. add_versions("3.8.0", "91ea92a8c37825bd502d96af9054064694899c5c7ecea21b8d11b1b5e7e993b5")
  6. add_versions("3.12.3", "74da289e0d0c24b2cb097f30fdc09fa30754175fd5ebb34fae4032c6d95d4ce3")
  7. add_versions("3.13.0", "f7b99f47822b0363175a6751ab59ccaa4ee980bf1198f11a4c3cef162698dde3")
  8. add_versions("3.14.0", "87d6e96166cf5cafc16f2bcfa91c0b54f48bab38538285bee1b9331d992569fa")
  9. if is_plat("windows") then
  10. add_deps("cmake")
  11. end
  12. if is_plat("windows") then
  13. add_links("libprotobuf")
  14. else
  15. add_links("protobuf")
  16. end
  17. on_load(function (package)
  18. package:addenv("PATH", "bin")
  19. end)
  20. on_install("windows", function (package)
  21. os.cd("cmake")
  22. local configs = {"-Dprotobuf_BUILD_TESTS=OFF", "-Dprotobuf_BUILD_PROTOC_BINARIES=ON"}
  23. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  24. table.insert(configs, "-Dprotobuf_MSVC_STATIC_RUNTIME=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
  25. if package:config("shared") then
  26. package:add("defines", "PROTOBUF_USE_DLLS")
  27. end
  28. import("package.tools.cmake").install(package, configs)
  29. os.cp("build_*/Release/protoc.exe", package:installdir("bin"))
  30. end)
  31. on_install("linux", "macosx", function (package)
  32. local configs = {}
  33. if package:config("pic") ~= false then
  34. table.insert(configs, "--with-pic")
  35. end
  36. if package:config("shared") then
  37. table.insert(configs, "--enable-shared=yes")
  38. table.insert(configs, "--enable-static=no")
  39. else
  40. table.insert(configs, "--enable-static=yes")
  41. table.insert(configs, "--enable-shared=no")
  42. end
  43. import("package.tools.autoconf").install(package, configs)
  44. end)
  45. on_test(function (package)
  46. io.writefile("test.proto", [[
  47. syntax = "proto3";
  48. package test;
  49. message TestCase {
  50. string name = 4;
  51. }
  52. message Test {
  53. repeated TestCase case = 1;
  54. }
  55. ]])
  56. os.vrun("protoc test.proto --cpp_out=.")
  57. assert(package:check_cxxsnippets({test = io.readfile("test.pb.cc")}, {configs = {includedirs = {".", package:installdir("include")}, languages = "c++11"}}))
  58. end)