xmake.lua 8.2 KB

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