diff options
| author | FireFight <[email protected]> | 2026-02-06 22:05:53 +0800 |
|---|---|---|
| committer | FireFight <[email protected]> | 2026-02-06 22:05:53 +0800 |
| commit | 7a6078cf4f4f28f607406f743c8482c4121d619c (patch) | |
| tree | de5410872bf9e0b6f9886a1fb85e46caa68bdfb1 | |
| parent | 41d6a48953038df041194bafc7cc87a7e6466b3e (diff) | |
fix attempt to add dependency handling for vcpkg
| -rw-r--r-- | xmake/modules/package/manager/vcpkg/find_package.lua | 149 |
1 files changed, 87 insertions, 62 deletions
diff --git a/xmake/modules/package/manager/vcpkg/find_package.lua b/xmake/modules/package/manager/vcpkg/find_package.lua index f44f7b3f9..359e7dfa2 100644 --- a/xmake/modules/package/manager/vcpkg/find_package.lua +++ b/xmake/modules/package/manager/vcpkg/find_package.lua @@ -63,7 +63,7 @@ function _find_package_from_pkgconfig(pkgconfig_files, opt) end end -function _find_package(vcpkgdir, name, opt) +function _find_package(vcpkg, vcpkgdir, name, opt) -- get configs local configs = opt.configs or {} @@ -80,6 +80,20 @@ function _find_package(vcpkgdir, name, opt) arch = configurations.arch(arch) local triplet = configurations.triplet(configs, plat, arch) + -- find dependency package + local dependencypackage = {} + local _, dependinfo = os.iorunv(vcpkg, {"depend-info", name}) + 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 + table.insert(dependencypackage, packagename) + end + end + end + end + -- get the vcpkg info directories local infodirs = {} if opt.installdir then @@ -87,80 +101,85 @@ function _find_package(vcpkgdir, name, opt) 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 - local installdir = path.directory(path.directory(path.directory(infofile))) - - -- save includedirs, linkdirs and links local result = nil - local pkgconfig_files = {} - local info = io.readfile(infofile) - if info then - for _, line in ipairs(info:split('\n')) do - line = line:trim() - if plat == "windows" then - line = line:lower() - end + for _, dependencyname in ipairs(dependencypackage) do + -- find the package info file, e.g. zlib_1.2.11-3_x86-windows[-static].list + local infofile = find_file(format("%s_*_%s.list", dependencyname, triplet), infodirs) + if not infofile then + goto continue + -- return + end + local installdir = path.directory(path.directory(path.directory(infofile))) - -- get pkgconfig files - if line:find(triplet .. (mode == "debug" and "/debug" or "") .. "/lib/pkgconfig/", 1, true) and line:endswith(".pc") then - table.insert(pkgconfig_files, line) - end + -- save includedirs, linkdirs and links + local pkgconfig_files = {} + local info = io.readfile(infofile) + if info then + for _, line in ipairs(info:split('\n')) do + line = line:trim() + if plat == "windows" then + line = line:lower() + end - -- get includedirs - if line:endswith("/include/") then - result = result or {} - result.includedirs = result.includedirs or {} - table.insert(result.includedirs, path.join(installdir, line)) - end + -- get pkgconfig files + if line:find(triplet .. (mode == "debug" and "/debug" or "") .. "/lib/pkgconfig/", 1, true) and line:endswith(".pc") then + table.insert(pkgconfig_files, line) + end - -- get linkdirs and links - if (plat == "windows" and line:endswith(".lib")) or line:endswith(".a") or line:endswith(".so") then - if line:find(triplet .. (mode == "debug" and "/debug" or "") .. "/lib/", 1, true) then + -- get includedirs + if line:endswith("/include/") then result = result or {} - result.links = result.links or {} - result.linkdirs = result.linkdirs or {} - result.libfiles = result.libfiles or {} - table.insert(result.linkdirs, path.join(installdir, path.directory(line))) - table.insert(result.links, target.linkname(path.filename(line), {plat = plat})) - table.insert(result.libfiles, path.join(installdir, path.directory(line), path.filename(line))) + result.includedirs = result.includedirs or {} + table.insert(result.includedirs, path.join(installdir, line)) end - end - -- add shared library directory (/bin/) to linkdirs for running with PATH on windows - if plat == "windows" and line:endswith(".dll") then - if line:find(plat .. (mode == "debug" and "/debug" or "") .. "/bin/", 1, true) then - result = result or {} - result.linkdirs = result.linkdirs or {} - result.libfiles = result.libfiles or {} - table.insert(result.linkdirs, path.join(installdir, path.directory(line))) - table.insert(result.libfiles, path.join(installdir, path.directory(line), path.filename(line))) + -- get linkdirs and links + if (plat == "windows" and line:endswith(".lib")) or line:endswith(".a") or line:endswith(".so") then + if line:find(triplet .. (mode == "debug" and "/debug" or "") .. "/lib/", 1, true) then + result = result or {} + result.links = result.links or {} + result.linkdirs = result.linkdirs or {} + result.libfiles = result.libfiles or {} + table.insert(result.linkdirs, path.join(installdir, path.directory(line))) + table.insert(result.links, target.linkname(path.filename(line), {plat = plat})) + table.insert(result.libfiles, path.join(installdir, path.directory(line), path.filename(line))) + end + end + + -- add shared library directory (/bin/) to linkdirs for running with PATH on windows + if plat == "windows" and line:endswith(".dll") then + if line:find(plat .. (mode == "debug" and "/debug" or "") .. "/bin/", 1, true) then + result = result or {} + result.linkdirs = result.linkdirs or {} + result.libfiles = result.libfiles or {} + table.insert(result.linkdirs, path.join(installdir, path.directory(line))) + table.insert(result.libfiles, path.join(installdir, path.directory(line), path.filename(line))) + end end end end - end - -- find result from pkgconfig first - if #pkgconfig_files > 0 then - local pkgconfig_result = _find_package_from_pkgconfig(pkgconfig_files, {installdir = installdir, linkdirs = result and result.linkdirs}) - if pkgconfig_result then - result = pkgconfig_result + -- find result from pkgconfig first + if #pkgconfig_files > 0 then + local pkgconfig_result = _find_package_from_pkgconfig(pkgconfig_files, {installdir = installdir, linkdirs = result and result.linkdirs}) + if pkgconfig_result then + result = pkgconfig_result + end end - end - -- save version - if result then - local infoname = path.basename(infofile) - local prefix = name - -- name maybe contains lua pattern characters, we need escape it. e.g. `-` - prefix = prefix:gsub("([%+%.%-%^%$%(%)%%])", "%%%1") - result.version = infoname:match(prefix .. "_(%d+%.?%d*%.?%d*.-)_" .. arch) - if not result.version then - result.version = infoname:match(prefix .. "_(%d+%.?%d*%.-)_" .. arch) + -- save version + if result then + local infoname = path.basename(infofile) + local prefix = dependencyname + -- dependencyname maybe contains lua pattern characters, we need escape it. e.g. `-` + prefix = prefix:gsub("([%+%.%-%^%$%(%)%%])", "%%%1") + result.version = infoname:match(prefix .. "_(%d+%.?%d*%.?%d*.-)_" .. arch) + if not result.version then + result.version = infoname:match(prefix .. "_(%d+%.?%d*%.-)_" .. arch) + end end + + ::continue:: end -- remove repeat @@ -192,6 +211,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 |
