xmake.lua 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package("faker-cxx")
  2. set_homepage("https://cieslarmichal.github.io/faker-cxx/")
  3. set_description("C++ Faker library for generating fake (but realistic) data.")
  4. set_license("MIT")
  5. add_urls("https://github.com/cieslarmichal/faker-cxx/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/cieslarmichal/faker-cxx.git", {submodules = false})
  7. add_versions("v4.0.1", "ebeac25780878905d0e73cd6a5211bd0b5ce065d06961570f0de7f1a25ec7d9d")
  8. add_versions("v3.0.0", "63d6846376593e05da690136cabe8e7bf42ddcdd4edad3ae9b48696f86d80468")
  9. add_versions("v2.0.0", "8a7f5441f4453af868444675878a2d9a74918c1595caa65d537d3ea327e46a49")
  10. add_deps("cmake")
  11. if on_check then
  12. on_check(function (package)
  13. if package:version() and package:version():ge("4.0.0") then
  14. if package:is_plat("mingw") then
  15. raise("package(faker-cxx v4.0.1) unsupported platform. You can open a pr to fix build error")
  16. elseif package:is_plat("windows") then
  17. local vs_toolset = package:toolchain("msvc"):config("vs_toolset")
  18. if vs_toolset then
  19. local vs_toolset_ver = import("core.base.semver").new(vs_toolset)
  20. local minor = vs_toolset_ver:minor()
  21. assert(minor and minor >= 30, "package(faker-cxx) require vs_toolset >= 14.3")
  22. end
  23. end
  24. end
  25. assert(package:check_cxxsnippets({test = [[
  26. #include <concepts>
  27. #include <ranges>
  28. #include <format>
  29. static_assert(std::integral<bool>);
  30. void test() {
  31. const auto v = {4, 1, 3, 2};
  32. auto it = std::ranges::find(v, 3);
  33. std::format("Hello {}!\n", "world");
  34. }
  35. ]]}, {configs = {languages = "c++20"}}), "package(faker-cxx) Require at least C++20.")
  36. end)
  37. end
  38. on_load(function (package)
  39. if package:version() and package:version():lt("4.0.0") then
  40. package:add("deps", "fmt")
  41. end
  42. end)
  43. on_install(function (package)
  44. if not package:config("shared") then
  45. package:add("defines", "FAKER_CXX_STATIC_DEFINE")
  46. end
  47. local configs = {"-DBUILD_TESTING=OFF", "-DUSE_SYSTEM_DEPENDENCIES=ON", "-DUSE_STD_FORMAT=OFF"}
  48. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  49. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  50. if package:version() and package:version():lt("4.0.0") then
  51. if package:is_plat("windows") and package:config("shared") then
  52. table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
  53. end
  54. end
  55. local cxflags
  56. if package:has_tool("cxx", "cl") then
  57. cxflags = "/utf-8"
  58. end
  59. import("package.tools.cmake").install(package, configs, {cxflags = cxflags})
  60. end)
  61. on_test(function (package)
  62. local includes = "faker-cxx/string.h"
  63. local snippets = [[
  64. void test() {
  65. const auto id = faker::string::uuidV4();
  66. }
  67. ]]
  68. local version = package:version()
  69. if version then
  70. if version:lt("3.0.0") then
  71. includes = "faker-cxx/String.h"
  72. end
  73. if version:lt("4.0.0") then
  74. snippets = [[
  75. void test() {
  76. const auto id = faker::string::uuid();
  77. }
  78. ]]
  79. end
  80. end
  81. assert(package:check_cxxsnippets({test = snippets}, {configs = {languages = "c++20"}, includes = includes}))
  82. end)