xmake.lua 6.7 KB

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