xmake.lua 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package("libgit2")
  2. set_homepage("https://libgit2.org/")
  3. set_description("A cross-platform, linkable library implementation of Git that you can use in your application.")
  4. set_license("GPL-2.0-only")
  5. set_urls("https://github.com/libgit2/libgit2/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/libgit2/libgit2.git")
  7. add_versions("v1.9.0", "75b27d4d6df44bd34e2f70663cfd998f5ec41e680e1e593238bbe517a84c7ed2")
  8. add_versions("v1.8.4", "49d0fc50ab931816f6bfc1ac68f8d74b760450eebdb5374e803ee36550f26774")
  9. add_versions("v1.8.2", "184699f0d9773f96eeeb5cb245ba2304400f5b74671f313240410f594c566a28")
  10. add_versions("v1.8.1", "8c1eaf0cf07cba0e9021920bfba9502140220786ed5d8a8ec6c7ad9174522f8e")
  11. add_versions("v1.8.0", "9e1d6a880d59026b675456fbb1593c724c68d73c34c0d214d6eb848e9bbd8ae4")
  12. add_versions("v1.7.1", "17d2b292f21be3892b704dddff29327b3564f96099a1c53b00edc23160c71327")
  13. add_versions("v1.3.0", "192eeff84596ff09efb6b01835a066f2df7cd7985e0991c79595688e6b36444e")
  14. add_configs("ssh", {description = "Enable SSH support", default = false, type = "boolean"})
  15. add_configs("tools", {description = "Build tools", default = false, type = "boolean"})
  16. add_configs("https", {description = "Select crypto backend.", default = (is_plat("windows", "mingw") and "winhttp" or "openssl3"), type = "string", values = {"winhttp", "openssl3", "mbedtls"}})
  17. if is_plat("linux", "bsd") then
  18. add_syslinks("pthread", "dl")
  19. elseif is_plat("windows", "mingw") then
  20. add_syslinks("ole32", "rpcrt4", "winhttp", "ws2_32", "user32", "crypt32", "advapi32")
  21. elseif is_plat("macosx", "iphoneos") then
  22. add_frameworks("CoreFoundation", "Security")
  23. add_syslinks("iconv", "z")
  24. end
  25. add_deps("cmake")
  26. if is_subhost("windows") then
  27. add_deps("pkgconf")
  28. end
  29. add_deps("pcre2", "llhttp")
  30. if not is_plat("macosx", "iphoneos") then
  31. add_deps("zlib")
  32. end
  33. if on_check then
  34. on_check("windows", function (package)
  35. -- undefined symbol __except_handler4_common(msvcrt)
  36. if package:is_arch("x86") and package:has_runtime("MD", "MDd") and package:config("shared") then
  37. raise("package(libgit2) unsupported x86 & MD & shared")
  38. end
  39. end)
  40. on_check("android", function (package)
  41. if package:is_arch("armeabi-v7a") then
  42. local ndk = package:toolchain("ndk")
  43. local ndkver = ndk:config("ndkver")
  44. assert(ndkver and tonumber(ndkver) > 22, "package(libgit2) deps(pcre2) require ndk version > 22")
  45. end
  46. end)
  47. end
  48. on_load(function (package)
  49. local https = package:config("https")
  50. if https ~= "winhttp" then
  51. package:add("deps", https)
  52. end
  53. if package:config("ssh") then
  54. local backend
  55. if https == "winhttp" then
  56. backend = "wincng"
  57. else
  58. backend = https
  59. end
  60. package:add("deps", "libssh2", {configs = {backend = backend}})
  61. end
  62. end)
  63. on_install(function (package)
  64. if package:is_plat("android") then
  65. for _, file in ipairs(os.files("src/**.txt")) do
  66. if path.basename(file) == "CMakeLists" then
  67. io.replace(file, "C_STANDARD 90", "C_STANDARD 99", {plain = true})
  68. end
  69. end
  70. elseif package:is_plat("windows") then
  71. -- MDd == _MT + _DLL + _DEBUG
  72. io.replace("cmake/DefaultCFlags.cmake", "/D_DEBUG", "", {plain = true})
  73. -- Use CMAKE_MSVC_RUNTIME_LIBRARY
  74. io.replace("cmake/DefaultCFlags.cmake", "/MT", "", {plain = true})
  75. io.replace("cmake/DefaultCFlags.cmake", "/MTd", "", {plain = true})
  76. io.replace("cmake/DefaultCFlags.cmake", "/MD", "", {plain = true})
  77. io.replace("cmake/DefaultCFlags.cmake", "/MDd", "", {plain = true})
  78. io.replace("CMakeLists.txt", "/GL", "", {plain = true})
  79. if package:version():eq("1.7.1") then
  80. io.replace("cmake/DefaultCFlags.cmake", "/GL", "", {plain = true})
  81. end
  82. end
  83. local https = package:config("https")
  84. if https ~= "winhttp" then
  85. if package:is_plat("windows", "mingw", "msys") then
  86. -- Need to pass `-DUSE_HTTPS=xxxssl`, but let cmake auto-detect is convenient
  87. io.replace("cmake/SelectHTTPSBackend.cmake", "elseif(WIN32)", "elseif(0)", {plain = true})
  88. end
  89. if https == "mbedtls" then
  90. local links = {"${MBEDTLS_LIBRARY}", "${MBEDX509_LIBRARY}", "${MBEDCRYPTO_LIBRARY}"}
  91. if package:is_plat("windows", "mingw", "msys") then
  92. table.join2(links, {"ws2_32", "advapi32", "bcrypt"})
  93. end
  94. io.replace("cmake/FindmbedTLS.cmake",
  95. [["-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}"]],
  96. table.concat(links, " "), {plain = true})
  97. end
  98. end
  99. local configs = {
  100. "-DBUILD_TESTS=OFF",
  101. "-DBUILD_CLAR=OFF",
  102. "-DBUILD_EXAMPLES=OFF",
  103. "-DBUILD_FUZZERS=OFF",
  104. "-DREGEX_BACKEND=pcre2",
  105. "-DUSE_HTTP_PARSER=llhttp",
  106. "-DUSE_GSSAPI=OFF"
  107. }
  108. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  109. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  110. table.insert(configs, "-DUSE_SSH=" .. (package:config("ssh") and "ON" or "OFF"))
  111. table.insert(configs, "-DBUILD_CLI=" .. (package:config("tools") and "ON" or "OFF"))
  112. local opt = {}
  113. opt.packagedeps = {"pcre2"}
  114. if package:is_plat("mingw") then
  115. local mingw = import("detect.sdks.find_mingw")()
  116. local dlltool = assert(os.files(path.join(mingw.bindir, "*dlltool*"))[1], "dlltool not found!")
  117. table.insert(configs, "-DDLLTOOL=" .. dlltool)
  118. end
  119. import("package.tools.cmake").install(package, configs, opt)
  120. if package:is_plat("linux") and linuxos.name() == "fedora" then
  121. io.replace(path.join(package:installdir("lib/pkgconfig"), "libgit2.pc"),
  122. "Requires.private: openssl ", "Requires.private: openssl3 ", {plain = true})
  123. end
  124. end)
  125. on_test(function (package)
  126. assert(package:has_cfuncs("git_repository_init", {includes = "git2.h"}))
  127. end)