xmake.lua 10 KB

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