diff options
| author | ruki <[email protected]> | 2021-03-23 00:25:16 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-03-23 00:25:16 +0800 |
| commit | dd5f678184a8d8577d899acd37f08764549636f9 (patch) | |
| tree | 4cf377d3f6ec92043398059e9401d72ee20bc8e1 | |
| parent | 58eb3f1d3a353d92e358d5faf50c73b17681f4af (diff) | |
add install pkgconfig files rule
| -rw-r--r-- | xmake/core/project/target.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/target/action/install/pkgconfig.lua | 83 | ||||
| -rw-r--r-- | xmake/rules/utils/install_files/xmake.lua | 26 |
3 files changed, 114 insertions, 0 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 1c3503667..6aa11d56d 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -660,6 +660,11 @@ function _instance:is_static() return self:kind() == "static" end +-- is library target? +function _instance:is_library() + return self:is_static() or self:is_shared() +end + -- is default target? function _instance:is_default() local default = self:get("default") diff --git a/xmake/modules/target/action/install/pkgconfig.lua b/xmake/modules/target/action/install/pkgconfig.lua new file mode 100644 index 000000000..46dfb9389 --- /dev/null +++ b/xmake/modules/target/action/install/pkgconfig.lua @@ -0,0 +1,83 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed 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-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file pkgconfig.lua +-- + +-- install pkgconfig/.pc files +function main(target, opt) + + -- check + opt = opt or {} + assert(target:is_library(), 'rule("utils.install.pkgconfig_files"): only support for library target!') + + -- only for unix platform + local installdir = target:installdir() + if target:is_plat("windows") or not installdir then + return + end + + -- get pkgconfig/.pc file + local pcfile = path.join(installdir, opt and opt.libdir or "lib", "pkgconfig", opt.filename or (target:basename() .. ".pc")) + + -- get includedirs + local includedirs = opt.includedirs or {path.join(installdir, "include")} + + -- get links and linkdirs + local links = opt.links or target:basename() + local linkdirs = opt.linkdirs or {path.join(installdir, "lib")} + + -- get libs + local libs = "" + for _, linkdir in ipairs(linkdirs) do + libs = libs .. "-L" .. linkdir + end + libs = libs .. " -L${libdir}" + for _, link in ipairs(links) do + libs = libs .. " -l" .. link + end + + -- get cflags + local cflags = "" + for _, includedir in ipairs(includedirs) do + cflags = cflags .. "-I" .. includedir + end + cflags = cflags .. " -I${includedir}" + + -- trace + vprint("generating %s ..", pcfile) + + -- generate a *.pc file + local file = io.open(pcfile, 'w') + if file then + file:print("prefix=%s", installdir) + file:print("exec_prefix=${prefix}") + file:print("libdir=${exec_prefix}/lib") + file:print("includedir=${prefix}/include") + file:print("") + file:print("Name: %s", target:name()) + local version = target:get("version") + if version then + file:print("Version: %s", version) + end + file:print("Libs: %s", libs) + file:print("Libs.private: ") + file:print("Cflags: %s", cflags) + file:close() + end +end + diff --git a/xmake/rules/utils/install_files/xmake.lua b/xmake/rules/utils/install_files/xmake.lua new file mode 100644 index 000000000..58d8adf1b --- /dev/null +++ b/xmake/rules/utils/install_files/xmake.lua @@ -0,0 +1,26 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed 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-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- install pkg-config/*.pc files +rule("utils.install.pkgconfig_files") + after_install(function (target, opt) + import("target.action.install.pkgconfig")(target, opt) + end) + |
