xmake.lua 6.8 KB

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