summaryrefslogtreecommitdiff
path: root/xmake/modules/package/manager
diff options
context:
space:
mode:
authorruki <[email protected]>2020-11-17 00:53:23 +0800
committerruki <[email protected]>2020-11-17 00:53:23 +0800
commitb0bb7321d5474c04becc4a1dab0502ad29203e73 (patch)
tree751a10fc577378e2e7c31d1fe18fca14dac1e44c /xmake/modules/package/manager
parent5126a44b24e0f3266e0f588308469225ff3d603d (diff)
improve vcpkg
Diffstat (limited to 'xmake/modules/package/manager')
-rw-r--r--xmake/modules/package/manager/vcpkg/find_package.lua41
-rw-r--r--xmake/modules/package/manager/vcpkg/install_package.lua10
2 files changed, 42 insertions, 9 deletions
diff --git a/xmake/modules/package/manager/vcpkg/find_package.lua b/xmake/modules/package/manager/vcpkg/find_package.lua
index fecf9e3c3..ff9ac3485 100644
--- a/xmake/modules/package/manager/vcpkg/find_package.lua
+++ b/xmake/modules/package/manager/vcpkg/find_package.lua
@@ -21,19 +21,52 @@
-- imports
import("lib.detect.find_file")
import("lib.detect.find_library")
-import("detect.sdks.find_vcpkgdir")
+import("lib.detect.find_tool")
import("core.project.config")
import("core.project.target")
--- find package from the brew package manager
+-- find vcpkg root directory
+function _find_vcpkgdir()
+ local vcpkgdir = _g.vcpkgdir
+ if vcpkgdir == nil then
+ local vcpkg = find_tool("vcpkg")
+ if vcpkg then
+ local dir = path.directory(vcpkg.program)
+ if os.isdir(path.join(dir, "installed")) then
+ vcpkgdir = dir
+ elseif is_host("macosx", "linux") then
+ local brew = find_tool("brew")
+ if brew then
+ dir = try
+ {
+ function ()
+ return os.iorunv(brew.program, {"--prefix", "vcpkg"})
+ end
+ }
+ end
+ if dir then
+ dir = path.join(dir:trim(), "libexec")
+ if os.isdir(path.join(dir, "installed")) then
+ vcpkgdir = dir
+ end
+ end
+
+ end
+ end
+ _g.vcpkgdir = vcpkgdir or false
+ end
+ return vcpkgdir or nil
+end
+
+-- find package from the vcpkg package manager
--
-- @param name the package name, e.g. zlib, pcre
-- @param opt the options, e.g. {verbose = true, version = "1.12.x")
--
function main(name, opt)
- -- attempt to find the vcpkg root directory
- local vcpkgdir = find_vcpkgdir(opt.vcpkgdir)
+ -- attempt to find vcpkg directory
+ local vcpkgdir = _find_vcpkgdir()
if not vcpkgdir then
return
end
diff --git a/xmake/modules/package/manager/vcpkg/install_package.lua b/xmake/modules/package/manager/vcpkg/install_package.lua
index d04602a25..35c77b4b9 100644
--- a/xmake/modules/package/manager/vcpkg/install_package.lua
+++ b/xmake/modules/package/manager/vcpkg/install_package.lua
@@ -20,7 +20,7 @@
-- imports
import("core.base.option")
-import("detect.sdks.find_vcpkgdir")
+import("lib.detect.find_tool")
-- install package
--
@@ -31,9 +31,9 @@ import("detect.sdks.find_vcpkgdir")
--
function main(name, opt)
- -- attempt to find the vcpkg root directory
- local vcpkgdir = find_vcpkgdir(opt.vcpkgdir)
- if not vcpkgdir then
+ -- attempt to find vcpkg
+ local vcpkg = find_tool("vcpkg")
+ if not vcpkg then
raise("vcpkg not found!")
end
@@ -64,5 +64,5 @@ function main(name, opt)
end
-- install package
- os.vrunv(path.join(vcpkgdir, "vcpkg"), argv)
+ os.vrunv(vcpkg.program, argv)
end