xmake.lua 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. includes(path.join(os.scriptdir(), "versions.lua"))
  2. package("libcurl")
  3. set_homepage("https://curl.haxx.se/")
  4. set_description("The multiprotocol file transfer library.")
  5. set_license("MIT")
  6. set_urls("https://curl.haxx.se/download/curl-$(version).tar.bz2",
  7. "http://curl.mirror.anstey.ca/curl-$(version).tar.bz2")
  8. add_urls("https://github.com/curl/curl/releases/download/curl-$(version).tar.bz2",
  9. {version = function (version) return (version:gsub("%.", "_")) .. "/curl-" .. version end})
  10. if add_versionfiles then
  11. add_versionfiles("versions.txt")
  12. else
  13. add_versions_list()
  14. end
  15. add_deps("cmake")
  16. if is_plat("macosx", "iphoneos") then
  17. add_frameworks("Security", "CoreFoundation", "SystemConfiguration")
  18. elseif is_plat("linux") then
  19. add_syslinks("pthread")
  20. elseif is_plat("windows", "mingw") then
  21. add_syslinks("advapi32", "crypt32", "wldap32", "winmm", "ws2_32", "user32")
  22. end
  23. add_configs("cares", {description = "Enable c-ares support.", default = false, type = "boolean"})
  24. add_configs("openssl", {description = "Enable OpenSSL for SSL/TLS.", default = is_plat("linux", "android", "cross"), type = "boolean"})
  25. add_configs("mbedtls", {description = "Enable mbedTLS for SSL/TLS.", default = false, type = "boolean"})
  26. add_configs("nghttp2", {description = "Use Nghttp2 library.", default = false, type = "boolean"})
  27. add_configs("openldap", {description = "Use OpenLDAP library.", default = false, type = "boolean"})
  28. add_configs("libidn2", {description = "Use Libidn2 for IDN support.", default = false, type = "boolean"})
  29. add_configs("zlib", {description = "Enable zlib support.", default = false, type = "boolean"})
  30. add_configs("zstd", {description = "Enable zstd support.", default = false, type = "boolean"})
  31. add_configs("brotli", {description = "Enable brotli support.", default = false, type = "boolean"})
  32. add_configs("libssh2", {description = "Use libSSH2 library.", default = false, type = "boolean"})
  33. add_configs("libpsl", {description = "Use libpsl library.", default = false, type = "boolean"})
  34. if is_plat("mingw") and is_subhost("msys") then
  35. add_extsources("pacman::curl")
  36. elseif is_plat("linux") then
  37. add_extsources("pacman::curl", "apt::libcurl4-gnutls-dev", "apt::libcurl4-nss-dev", "apt::libcurl4-openssl-dev")
  38. elseif is_plat("macosx") then
  39. add_extsources("brew::curl")
  40. end
  41. on_load(function (package)
  42. if package:is_plat("windows", "mingw") then
  43. if not package:config("shared") then
  44. package:add("defines", "CURL_STATICLIB")
  45. end
  46. end
  47. local configdeps = {cares = "c-ares",
  48. openssl = "openssl",
  49. mbedtls = "mbedtls",
  50. nghttp2 = "nghttp2",
  51. openldap = "openldap",
  52. libidn2 = "libidn2",
  53. libpsl = "libpsl",
  54. zlib = "zlib",
  55. zstd = "zstd",
  56. brotli = "brotli",
  57. libssh2 = "libssh2"}
  58. local has_deps = false
  59. for name, dep in pairs(configdeps) do
  60. if package:config(name) then
  61. package:add("deps", dep)
  62. has_deps = true
  63. end
  64. end
  65. if has_deps and package:is_plat("linux", "macosx") then
  66. package:add("deps", "pkg-config")
  67. end
  68. end)
  69. on_install("windows", "mingw", "linux", "macosx", "iphoneos", "cross", function (package)
  70. local version = package:version()
  71. local configs = {"-DBUILD_TESTING=OFF", "-DENABLE_MANUAL=OFF"}
  72. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  73. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  74. if (package:is_plat("mingw") and version:ge("7.85")) then
  75. package:add("syslinks", "bcrypt")
  76. end
  77. local configopts = {cares = "ENABLE_ARES",
  78. openssl = (version:ge("7.81") and "CURL_USE_OPENSSL" or "CMAKE_USE_OPENSSL"),
  79. mbedtls = (version:ge("7.81") and "CURL_USE_MBEDTLS" or "CMAKE_USE_MBEDTLS"),
  80. nghttp2 = "USE_NGHTTP2",
  81. libidn2 = "USE_LIBIDN2",
  82. zlib = "CURL_ZLIB",
  83. zstd = "CURL_ZSTD",
  84. brotli = "CURL_BROTLI",
  85. libssh2 = (version:ge("7.81") and "CURL_USE_LIBSSH2" or "CMAKE_USE_LIBSSH2"),
  86. libpsl = "CURL_USE_LIBPSL"}
  87. for name, opt in pairs(configopts) do
  88. table.insert(configs, "-D" .. opt .. "=" .. (package:config(name) and "ON" or "OFF"))
  89. end
  90. if not package:config("openldap") then
  91. table.insert(configs, "-DCURL_DISABLE_LDAP=ON")
  92. end
  93. if package:is_plat("windows", "mingw") then
  94. table.insert(configs, (version:ge("7.80") and "-DCURL_USE_SCHANNEL=ON" or "-DCMAKE_USE_SCHANNEL=ON"))
  95. end
  96. if package:is_plat("macosx", "iphoneos") then
  97. table.insert(configs, (version:ge("7.65") and "-DCURL_USE_SECTRANSP=ON" or "-DCMAKE_USE_DARWINSSL=ON"))
  98. end
  99. if package:is_plat("windows") then
  100. table.insert(configs, "-DCURL_STATIC_CRT=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
  101. end
  102. if package:is_plat("mingw") and version:le("7.85.0") then
  103. io.replace("src/CMakeLists.txt", 'COMMAND ${CMAKE_COMMAND} -E echo "/* built-in manual is disabled, blank function */" > tool_hugehelp.c', "", {plain = true})
  104. end
  105. if package:is_plat("linux", "cross") then
  106. io.replace("CMakeLists.txt", "list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto)", "list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto dl)", {plain = true})
  107. io.replace("CMakeLists.txt", "list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})", "list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES} dl)", {plain = true})
  108. end
  109. import("package.tools.cmake").install(package, configs, opt)
  110. end)
  111. on_install("android", function (package)
  112. local configs = {"--disable-silent-rules",
  113. "--disable-dependency-tracking",
  114. "--without-hyper",
  115. "--without-libgsasl",
  116. "--without-librtmp",
  117. "--without-quiche",
  118. "--without-ngtcp2",
  119. "--without-nghttp3"}
  120. local version = package:version()
  121. if (package:is_plat("mingw") and version:ge("7.85")) then
  122. package:add("syslinks", "Bcrypt")
  123. end
  124. table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
  125. table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
  126. if package:debug() then
  127. table.insert(configs, "--enable-debug")
  128. end
  129. if package:is_plat("macosx", "iphoneos") then
  130. table.insert(configs, (package:version():ge("7.77") and "--with-secure-transport" or "--with-darwinssl"))
  131. end
  132. for _, name in ipairs({"openssl", "mbedtls", "zlib", "brotli", "zstd", "libssh2", "libidn2", "libpsl", "nghttp2"}) do
  133. table.insert(configs, package:config(name) and "--with-" .. name or "--without-" .. name)
  134. end
  135. table.insert(configs, package:config("cares") and "--enable-ares" or "--disable-ares")
  136. table.insert(configs, package:config("openldap") and "--enable-ldap" or "--disable-ldap")
  137. if package:is_plat("macosx") then
  138. local cares = package:dep("c-ares")
  139. if cares and not cares:config("shared") then
  140. -- we need fix missing `-lresolv` when checking c-ares
  141. io.replace("./configure", "PKGCONFIG --libs-only-l libcares", "PKGCONFIG --libs-only-l --static libcares", {plain = true})
  142. end
  143. end
  144. import("package.tools.autoconf").install(package, configs)
  145. end)
  146. on_test(function (package)
  147. assert(package:has_cfuncs("curl_version", {includes = "curl/curl.h"}))
  148. end)