xmake.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package("abseil")
  2. set_homepage("https://abseil.io")
  3. set_description("C++ Common Libraries")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/abseil/abseil-cpp/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/abseil/abseil-cpp.git")
  7. add_versions("20250127.1", "b396401fd29e2e679cace77867481d388c807671dc2acc602a0259eeb79b7811")
  8. add_versions("20200225.1", "0db0d26f43ba6806a8a3338da3e646bb581f0ca5359b3a201d8fb8e4752fd5f8")
  9. add_versions("20210324.1", "441db7c09a0565376ecacf0085b2d4c2bbedde6115d7773551bc116212c2a8d6")
  10. add_versions("20210324.2", "59b862f50e710277f8ede96f083a5bb8d7c9595376146838b9580be90374ee1f")
  11. add_versions("20211102.0", "dcf71b9cba8dc0ca9940c4b316a0c796be8fab42b070bb6b7cab62b48f0e66c4")
  12. add_versions("20220623.0", "4208129b49006089ba1d6710845a45e31c59b0ab6bff9e5788a87f55c5abd602")
  13. add_versions("20230125.2", "9a2b5752d7bfade0bdeee2701de17c9480620f8b237e1964c1b9967c75374906")
  14. add_versions("20230802.1", "987ce98f02eefbaf930d6e38ab16aa05737234d7afbab2d5c4ea7adbe50c28ed")
  15. add_versions("20240116.1", "3c743204df78366ad2eaf236d6631d83f6bc928d1705dd0000b872e53b73dc6a")
  16. add_versions("20240116.2", "733726b8c3a6d39a4120d7e45ea8b41a434cdacde401cba500f14236c49b39dc")
  17. add_versions("20240722.0", "f50e5ac311a81382da7fa75b97310e4b9006474f9560ac46f54a9967f07d4ae3")
  18. add_versions("20250127.0", "16242f394245627e508ec6bb296b433c90f8d914f73b9c026fddb905e27276e8")
  19. add_patches("20240116.1", "https://github.com/abseil/abseil-cpp/commit/3335e58f198e899a500b744163f9b883035a5217.patch", "f83278086b42bc997846d2b931a266678f96e2727fce6ffd98b2b58ce75fa0a3")
  20. add_patches("20240116.2", "https://github.com/abseil/abseil-cpp/commit/3335e58f198e899a500b744163f9b883035a5217.patch", "f83278086b42bc997846d2b931a266678f96e2727fce6ffd98b2b58ce75fa0a3")
  21. add_deps("cmake")
  22. add_configs("cxx_standard", {description = "Select c++ standard to build.", default = "17", type = "string", values = {"14", "17", "20"}})
  23. on_load(function (package)
  24. if package:is_plat("windows", "mingw", "msys") then
  25. package:add("syslinks", "advapi32", "dbghelp", "bcrypt")
  26. elseif package:is_plat("linux", "bsd") then
  27. package:add("syslinks", "pthread")
  28. elseif package:is_plat("macosx", "iphoneos") then
  29. package:add("frameworks", "CoreFoundation")
  30. end
  31. if package:is_plat("windows") and package:config("shared") then
  32. package:add("defines", "ABSL_CONSUME_DLL")
  33. end
  34. end)
  35. on_install(function (package)
  36. if package:version() and package:version():eq("20230802.1") and package:is_plat("mingw") then
  37. io.replace(path.join("absl", "synchronization", "internal", "pthread_waiter.h"), "#ifndef _WIN32", "#if !defined(_WIN32) && !defined(__MINGW32__)", {plain = true})
  38. io.replace(path.join("absl", "synchronization", "internal", "win32_waiter.h"), "#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA", "#if defined(_WIN32) && !defined(__MINGW32__) && _WIN32_WINNT >= _WIN32_WINNT_VISTA", {plain = true})
  39. end
  40. io.replace("CMakeLists.txt", [[set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")]], "", {plain = true})
  41. io.replace("CMakeLists.txt", [[set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")]], "", {plain = true})
  42. local configs = {
  43. "-DCMAKE_CXX_STANDARD=" .. package:config("cxx_standard"),
  44. "-DABSL_ENABLE_INSTALL=ON",
  45. "-DABSL_PROPAGATE_CXX_STD=ON",
  46. }
  47. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  48. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  49. import("package.tools.cmake").install(package, configs, {buildir = os.tmpfile() .. ".dir"})
  50. -- get links and ensure link order
  51. import("core.base.graph")
  52. local dag = graph.new(true)
  53. local pkgconfigdir = package:installdir("lib", "pkgconfig")
  54. for _, pcfile in ipairs(os.files(path.join(pkgconfigdir, "*.pc"))) do
  55. local link = path.basename(pcfile)
  56. local content = io.readfile(pcfile)
  57. for _, line in ipairs(content:split("\n")) do
  58. if line:startswith("Requires: ") then
  59. local requires = line:sub(10):split(",")
  60. for _, dep in ipairs(requires) do
  61. dep = dep:split("=")[1]:trim()
  62. dag:add_edge(link, dep)
  63. end
  64. end
  65. end
  66. end
  67. local links = dag:topological_sort()
  68. package:add("links", links)
  69. local cycle = dag:find_cycle()
  70. if cycle then
  71. wprint("cycle links found", cycle)
  72. end
  73. end)
  74. on_test(function (package)
  75. assert(package:check_cxxsnippets({test = [[
  76. #include "absl/strings/numbers.h"
  77. #include "absl/strings/str_join.h"
  78. #include <iostream>
  79. #include <string>
  80. #include <vector>
  81. void test() {
  82. std::vector<std::string> v = {"foo", "bar", "baz"};
  83. std::string s = absl::StrJoin(v, "-");
  84. int result = 0;
  85. auto a = absl::SimpleAtoi("123", &result);
  86. std::cout << "Joined string: " << s << "\\n";
  87. }
  88. ]]}, {configs = {languages = "cxx" .. package:config("cxx_standard")}}))
  89. end)