xmake.lua 7.2 KB

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