xmake.lua 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 package:config("tcmalloc") then
  48. local libsuffix = package:config("minimal") and "_minimal" or ""
  49. libsuffix = package:is_debug() and libsuffix .. "_debug" or libsuffix
  50. package:add("links", "tcmalloc" .. libsuffix)
  51. end
  52. if package:config("profiler") then
  53. package:add("links", "profiler")
  54. end
  55. end)
  56. on_install("windows|!arm64", "macosx", "linux", "mingw", function (package)
  57. local configs = {"-DBUILD_TESTING=OFF", "-Dgperftools_build_benchmark=OFF"}
  58. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  59. table.insert(configs, "-DGPERFTOOLS_BUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
  60. table.insert(configs, "-Dgperftools_build_minimal=" .. (package:config("minimal") and "ON" or "OFF"))
  61. if package:is_plat("linux") then
  62. table.insert(configs, "-Dgperftools_enable_libunwind=" .. (package:config("unwind") and "ON" or "OFF"))
  63. end
  64. io.replace("CMakeLists.txt", "if(MINGW OR MSVC)", "if(MINGW OR MSVC)\nlink_libraries(psapi synchronization shlwapi)", {plain = true})
  65. io.replace("src/windows/port.h", "inline int nanosleep", "extern \"C\" inline int nanosleep", {plain = true})
  66. if package:version():le("2.15") then
  67. import("package.tools.cmake").install(package, configs)
  68. else
  69. import("package.tools.cmake").build(package, configs, {buildir = "build"})
  70. os.trycp("build/gperftools", package:installdir("include"))
  71. os.trycp("build/**.a", package:installdir("lib"))
  72. os.trycp("build/**.dylib", package:installdir("lib"))
  73. os.trycp("build/**.so", package:installdir("lib"))
  74. os.trycp("build/**.lib", package:installdir("lib"))
  75. os.trycp("build/**.dll", package:installdir("bin"))
  76. end
  77. end)
  78. on_test(function (package)
  79. assert(package:has_cfuncs("tc_version", {includes = "gperftools/tcmalloc.h"}))
  80. end)