summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-02-10 14:25:22 +0800
committerGitHub <[email protected]>2026-02-10 14:25:22 +0800
commitee98b61be7054e1b8b8e2668b67c662ba12e264b (patch)
tree5c6ec007c96c904d514b97a652923a1c7ef8977a
parentd481d13b1c8c8536de5919104b99e43e0b1bb263 (diff)
parent85b9b630211b2689df96716d1fe677aeb5d9fd6a (diff)
Merge pull request #7299 from 138436724/vcpkgdepend
fix: ‌attempt to add dependency handling for vcpkg
-rw-r--r--tests/projects/package/vcpkg/.gitignore2
-rw-r--r--tests/projects/package/vcpkg/src/main.cpp3
-rw-r--r--tests/projects/package/vcpkg/xmake.lua2
-rw-r--r--tests/projects/package/vcpkg_dependency/.gitignore6
-rw-r--r--tests/projects/package/vcpkg_dependency/src/main.cpp20
-rw-r--r--tests/projects/package/vcpkg_dependency/xmake.lua11
-rw-r--r--tests/projects/package/vcpkg_manifest/.gitignore2
-rw-r--r--tests/projects/package/vcpkg_manifest/src/main.cpp3
-rw-r--r--tests/projects/package/vcpkg_manifest/xmake.lua2
-rw-r--r--xmake/modules/package/manager/vcpkg/find_package.lua98
10 files changed, 111 insertions, 38 deletions
diff --git a/tests/projects/package/vcpkg/.gitignore b/tests/projects/package/vcpkg/.gitignore
index 152105761..d66efff82 100644
--- a/tests/projects/package/vcpkg/.gitignore
+++ b/tests/projects/package/vcpkg/.gitignore
@@ -4,5 +4,3 @@ build/
# MacOS Cache
.DS_Store
-
-
diff --git a/tests/projects/package/vcpkg/src/main.cpp b/tests/projects/package/vcpkg/src/main.cpp
index 7c435d251..e64ad9bc2 100644
--- a/tests/projects/package/vcpkg/src/main.cpp
+++ b/tests/projects/package/vcpkg/src/main.cpp
@@ -2,8 +2,7 @@
using namespace std;
-int main(int argc, char** argv)
-{
+int main(int argc, char** argv) {
cout << "hello world!" << endl;
return 0;
}
diff --git a/tests/projects/package/vcpkg/xmake.lua b/tests/projects/package/vcpkg/xmake.lua
index 3f5dbcf55..3abedd205 100644
--- a/tests/projects/package/vcpkg/xmake.lua
+++ b/tests/projects/package/vcpkg/xmake.lua
@@ -1,3 +1,5 @@
+add_rules("mode.debug", "mode.release")
+
add_requires("vcpkg::zlib", "vcpkg::pcre2")
add_requires("vcpkg::boost[core]", {alias = "boost"})
diff --git a/tests/projects/package/vcpkg_dependency/.gitignore b/tests/projects/package/vcpkg_dependency/.gitignore
new file mode 100644
index 000000000..d66efff82
--- /dev/null
+++ b/tests/projects/package/vcpkg_dependency/.gitignore
@@ -0,0 +1,6 @@
+# Xmake cache
+.xmake/
+build/
+
+# MacOS Cache
+.DS_Store
diff --git a/tests/projects/package/vcpkg_dependency/src/main.cpp b/tests/projects/package/vcpkg_dependency/src/main.cpp
new file mode 100644
index 000000000..4955734dc
--- /dev/null
+++ b/tests/projects/package/vcpkg_dependency/src/main.cpp
@@ -0,0 +1,20 @@
+#include <OpenColorIO/OpenColorIO.h>
+#include <OpenImageIO/imageio.h>
+#include <boost/system/error_code.hpp>
+#include <boost/filesystem.hpp>
+
+int main(int argc, char **argv) {
+ // test for opencolorio, opencolorio is one of the dependencies of openimageio.
+ auto transform = OCIO_NAMESPACE::ColorSpaceTransform::Create();
+
+ // test for openimageio.
+ auto write_image = OIIO::ImageInput::open("test.png");
+
+ // test for boost-system, boost-system is one of the dependencies of boost-filesystem.
+ boost::system::error_code ec;
+
+ // test for boost-filesystem.
+ boost::filesystem::exists("test.png", ec);
+
+ return 0;
+}
diff --git a/tests/projects/package/vcpkg_dependency/xmake.lua b/tests/projects/package/vcpkg_dependency/xmake.lua
new file mode 100644
index 000000000..d309a3fc3
--- /dev/null
+++ b/tests/projects/package/vcpkg_dependency/xmake.lua
@@ -0,0 +1,11 @@
+add_rules("mode.debug", "mode.release")
+
+add_requires("vcpkg::openimageio[jpegxl,libraw,webp]", { configs = { shared = true } })
+add_requires("vcpkg::boost-filesystem", { alias = "filesystem" })
+
+target("test")
+ set_kind("binary")
+ add_files("src/*.cpp")
+ set_languages("c++17")
+ set_encodings("utf-8")
+ add_packages("vcpkg::openimageio[jpegxl,libraw,webp]", "filesystem")
diff --git a/tests/projects/package/vcpkg_manifest/.gitignore b/tests/projects/package/vcpkg_manifest/.gitignore
index 152105761..d66efff82 100644
--- a/tests/projects/package/vcpkg_manifest/.gitignore
+++ b/tests/projects/package/vcpkg_manifest/.gitignore
@@ -4,5 +4,3 @@ build/
# MacOS Cache
.DS_Store
-
-
diff --git a/tests/projects/package/vcpkg_manifest/src/main.cpp b/tests/projects/package/vcpkg_manifest/src/main.cpp
index 7c435d251..e64ad9bc2 100644
--- a/tests/projects/package/vcpkg_manifest/src/main.cpp
+++ b/tests/projects/package/vcpkg_manifest/src/main.cpp
@@ -2,8 +2,7 @@
using namespace std;
-int main(int argc, char** argv)
-{
+int main(int argc, char** argv) {
cout << "hello world!" << endl;
return 0;
}
diff --git a/tests/projects/package/vcpkg_manifest/xmake.lua b/tests/projects/package/vcpkg_manifest/xmake.lua
index 8a851328b..0814b817e 100644
--- a/tests/projects/package/vcpkg_manifest/xmake.lua
+++ b/tests/projects/package/vcpkg_manifest/xmake.lua
@@ -1,3 +1,5 @@
+add_rules("mode.debug", "mode.release")
+
add_requires("vcpkg::zlib 1.2.11+10")
add_requires("vcpkg::fmt >=8.0.1", {configs = {baseline = "50fd3d9957195575849a49fa591e645f1d8e7156"}})
add_requires("vcpkg::libpng", {configs = {features = {"apng"}}})
diff --git a/xmake/modules/package/manager/vcpkg/find_package.lua b/xmake/modules/package/manager/vcpkg/find_package.lua
index f44f7b3f9..045adf050 100644
--- a/xmake/modules/package/manager/vcpkg/find_package.lua
+++ b/xmake/modules/package/manager/vcpkg/find_package.lua
@@ -63,30 +63,7 @@ function _find_package_from_pkgconfig(pkgconfig_files, opt)
end
end
-function _find_package(vcpkgdir, name, opt)
-
- -- get configs
- local configs = opt.configs or {}
-
- -- fix name, e.g. ffmpeg[x264] as ffmpeg
- -- @see https://github.com/xmake-io/xmake/issues/925
- name = name:gsub("%[.-%]", "")
-
- -- init triplet
- local arch = opt.arch
- local plat = opt.plat
- local mode = opt.mode
- plat = configurations.plat(plat)
- arch = configurations.arch(arch)
- local triplet = configurations.triplet(configs, plat, arch)
-
- -- get the vcpkg info directories
- local infodirs = {}
- if opt.installdir then
- table.join2(infodirs, path.join(opt.installdir, "vcpkg_installed", "vcpkg", "info"))
- end
- table.join2(infodirs, path.join(vcpkgdir, "installed", "vcpkg", "info"))
-
+function _get_package_info(name, triplet, infodirs, arch, plat, mode)
-- find the package info file, e.g. zlib_1.2.11-3_x86-windows[-static].list
local infofile = find_file(format("%s_*_%s.list", name, triplet), infodirs)
if not infofile then
@@ -151,6 +128,60 @@ function _find_package(vcpkgdir, name, opt)
end
end
+ return result
+end
+
+function _find_package(vcpkg, vcpkgdir, name, opt)
+
+ -- get configs
+ local configs = opt.configs or {}
+
+ -- fix name, e.g. ffmpeg[x264] as ffmpeg
+ -- @see https://github.com/xmake-io/xmake/issues/925
+ name = name:gsub("%[.-%]", "")
+
+ -- init triplet
+ local arch = opt.arch
+ local plat = opt.plat
+ local mode = opt.mode
+ plat = configurations.plat(plat)
+ arch = configurations.arch(arch)
+ local triplet = configurations.triplet(configs, plat, arch)
+
+ -- get the vcpkg info directories
+ local infodirs = {}
+ if opt.installdir then
+ table.join2(infodirs, path.join(opt.installdir, "vcpkg_installed", "vcpkg", "info"))
+ end
+ table.join2(infodirs, path.join(vcpkgdir, "installed", "vcpkg", "info"))
+
+ -- find the package info file, e.g. zlib_1.2.11-3_x86-windows[-static].list
+ local infofile = find_file(format("%s_*_%s.list", name, triplet), infodirs)
+ if not infofile then
+ return
+ end
+
+ -- find dependency package
+ local result = nil
+ local _, dependinfo = try { function () return os.iorunv(vcpkg, {"depend-info", name, "--sort=reverse", "--triplet=" .. triplet}) end }
+ if dependinfo then
+ for _, line in ipairs(dependinfo:split("\n", {plain = true})) do
+ if not line:startswith("vcpkg-") then
+ local packagename = line:match("^([^%[:]+)[^:]*:")
+ if packagename then
+ local dependencyresult = _get_package_info(packagename, triplet, infodirs, arch, plat, mode)
+ if dependencyresult then
+ result = result or {}
+ for key, dependencylist in pairs(dependencyresult) do
+ result[key] = result[key] or {}
+ table.join2(result[key], dependencylist)
+ end
+ end
+ end
+ end
+ end
+ end
+
-- save version
if result then
local infoname = path.basename(infofile)
@@ -165,11 +196,12 @@ function _find_package(vcpkgdir, name, opt)
-- remove repeat
if result then
- if result.linkdirs then
- result.linkdirs = table.unique(result.linkdirs)
- end
- if result.includedirs then
- result.includedirs = table.unique(result.includedirs)
+ for k, v in pairs(result) do
+ if k == "links" or k == "syslinks" or k == "frameworks" then
+ result[k] = table.unwrap(table.reverse_unique(v))
+ else
+ result[k] = table.unwrap(table.unique(v))
+ end
end
end
return result
@@ -192,6 +224,12 @@ function main(name, opt)
return
end
+ -- attempt to find vcpkg
+ local vcpkg = find_tool("vcpkg")
+ if not vcpkg then
+ raise("vcpkg not found!")
+ end
+
-- do find package
- return _find_package(vcpkgdir, name, opt)
+ return _find_package(vcpkg.program, vcpkgdir, name, opt)
end