mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Cleanup of premake pkgconfig module
Split public and private stuff into their own sections and do parsing of libs in a helper function analog to the parse helper function for includes and document public funcions using LDoc. Finally make setting the static flag a function. Ref: #8135 Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
@@ -65,7 +65,7 @@ pkgconfig = require "pkgconfig"
|
|||||||
-- Configure pkgconfig for MacOSX systems
|
-- Configure pkgconfig for MacOSX systems
|
||||||
if os.istarget("macosx") then
|
if os.istarget("macosx") then
|
||||||
pkgconfig.add_pkg_config_path(libraries_dir .. "pkgconfig/")
|
pkgconfig.add_pkg_config_path(libraries_dir .. "pkgconfig/")
|
||||||
pkgconfig.static_link_libs = true
|
pkgconfig.set_static_link_libs(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function add_delayload(name, suffix, def)
|
local function add_delayload(name, suffix, def)
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
local m = {}
|
|
||||||
m._VERSION = "1.4.0-dev"
|
|
||||||
|
|
||||||
m.static_link_libs = false
|
|
||||||
|
|
||||||
local pkg_config_command = "pkg-config"
|
local pkg_config_command = "pkg-config"
|
||||||
if os.getenv("PKG_CONFIG") then
|
if os.getenv("PKG_CONFIG") then
|
||||||
pkg_config_command = os.getenv("PKG_CONFIG")
|
pkg_config_command = os.getenv("PKG_CONFIG")
|
||||||
@@ -13,6 +8,8 @@ if os.getenv("PKG_CONFIG_PATH") then
|
|||||||
pkg_config_path = os.getenv("PKG_CONFIG_PATH")
|
pkg_config_path = os.getenv("PKG_CONFIG_PATH")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local static_link_libs = false
|
||||||
|
|
||||||
|
|
||||||
local function os_capture(cmd)
|
local function os_capture(cmd)
|
||||||
return io.popen(cmd, 'r'):read('*a'):gsub("\n", " ")
|
return io.popen(cmd, 'r'):read('*a'):gsub("\n", " ")
|
||||||
@@ -53,34 +50,10 @@ local function parse_pkg_config_includes(lib, alternative_cmd, alternative_flags
|
|||||||
return dirs, files, options
|
return dirs, files, options
|
||||||
end
|
end
|
||||||
|
|
||||||
function m.add_pkg_config_path(path)
|
local function parse_pkg_config_links(lib, alternative_cmd, alternative_flags)
|
||||||
if pkg_config_path == "" then
|
|
||||||
pkg_config_path = path
|
|
||||||
else
|
|
||||||
pkg_config_path = pkg_config_path .. ":" .. path
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function m.add_includes(lib, alternative_cmd, alternative_flags)
|
|
||||||
local dirs, files, options = parse_pkg_config_includes(lib, alternative_cmd, alternative_flags)
|
|
||||||
|
|
||||||
externalincludedirs(dirs)
|
|
||||||
forceincludes(files)
|
|
||||||
buildoptions(options)
|
|
||||||
end
|
|
||||||
|
|
||||||
function m.add_includes_after(lib, alternative_cmd, alternative_flags)
|
|
||||||
local dirs, files, options = parse_pkg_config_includes(lib, alternative_cmd, alternative_flags)
|
|
||||||
|
|
||||||
includedirsafter(dirs)
|
|
||||||
forceincludes(files)
|
|
||||||
buildoptions(options)
|
|
||||||
end
|
|
||||||
|
|
||||||
function m.add_links(lib, alternative_cmd, alternative_flags)
|
|
||||||
local result
|
local result
|
||||||
if not alternative_cmd then
|
if not alternative_cmd then
|
||||||
local static = m.static_link_libs and " --static " or ""
|
local static = static_link_libs and " --static " or ""
|
||||||
result = os_capture("PKG_CONFIG_PATH=" .. pkg_config_path .. " " .. pkg_config_command .. " --libs " .. static .. lib)
|
result = os_capture("PKG_CONFIG_PATH=" .. pkg_config_path .. " " .. pkg_config_command .. " --libs " .. static .. lib)
|
||||||
else
|
else
|
||||||
if not alternative_flags then
|
if not alternative_flags then
|
||||||
@@ -108,8 +81,64 @@ function m.add_links(lib, alternative_cmd, alternative_flags)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
links(libs)
|
return dirs, libs, options
|
||||||
|
end
|
||||||
|
|
||||||
|
-- ----------------------------------------------------------------------------
|
||||||
|
-- Public API
|
||||||
|
-- ----------------------------------------------------------------------------
|
||||||
|
local m = {}
|
||||||
|
m._VERSION = "2.0.0"
|
||||||
|
|
||||||
|
--- Append path to PKG_CONFIG_PATH
|
||||||
|
-- @param path string Path to append to PKG_CONFIG_PATH
|
||||||
|
function m.add_pkg_config_path(path)
|
||||||
|
if pkg_config_path == "" then
|
||||||
|
pkg_config_path = path
|
||||||
|
else
|
||||||
|
pkg_config_path = pkg_config_path .. ":" .. path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Set whether to link libraries statically.
|
||||||
|
-- @param value boolean True for static linking, false otherwise.
|
||||||
|
function m.set_static_link_libs(value)
|
||||||
|
static_link_libs = value
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Add include directories and build options for a library.
|
||||||
|
-- @param lib string The library name.
|
||||||
|
-- @param alternative_cmd string|nil Optional alternative command.
|
||||||
|
-- @param alternative_flags string|nil Optional alternative flags.
|
||||||
|
function m.add_includes(lib, alternative_cmd, alternative_flags)
|
||||||
|
local dirs, files, options = parse_pkg_config_includes(lib, alternative_cmd, alternative_flags)
|
||||||
|
|
||||||
|
externalincludedirs(dirs)
|
||||||
|
forceincludes(files)
|
||||||
|
buildoptions(options)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Add include directories after the default ones (used for overrides).
|
||||||
|
-- @param lib string The library name.
|
||||||
|
-- @param alternative_cmd string|nil Optional alternative command.
|
||||||
|
-- @param alternative_flags string|nil Optional alternative flags.
|
||||||
|
function m.add_includes_after(lib, alternative_cmd, alternative_flags)
|
||||||
|
local dirs, files, options = parse_pkg_config_includes(lib, alternative_cmd, alternative_flags)
|
||||||
|
|
||||||
|
includedirsafter(dirs)
|
||||||
|
forceincludes(files)
|
||||||
|
buildoptions(options)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Add library directories, libraries, and link options for a library.
|
||||||
|
-- @param lib string The library name.
|
||||||
|
-- @param alternative_cmd string|nil Optional alternative command.
|
||||||
|
-- @param alternative_flags string|nil Optional alternative flags.
|
||||||
|
function m.add_links(lib, alternative_cmd, alternative_flags)
|
||||||
|
local dirs, libs, options = parse_pkg_config_links(lib, alternative_cmd, alternative_flags)
|
||||||
|
|
||||||
libdirs(dirs)
|
libdirs(dirs)
|
||||||
|
links(libs)
|
||||||
linkoptions(options)
|
linkoptions(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user