diff options
| author | ruki <[email protected]> | 2018-08-18 00:50:29 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-08-17 23:02:58 +0800 |
| commit | 7df03dd8e81837f77a7bfb0b4b33ded1770e55b5 (patch) | |
| tree | 9f54a3ff89fab9ceed05b2f3cbfa4515c383b06e | |
| parent | c49755cdff88b6e2f79cd6b03eb581509fb8499e (diff) | |
add detect.sdks.find_vcpkgdir
| -rw-r--r-- | xmake/modules/detect/sdks/find_vcpkgdir.lua | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/xmake/modules/detect/sdks/find_vcpkgdir.lua b/xmake/modules/detect/sdks/find_vcpkgdir.lua new file mode 100644 index 000000000..faa312b15 --- /dev/null +++ b/xmake/modules/detect/sdks/find_vcpkgdir.lua @@ -0,0 +1,110 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_vcpkgdir.lua +-- + +-- imports +import("lib.detect.cache") +import("lib.detect.find_file") +import("core.base.option") +import("core.base.global") +import("core.project.config") + +-- find vcpkg directory +function _find_vcpkgdir(sdkdir) + + -- init the search directories + local pathes = {} + if sdkdir then + table.insert(pathes, sdkdir) + end + if is_host("windows") then + -- attempt to read path info after running `vcpkg integrate install` + local pathfile = "~/../Local/vcpkg/vcpkg.path.txt" + if os.isfile(pathfile) then + local dir = io.readfile(pathfile):trim() + if os.isdir(dir) then + table.insert(pathes, dir) + end + end + else + -- TODO + end + + -- attempt to find vcpkg + local vcpkg = find_file(is_host("windows") and "vcpkg.exe" or "vcpkg", pathes) + if vcpkg then + return path.directory(vcpkg) + end +end + +-- find vcpkg directory +-- +-- @param sdkdir the vcpkg directory +-- @param opt the argument options, .e.g {verbose = true, force = false} +-- +-- @return the vcpkg directory +-- +-- @code +-- +-- local vcpkgdir = find_vcpkgdir() +-- +-- @endcode +-- +function main(sdkdir, opt) + + -- init arguments + opt = opt or {} + + -- attempt to load cache first + local key = "detect.sdks.find_vcpkgdir." .. (sdkdir or "") + local cacheinfo = cache.load(key) + if not opt.force and cacheinfo.vcpkg then + return cacheinfo.vcpkg + end + + -- find vcpkg + local vcpkg = _find_vcpkgdir(sdkdir or config.get("vcpkg") or global.get("vcpkg")) + if vcpkg then + + -- save to config + config.set("vcpkg", vcpkg.sdkdir, {force = true, readonly = true}) + + -- trace + if opt.verbose or option.get("verbose") then + cprint("checking for the vcpkg directory ... ${green}%s", vcpkg.sdkdir) + end + else + + -- trace + if opt.verbose or option.get("verbose") then + cprint("checking for the vcpkg directory ... ${red}no") + end + end + + -- save to cache + cacheinfo.vcpkg = vcpkg or false + cache.save(key, cacheinfo) + + -- ok? + return vcpkg +end |
