xmake.lua 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package("glog")
  2. set_homepage("https://github.com/google/glog/")
  3. set_description("C++ implementation of the Google logging module")
  4. set_license("BSD-3-Clause")
  5. add_urls("https://github.com/google/glog/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/google/glog.git")
  7. add_versions("v0.7.1", "00e4a87e87b7e7612f519a41e491f16623b12423620006f59f5688bfd8d13b08")
  8. add_versions("v0.7.0", "375106b5976231b92e66879c1a92ce062923b9ae573c42b56ba28b112ee4cc11")
  9. add_versions("v0.6.0", "8a83bf982f37bb70825df71a9709fa90ea9f4447fb3c099e1d720a439d88bad6")
  10. add_versions("v0.5.0", "eede71f28371bf39aa69b45de23b329d37214016e2055269b3b5e7cfd40b59f5")
  11. add_versions("v0.4.0", "f28359aeba12f30d73d9e4711ef356dc842886968112162bc73002645139c39c")
  12. local configdeps = {gtest = "gtest", gflags = "gflags", unwind = "libunwind"}
  13. for config, dep in pairs(configdeps) do
  14. add_configs(config, {description = "Enable " .. dep .. " support.", default = (config == "gflags"), type = "boolean"})
  15. end
  16. add_deps("cmake")
  17. if is_plat("linux") then
  18. add_syslinks("pthread")
  19. elseif is_plat("windows") then
  20. add_syslinks("dbghelp")
  21. end
  22. on_load(function (package)
  23. if package:is_plat("windows") then
  24. if package:version():le("0.4") and not package:config("shared") then
  25. package:add("defines", "GOOGLE_GLOG_DLL_DECL=")
  26. end
  27. package:add("defines", "GLOG_NO_ABBREVIATED_SEVERITIES")
  28. end
  29. for config, dep in pairs(configdeps) do
  30. if package:config(config) then
  31. package:add("deps", dep)
  32. end
  33. end
  34. end)
  35. on_install(function (package)
  36. local configs = {"-DBUILD_TESTING=OFF", "-DCMAKE_INSTALL_LIBDIR=lib"}
  37. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  38. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  39. for config, dep in pairs(configdeps) do
  40. table.insert(configs, "-DWITH_" .. config:upper() .. "=" .. (package:config(config) and "ON" or "OFF"))
  41. end
  42. -- fix cmake try run
  43. if package:is_plat("mingw") then
  44. table.insert(configs, "-DHAVE_SYMBOLIZE_EXITCODE=ON")
  45. end
  46. import("package.tools.cmake").install(package, configs)
  47. -- fix https://github.com/xmake-io/xmake-repo/discussions/4221
  48. if package:version() and package:version():ge("0.7.0") then
  49. io.replace(path.join(package:installdir("include"), "glog/logging.h"),
  50. "#define GLOG_LOGGING_H", "#define GLOG_LOGGING_H\n#define GLOG_USE_GLOG_EXPORT", {plain = true})
  51. end
  52. end)
  53. on_test(function (package)
  54. local languages
  55. if package:version():ge("0.7.0") then
  56. languages = "c++14"
  57. end
  58. assert(package:has_cxxfuncs("google::InitGoogleLogging(\"glog\")", {includes = "glog/logging.h", configs = {languages = languages}}))
  59. end)