xmake.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package("gperftools")
  2. set_homepage("https://github.com/gperftools/gperftools")
  3. set_description("gperftools is a collection of a high-performance multi-threaded malloc() implementation, plus some pretty nifty performance analysis tools.")
  4. set_license("BSD-3-Clause")
  5. add_urls("https://github.com/gperftools/gperftools/archive/refs/tags/gperftools-$(version).tar.gz",
  6. "https://github.com/gperftools/gperftools.git")
  7. add_versions("2.16", "737be182b4e42f5c7f595da2a7aa59ce0489a73d336d0d16847f2aa52d5221b4")
  8. add_versions("2.15", "3918ff2e21bb3dbb5a801e1daf55fb20421906f7c42fbb482bede7bdc15dfd2e")
  9. add_versions("2.14", "ab456a74af2f57a3ee6c20462f73022d11f7ffc22e470fc06dec39692c0ee5f3")
  10. add_versions("2.13", "fd43adbe0419cb0eaaa3e439845cc89fe7d42c22eff7fd2d6b7e87ae2acbce1d")
  11. add_versions("2.12", "1cc42af8c0ec117695ecfa49ef518d9eaf7b215a2657b51f655daa2dc07101ce")
  12. add_versions("2.11", "b0d32b3d82da0ddac2a347412b50f97efddeae66dfbceb49455b7262fb965434")
  13. add_versions("2.10", "b0dcfe3aca1a8355955f4b415ede43530e3bb91953b6ffdd75c45891070fe0f1")
  14. if is_plat("linux") then
  15. add_extsources("pacman::gperftools", "apt::libgoogle-perftools-dev")
  16. elseif is_plat("macosx") then
  17. add_extsources("brew::gperftools")
  18. end
  19. add_configs("minimal", {description = "Build only tcmalloc-minimal (and maybe tcmalloc-minimal-debug)", default = is_plat("windows", "mingw"), type = "boolean"})
  20. add_configs("tcmalloc", {description = "Use tcmalloc", default = true, type = "boolean"})
  21. add_configs("profiler", {description = "Use profiler", default = true, type = "boolean"})
  22. if is_plat("linux") then
  23. add_configs("unwind", {description = "Enable libunwind support.", default = false, type = "boolean"})
  24. end
  25. add_deps("cmake")
  26. if on_check then
  27. on_check("windows", "mingw", function (package)
  28. assert(package:config("minimal"), "package(gperftools): only tcmalloc_minimal is supported on Windows or MinGW")
  29. if package:is_plat("windows") then
  30. assert(package:version():ge("2.16") or package:version():eq("2.10"), "package(gperftools): requires version = 2.10 or >= 2.16 for Windows")
  31. else
  32. assert(package:version():ge("2.16"), "package(gperftools): requires version >= 2.16 for MinGW")
  33. end
  34. end)
  35. on_check("macosx", function (package)
  36. if not package:version():ge("2.14") then
  37. if not (package:version():eq("2.10") and macos.version():le("12")) then
  38. raise("package(gperftools): requires version >= 2.14 for macOS")
  39. end
  40. end
  41. end)
  42. end
  43. on_load(function (package)
  44. if package:is_plat("linux") and package:config("unwind") then
  45. package:add("deps", "libunwind")
  46. end
  47. if not package:config("shared") then
  48. package:add("defines", "PERFTOOLS_DLL_DECL=")
  49. end
  50. if package:config("tcmalloc") then
  51. local libsuffix = package:config("minimal") and "_minimal" or ""
  52. libsuffix = package:is_debug() and libsuffix .. "_debug" or libsuffix
  53. package:add("links", "tcmalloc" .. libsuffix)
  54. end
  55. if package:config("profiler") then
  56. package:add("links", "profiler")
  57. end
  58. package:add("links", "stacktrace", "common")
  59. end)
  60. on_install("windows|!arm64", "macosx", "linux", "mingw", function (package)
  61. local configs = {"-DBUILD_TESTING=OFF", "-Dgperftools_build_benchmark=OFF"}
  62. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  63. table.insert(configs, "-DGPERFTOOLS_BUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
  64. table.insert(configs, "-Dgperftools_build_minimal=" .. (package:config("minimal") and "ON" or "OFF"))
  65. if package:is_plat("linux") then
  66. table.insert(configs, "-Dgperftools_enable_libunwind=" .. (package:config("unwind") and "ON" or "OFF"))
  67. end
  68. io.replace("CMakeLists.txt", "if(MINGW OR MSVC)", "if(MINGW OR MSVC)\nlink_libraries(psapi synchronization shlwapi)", {plain = true})
  69. io.replace("src/windows/port.h", "inline int nanosleep", "extern \"C\" inline int nanosleep", {plain = true})
  70. if package:version():le("2.15") then
  71. import("package.tools.cmake").install(package, configs)
  72. else
  73. import("package.tools.cmake").build(package, configs, {buildir = "xmakebuild"})
  74. os.trycp("xmakebuild/gperftools", package:installdir("include"))
  75. os.trycp("xmakebuild/**.a", package:installdir("lib"))
  76. os.trycp("xmakebuild/**.dylib", package:installdir("lib"))
  77. os.trycp("xmakebuild/**.so", package:installdir("lib"))
  78. os.trycp("xmakebuild/**.lib", package:installdir("lib"))
  79. os.trycp("xmakebuild/**.dll", package:installdir("bin"))
  80. end
  81. end)
  82. on_test(function (package)
  83. assert(package:has_cfuncs("tc_version", {includes = "gperftools/tcmalloc.h"}))
  84. end)