Skip to content

Commit

Permalink
cpr: support clang-cl toolchain (#6374)
Browse files Browse the repository at this point in the history
* cpr: support clang-cl toolchain

* Update xmake.lua

* Update xmake.lua
  • Loading branch information
star-hengxing authored Feb 16, 2025
1 parent 22778ae commit 02ece0c
Showing 1 changed file with 38 additions and 21 deletions.
59 changes: 38 additions & 21 deletions packages/c/cpr/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package("cpr")

set_homepage("https://docs.libcpr.org/")
set_description("C++ Requests is a simple wrapper around libcurl inspired by the excellent Python Requests project.")
set_license("MIT")

set_urls("https://github.com/libcpr/cpr/archive/refs/tags/$(version).tar.gz",
"https://github.com/libcpr/cpr.git")

add_versions("1.11.1", "e84b8ef348f41072609f53aab05bdaab24bf5916c62d99651dfbeaf282a8e0a2")
add_versions("1.6.2", "c45f9c55797380c6ba44060f0c73713fbd7989eeb1147aedb8723aa14f3afaa3")
add_versions("1.7.2", "aa38a414fe2ffc49af13a08b6ab34df825fdd2e7a1213d032d835a779e14176f")
add_versions("1.8.3", "0784d4c2dbb93a0d3009820b7858976424c56578ce23dcd89d06a1d0bf5fd8e2")
add_versions("1.9.4", "2fbb27716c010d8a28e52d5bc8f108e0d073ca3b3f5a48a2696b0231ea5196d5")
add_versions("1.10.5", "c8590568996cea918d7cf7ec6845d954b9b95ab2c4980b365f582a665dea08d8")
add_versions("1.10.2", "044e98079032f7abf69c4c82f90ee2b4e4a7d2f28245498a5201ad6e8d0b1d08")
add_versions("1.10.3", "d7f2574bd9dae8adb0ce6cf1afab119b509c297fffcb4204a1bb3e4e731074f2")
add_versions("1.10.5", "c8590568996cea918d7cf7ec6845d954b9b95ab2c4980b365f582a665dea08d8")
add_versions("1.9.4", "2fbb27716c010d8a28e52d5bc8f108e0d073ca3b3f5a48a2696b0231ea5196d5")
add_versions("1.8.3", "0784d4c2dbb93a0d3009820b7858976424c56578ce23dcd89d06a1d0bf5fd8e2")
add_versions("1.7.2", "aa38a414fe2ffc49af13a08b6ab34df825fdd2e7a1213d032d835a779e14176f")
add_versions("1.6.2", "c45f9c55797380c6ba44060f0c73713fbd7989eeb1147aedb8723aa14f3afaa3")

add_configs("ssl", {description = "Enable SSL.", default = false, type = "boolean"})

Expand All @@ -23,6 +23,17 @@ package("cpr")
end
add_links("cpr")

if on_check then
on_check(function (package)
-- Require to fIX cmake try run
if package:version() and package:version():eq("1.6.2") then
if package:is_cross() then
raise("package(cpr 1.6.2) unsupported cross-compilation")
end
end
end)
end

on_load(function (package)
if package:config("ssl") then
package:add("deps", "libcurl", {configs = {libssh2 = true, zlib = true}})
Expand All @@ -33,25 +44,33 @@ package("cpr")
end)

on_install("linux", "macosx", "windows", "mingw@windows", function (package)
local configs = {"-DCPR_BUILD_TESTS=OFF",
"-DCPR_FORCE_USE_SYSTEM_CURL=ON",
"-DCPR_USE_SYSTEM_CURL=ON"}
io.replace("CMakeLists.txt", "-Werror", "", {plain = true})
if package:is_plat("windows") then
-- fix find_package issue on windows
io.replace("CMakeLists.txt", "find_package%(CURL COMPONENTS .-%)", "find_package(CURL)")
end

local configs = {
"-DCPR_BUILD_TESTS=OFF",
"-DCPR_FORCE_USE_SYSTEM_CURL=ON",
"-DCPR_USE_SYSTEM_CURL=ON",
}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DCPR_ENABLE_SSL=" .. (package:config("ssl") and "ON" or "OFF"))
local shflags
if package:config("shared") and package:is_plat("macosx") then
shflags = {"-framework", "CoreFoundation", "-framework", "Security", "-framework", "SystemConfiguration"}
end
local packagedeps = {"libcurl"}

local opt = {}
opt.packagedeps = {"libcurl"}
if package:config("ssl") then
table.insert(packagedeps, "libssh2")
table.insert(opt.packagedeps, "libssh2")
end
if package:is_plat("windows") then
-- fix find_package issue on windows
io.replace("CMakeLists.txt", "find_package%(CURL COMPONENTS .-%)", "find_package(CURL)")
if package:is_plat("windows") and package:has_tool("cxx", "cl", "clang_cl") then
opt.cxflags = {"/EHsc"}
end
import("package.tools.cmake").install(package, configs, {shflags = shflags, packagedeps = packagedeps})
if package:config("shared") and package:is_plat("macosx") then
opt.shflags = {"-framework", "CoreFoundation", "-framework", "Security", "-framework", "SystemConfiguration"}
end
import("package.tools.cmake").install(package, configs, opt)
end)

on_test(function (package)
Expand All @@ -64,5 +83,3 @@ package("cpr")
}
]]}, {configs = {languages = "c++17"}}))
end)


0 comments on commit 02ece0c

Please sign in to comment.