xmake.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. if is_plat("macosx", "iphoneos") then
  12. add_frameworks("Security", "CoreFoundation", "SystemConfiguration")
  13. elseif is_plat("linux") then
  14. add_syslinks("pthread")
  15. elseif is_plat("windows", "mingw") then
  16. add_deps("cmake")
  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", "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. on_load(function (package)
  31. if package:is_plat("windows", "mingw") then
  32. if not package:config("shared") then
  33. package:add("defines", "CURL_STATICLIB")
  34. end
  35. end
  36. local configdeps = {cares = "c-ares",
  37. openssl = "openssl",
  38. mbedtls = "mbedtls",
  39. nghttp2 = "nghttp2",
  40. openldap = "openldap",
  41. libidn2 = "libidn2",
  42. libpsl = "libpsl",
  43. zlib = "zlib",
  44. zstd = "zstd",
  45. brotli = "brotli",
  46. libssh2 = "libssh2"}
  47. local has_deps = false
  48. for name, dep in pairs(configdeps) do
  49. if package:config(name) then
  50. package:add("deps", dep)
  51. has_deps = true
  52. end
  53. end
  54. if has_deps and package:is_plat("linux", "macosx") then
  55. package:add("deps", "pkg-config")
  56. end
  57. end)
  58. on_install("windows", "mingw", function (package)
  59. local configs = {"-DBUILD_TESTING=OFF", "-DENABLE_MANUAL=OFF"}
  60. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  61. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  62. table.insert(configs, (package:version():ge("7.80") and "-DCURL_USE_SCHANNEL=ON" or "-DCMAKE_USE_SCHANNEL=ON"))
  63. local version = package:version()
  64. if (package:is_plat("mingw") and version:ge("7.85")) then
  65. package:add("syslinks", "bcrypt")
  66. end
  67. local configopts = {cares = "ENABLE_ARES",
  68. openssl = (version:ge("7.81") and "CURL_USE_OPENSSL" or "CMAKE_USE_OPENSSL"),
  69. mbedtls = (version:ge("7.81") and "CURL_USE_MBEDTLS" or "CMAKE_USE_MBEDTLS"),
  70. nghttp2 = "USE_NGHTTP2",
  71. openldap = "CURL_USE_OPENLDAP",
  72. libidn2 = "USE_LIBIDN2",
  73. zlib = "CURL_ZLIB",
  74. zstd = "CURL_ZSTD",
  75. brotli = "CURL_BROTLI",
  76. libssh2 = (version:ge("7.81") and "CURL_USE_LIBSSH2" or "CMAKE_USE_LIBSSH2"),
  77. libpsl = "CURL_USE_LIBPSL"}
  78. for name, opt in pairs(configopts) do
  79. table.insert(configs, "-D" .. opt .. "=" .. (package:config(name) and "ON" or "OFF"))
  80. end
  81. if package:is_plat("windows") then
  82. table.insert(configs, "-DCURL_STATIC_CRT=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
  83. end
  84. if package:is_plat("mingw") and version:le("7.85.0") then
  85. io.replace("src/CMakeLists.txt", 'COMMAND ${CMAKE_COMMAND} -E echo "/* built-in manual is disabled, blank function */" > tool_hugehelp.c', "", {plain = true})
  86. end
  87. import("package.tools.cmake").install(package, configs)
  88. end)
  89. on_install("macosx", "linux", "cross", function (package)
  90. local configs = {"--disable-silent-rules",
  91. "--disable-dependency-tracking",
  92. "--without-hyper",
  93. "--without-libgsasl",
  94. "--without-librtmp",
  95. "--without-quiche",
  96. "--without-ngtcp2",
  97. "--without-nghttp3"}
  98. local version = package:version()
  99. if (package:is_plat("mingw") and version:ge("7.85")) then
  100. package:add("syslinks", "Bcrypt")
  101. end
  102. table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
  103. table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
  104. if package:debug() then
  105. table.insert(configs, "--enable-debug")
  106. end
  107. if package:is_plat("macosx", "iphoneos") then
  108. table.insert(configs, (package:version():ge("7.77") and "--with-secure-transport" or "--with-darwinssl"))
  109. end
  110. for _, name in ipairs({"openssl", "mbedtls", "zlib", "brotli", "zstd", "libssh2", "libidn2", "libpsl", "nghttp2"}) do
  111. table.insert(configs, package:config(name) and "--with-" .. name or "--without-" .. name)
  112. end
  113. table.insert(configs, package:config("cares") and "--enable-ares" or "--disable-ares")
  114. table.insert(configs, package:config("openldap") and "--enable-ldap" or "--disable-ldap")
  115. if package:is_plat("macosx") then
  116. local cares = package:dep("c-ares")
  117. if cares and not cares:config("shared") then
  118. -- we need fix missing `-lresolv` when checking c-ares
  119. io.replace("./configure", "PKGCONFIG --libs-only-l libcares", "PKGCONFIG --libs-only-l --static libcares", {plain = true})
  120. end
  121. end
  122. import("package.tools.autoconf").install(package, configs)
  123. end)
  124. on_test(function (package)
  125. assert(package:has_cfuncs("curl_version", {includes = "curl/curl.h"}))
  126. end)