xmake.lua 6.6 KB

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