xmake.lua 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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_patches("7.84.0", path.join(os.scriptdir(), "patches", "7.84.0", "sched.patch"), "e79f56f840cbc6996a153f19d9266bd46fe4154e6b494c8ee0478cb5b87662d3")
  16. add_patches("8.7.1", path.join(os.scriptdir(), "patches", "8.7.1", "android_armv7.patch"), "b172fd25063fcf4bce987b47a3d95d9d79bcf80f45e7e45dbf4aba72c685fb24")
  17. add_deps("cmake")
  18. if is_plat("macosx", "iphoneos") then
  19. add_frameworks("Security", "CoreFoundation", "SystemConfiguration")
  20. elseif is_plat("linux") then
  21. add_syslinks("pthread")
  22. elseif is_plat("windows", "mingw") then
  23. add_syslinks("advapi32", "crypt32", "wldap32", "winmm", "ws2_32", "user32")
  24. end
  25. add_configs("cares", {description = "Enable c-ares support.", default = false, type = "boolean"})
  26. add_configs("openssl", {description = "Enable OpenSSL for SSL/TLS.", default = is_plat("linux", "android", "cross"), type = "boolean"})
  27. add_configs("mbedtls", {description = "Enable mbedTLS for SSL/TLS.", default = false, type = "boolean"})
  28. add_configs("nghttp2", {description = "Use Nghttp2 library.", default = false, type = "boolean"})
  29. add_configs("openldap", {description = "Use OpenLDAP library.", default = false, type = "boolean"})
  30. add_configs("libidn2", {description = "Use Libidn2 for IDN support.", default = false, type = "boolean"})
  31. add_configs("zlib", {description = "Enable zlib support.", default = false, type = "boolean"})
  32. add_configs("zstd", {description = "Enable zstd support.", default = false, type = "boolean"})
  33. add_configs("brotli", {description = "Enable brotli support.", default = false, type = "boolean"})
  34. add_configs("libssh2", {description = "Use libSSH2 library.", default = false, type = "boolean"})
  35. add_configs("libpsl", {description = "Use libpsl library.", default = false, type = "boolean"})
  36. if is_plat("mingw") and is_subhost("msys") then
  37. add_extsources("pacman::curl")
  38. elseif is_plat("linux") then
  39. add_extsources("pacman::curl", "apt::libcurl4-gnutls-dev", "apt::libcurl4-nss-dev", "apt::libcurl4-openssl-dev")
  40. elseif is_plat("macosx") then
  41. add_extsources("brew::curl")
  42. end
  43. on_load(function (package)
  44. if package:is_plat("windows", "mingw") then
  45. if not package:config("shared") then
  46. package:add("defines", "CURL_STATICLIB")
  47. end
  48. end
  49. local configdeps = {cares = "c-ares",
  50. openssl = "openssl",
  51. mbedtls = "mbedtls",
  52. nghttp2 = "nghttp2",
  53. openldap = "openldap",
  54. libidn2 = "libidn2",
  55. libpsl = "libpsl",
  56. zlib = "zlib",
  57. zstd = "zstd",
  58. brotli = "brotli",
  59. libssh2 = "libssh2"}
  60. local has_deps = false
  61. for name, dep in pairs(configdeps) do
  62. if package:config(name) then
  63. package:add("deps", dep)
  64. has_deps = true
  65. end
  66. end
  67. if has_deps and package:is_plat("linux", "macosx") then
  68. package:add("deps", "pkg-config")
  69. end
  70. end)
  71. on_install("windows", "mingw", "linux", "macosx", "iphoneos", "cross", "android", function (package)
  72. local version = package:version()
  73. local configs = {"-DBUILD_TESTING=OFF", "-DENABLE_MANUAL=OFF"}
  74. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  75. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  76. if (package:is_plat("mingw") and version:ge("7.85")) then
  77. package:add("syslinks", "bcrypt")
  78. end
  79. local configopts = {cares = "ENABLE_ARES",
  80. openssl = (version:ge("7.81") and "CURL_USE_OPENSSL" or "CMAKE_USE_OPENSSL"),
  81. mbedtls = (version:ge("7.81") and "CURL_USE_MBEDTLS" or "CMAKE_USE_MBEDTLS"),
  82. nghttp2 = "USE_NGHTTP2",
  83. libidn2 = "USE_LIBIDN2",
  84. zlib = "CURL_ZLIB",
  85. zstd = "CURL_ZSTD",
  86. brotli = "CURL_BROTLI",
  87. libssh2 = (version:ge("7.81") and "CURL_USE_LIBSSH2" or "CMAKE_USE_LIBSSH2"),
  88. libpsl = "CURL_USE_LIBPSL"}
  89. for name, opt in pairs(configopts) do
  90. table.insert(configs, "-D" .. opt .. "=" .. (package:config(name) and "ON" or "OFF"))
  91. end
  92. if not package:config("openldap") then
  93. table.insert(configs, "-DCURL_DISABLE_LDAP=ON")
  94. end
  95. if package:is_plat("windows", "mingw") then
  96. table.insert(configs, (version:ge("7.80") and "-DCURL_USE_SCHANNEL=ON" or "-DCMAKE_USE_SCHANNEL=ON"))
  97. end
  98. if package:is_plat("macosx", "iphoneos") then
  99. table.insert(configs, (version:ge("7.65") and "-DCURL_USE_SECTRANSP=ON" or "-DCMAKE_USE_DARWINSSL=ON"))
  100. end
  101. if package:is_plat("windows") then
  102. table.insert(configs, "-DCURL_STATIC_CRT=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
  103. end
  104. if package:is_plat("mingw") and version:le("7.85.0") then
  105. io.replace("src/CMakeLists.txt", 'COMMAND ${CMAKE_COMMAND} -E echo "/* built-in manual is disabled, blank function */" > tool_hugehelp.c', "", {plain = true})
  106. end
  107. if package:is_plat("linux", "cross") then
  108. io.replace("CMakeLists.txt", "list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto)", "list(APPEND CURL_LIBS OpenSSL::SSL OpenSSL::Crypto dl)", {plain = true})
  109. io.replace("CMakeLists.txt", "list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})", "list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES} dl)", {plain = true})
  110. end
  111. local function handledependency(conf, depname, includeconfig, libconfig)
  112. if package:config(conf) then
  113. local dep = package:dep(depname)
  114. if dep and not dep:is_system() then
  115. local fetchinfo = dep:fetch({external = false})
  116. if fetchinfo then
  117. local includedirs = fetchinfo.includedirs or fetchinfo.sysincludedirs
  118. if includedirs and #includedirs > 0 then
  119. table.insert(configs, "-D" .. includeconfig .. "=" .. table.concat(includedirs, ";"):gsub("\\", "/"))
  120. end
  121. if type(libconfig) == "table" then
  122. if fetchinfo.libfiles then
  123. for _, libfile in ipairs(fetchinfo.libfiles) do
  124. local libname = path.basename(libfile)
  125. if libname:startswith("lib") then
  126. libname = libname:sub(4)
  127. end
  128. for opt, suffix in pairs(libconfig) do
  129. if libname:endswith(suffix) then
  130. table.insert(configs, "-D" .. opt .. "=" .. libfile:gsub("\\", "/"))
  131. end
  132. end
  133. end
  134. end
  135. else
  136. if fetchinfo.libfiles then
  137. table.insert(configs, "-D" .. libconfig .. "=" .. table.concat(fetchinfo.libfiles, ";"):gsub("\\", "/"))
  138. end
  139. end
  140. end
  141. end
  142. end
  143. end
  144. handledependency("brotli", "brotli", "BROTLI_INCLUDE_DIR", {BROTLICOMMON_LIBRARY = "brotlicommon", BROTLIDEC_LIBRARY = "brotlidec"})
  145. handledependency("openssl", "openssl", "OPENSSL_INCLUDE_DIR", {OPENSSL_CRYPTO_LIBRARY = "crypto", OPENSSL_SSL_LIBRARY = "ssl"})
  146. handledependency("mbedtls", "mbedtls", "MBEDTLS_INCLUDE_DIRS", {MBEDTLS_LIBRARY = "mbedtls", MBEDX509_LIBRARY = "mbedx509", MBEDCRYPTO_LIBRARY = "mbedcrypto"})
  147. handledependency("zlib", "zlib", "ZLIB_INCLUDE_DIR", "ZLIB_LIBRARY")
  148. handledependency("zstd", "zstd", "Zstd_INCLUDE_DIR", "Zstd_LIBRARY")
  149. import("package.tools.cmake").install(package, configs, opt)
  150. end)
  151. on_test(function (package)
  152. assert(package:has_cfuncs("curl_version", {includes = "curl/curl.h"}))
  153. end)