xmake.lua 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package("flatbuffers")
  2. set_homepage("http://google.github.io/flatbuffers/")
  3. set_description("FlatBuffers is a cross platform serialization library architected for maximum memory efficiency.")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/google/flatbuffers/archive/refs/tags/$(version).zip",
  6. "https://github.com/google/flatbuffers.git")
  7. add_versions("v1.12.0", "4b8b21adbfe8a74b90604161afcf87c125a26b86c99327e7a04525080606536c")
  8. add_versions("v2.0.0", "ffd68aebdfb300c9e82582ea38bf4aa9ce65c77344c94d5047f3be754cc756ea")
  9. add_versions("v23.1.21", "48597d6a6f8ca67a02ae8d8494b3bfc9136eb93da60a538d5bfc024f7c564f97")
  10. add_versions("v23.5.26", "57bd580c0772fd1a726c34ab8bf05325293bc5f9c165060a898afa1feeeb95e1")
  11. add_versions("v24.3.25", "e706f5eb6ca8f78e237bf3f7eccffa1c5ec9a96d3c1c938f08dc09aab1884528")
  12. add_versions("v24.12.23", "c5cd6a605ff20350c7faa19d8eeb599df6117ea4aabd16ac58a7eb5ba82df4e7")
  13. add_versions("v25.2.10", "75ffbce7d32f8218b5faec86ae2f6397c7ca810605dc710dfa9c146b9df9e3e9")
  14. add_deps("cmake")
  15. on_install(function(package)
  16. io.replace("CMakeLists.txt", "/MT", "", {plain = true})
  17. io.replace("CMakeLists.txt",
  18. "RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}",
  19. "RUNTIME DESTINATION bin", {plain = true})
  20. if not package:is_cross() then
  21. package:addenv("PATH", "bin")
  22. end
  23. local configs = {"-DFLATBUFFERS_BUILD_TESTS=OFF"}
  24. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  25. if package:is_binary() then
  26. table.insert(configs, "-DFLATBUFFERS_BUILD_SHAREDLIB=OFF")
  27. table.insert(configs, "-DFLATBUFFERS_BUILD_FLATLIB=OFF")
  28. else
  29. table.insert(configs, "-DFLATBUFFERS_BUILD_SHAREDLIB=" .. (package:config("shared") and "ON" or "OFF"))
  30. table.insert(configs, "-DFLATBUFFERS_BUILD_FLATLIB=" .. (package:config("shared") and "OFF" or "ON"))
  31. end
  32. if package:config("shared") and package:is_plat("windows") then
  33. table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
  34. end
  35. table.insert(configs, "-DFLATBUFFERS_BUILD_FLATC=" .. (package:is_cross() and "OFF" or "ON"))
  36. table.insert(configs, "-DFLATBUFFERS_BUILD_FLATHASH=" .. (package:is_cross() and "OFF" or "ON"))
  37. import("package.tools.cmake").install(package, configs)
  38. if package:is_binary() then
  39. os.tryrm(package:installdir("include"))
  40. end
  41. if package:is_plat("windows") and package:is_debug() then
  42. os.trymv(package:installdir("lib/flatc.pdb"), package:installdir("bin"))
  43. end
  44. end)
  45. on_test(function(package)
  46. if not package:is_cross() then
  47. os.vrun("flatc --version")
  48. end
  49. if package:is_library() then
  50. assert(package:check_cxxsnippets({test = [[
  51. void test() {
  52. flatbuffers::FlatBufferBuilder builder;
  53. builder.CreateString("MyMonster");
  54. flatbuffers::DetachedBuffer dtbuilder = builder.Release();
  55. }
  56. ]]}, {configs = {languages = "c++14"}, includes = "flatbuffers/flatbuffers.h"}))
  57. end
  58. end)