summaryrefslogtreecommitdiff
path: root/xmake/modules/package/manager/brew/find_package.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2019-01-23 21:05:20 +0800
committerruki <[email protected]>2019-01-23 00:32:05 +0800
commit7d9fe778c235da802039bf46c62cd4142f4719e4 (patch)
tree4b2239aa013f24d8fc7fbd403c3e80245604363a /xmake/modules/package/manager/brew/find_package.lua
parentde29dc88bc3b7d39d4206d6e2bd034d15b232ca2 (diff)
rewrite find_package for brew, pkgconfig and system
Diffstat (limited to 'xmake/modules/package/manager/brew/find_package.lua')
-rw-r--r--xmake/modules/package/manager/brew/find_package.lua58
1 files changed, 58 insertions, 0 deletions
diff --git a/xmake/modules/package/manager/brew/find_package.lua b/xmake/modules/package/manager/brew/find_package.lua
new file mode 100644
index 000000000..988c162fa
--- /dev/null
+++ b/xmake/modules/package/manager/brew/find_package.lua
@@ -0,0 +1,58 @@
+--!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 - 2019, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file find_package.lua
+--
+
+-- imports
+import("lib.detect.find_tool")
+import("lib.detect.find_file")
+import("lib.detect.pkg_config")
+
+-- find package from the brew package manager
+--
+-- @param name the package name, e.g. zlib, pcre/libpcre16
+-- @param opt the options, .e.g {verbose = true, version = "1.12.x")
+--
+function main(name, opt)
+
+ -- find brew
+ local brew = find_tool("brew")
+ if not brew then
+ return
+ end
+
+ -- parse name, .e.g pcre/libpcre16
+ local nameinfo = name:split('/')
+ local pcname = nameinfo[2] or nameinfo[1]
+
+ -- find the prefix directory of brew
+ local brew_pkg_root = try { function () return os.iorunv(brew.program, {"--prefix"}) end } or "/usr/local"
+ brew_pkg_root = path.join(brew_pkg_root:trim(), opt.plat == "macosx" and "Cellar" or "opt")
+ local pcfile = find_file(pcname .. ".pc", path.join(brew_pkg_root, nameinfo[1], "*/lib/pkgconfig"))
+ if not pcfile then
+ return
+ end
+
+ -- do find
+ opt.configdirs = path.directory(pcfile)
+ return pkg_config.find(pcname, opt)
+end