This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

source: ps/trunk/build/premake/pkgconfig/pkgconfig.lua

Last change on this file was 27606, checked in by s0600204, 21 months ago

Use premake5 beta2's externalincludedirs when available

As of the beta2 version of premake5, sysincludedirs has been deprecated
and replaced with/renamed to externalincludedirs, and continuing to use it
causes warnings to be emitted.

With this change, we now use externalincludedirs when available so as to
prevent the warnings, falling back to sysincludedirs when it's not to prevent
breakage with pre-beta2 versions of premake5.

Accepted By: sera
Fixes: #6785
Differential Revision: https://code.wildfiregames.com/D4980

File size: 2.7 KB
RevLine 
[20381]1local m = {}
[27606]2m._VERSION = "1.1.2-dev"
[20381]3
[25938]4m.additional_pc_path = nil
5m.static_link_libs = false
6
[20381]7local function os_capture(cmd)
8 return io.popen(cmd, 'r'):read('*a'):gsub("\n", " ")
9end
10
[22302]11function m.add_includes(lib, alternative_cmd, alternative_flags)
[20381]12 local result
13 if not alternative_cmd then
[25938]14 local pc_path = m.additional_pc_path and "PKG_CONFIG_PATH="..m.additional_pc_path or ""
15 result = os_capture(pc_path.." pkg-config --cflags "..lib)
[20381]16 else
[22302]17 if not alternative_flags then
18 result = os_capture(alternative_cmd.." --cflags")
19 else
20 result = os_capture(alternative_cmd.." "..alternative_flags)
21 end
[20381]22 end
23
[20523]24 -- Small trick: delete the space after -include so that we can detect
25 -- which files have to be force-included without difficulty.
26 result = result:gsub("%-include +(%g+)", "-include%1")
27
[20381]28 local dirs = {}
[20523]29 local files = {}
[20381]30 local options = {}
31 for w in string.gmatch(result, "[^' ']+") do
32 if string.sub(w,1,2) == "-I" then
33 table.insert(dirs, string.sub(w,3))
[20523]34 elseif string.sub(w,1,8) == "-include" then
35 table.insert(files, string.sub(w,9))
[20381]36 else
37 table.insert(options, w)
38 end
39 end
40
[27606]41 -- As of premake5-beta2, `sysincludedirs` has been deprecated in favour of
42 -- `externalincludedirs`, and continuing to use it causes warnings to be emitted.
43 -- We use `externalincludedirs` when available to prevent the warnings, falling back
44 -- to `sysincludedirs` when not to prevent breakage of the `--with-system-premake5`
45 -- build argument.
46 if externalincludedirs then
47 externalincludedirs(dirs)
48 else
49 sysincludedirs(dirs)
50 end
51
[20523]52 forceincludes(files)
[20381]53 buildoptions(options)
54end
55
[22302]56function m.add_links(lib, alternative_cmd, alternative_flags)
[20381]57 local result
58 if not alternative_cmd then
[25938]59 local pc_path = m.additional_pc_path and "PKG_CONFIG_PATH="..m.additional_pc_path or ""
60 local static = m.static_link_libs and " --static " or ""
61 result = os_capture(pc_path.." pkg-config --libs "..static..lib)
[20381]62 else
[25938]63 if not alternative_flags then
[22302]64 result = os_capture(alternative_cmd.." --libs")
65 else
66 result = os_capture(alternative_cmd.." "..alternative_flags)
67 end
[20381]68 end
69
70 -- On OSX, wx-config outputs "-framework foo" instead of "-Wl,-framework,foo"
71 -- which doesn't fare well with the splitting into libs, libdirs and options
72 -- we perform afterwards.
73 result = result:gsub("%-framework +(%g+)", "-Wl,-framework,%1")
74
75 local libs = {}
76 local dirs = {}
77 local options = {}
78 for w in string.gmatch(result, "[^' ']+") do
79 if string.sub(w,1,2) == "-l" then
80 table.insert(libs, string.sub(w,3))
81 elseif string.sub(w,1,2) == "-L" then
82 table.insert(dirs, string.sub(w,3))
83 else
84 table.insert(options, w)
85 end
86 end
87
88 links(libs)
89 libdirs(dirs)
90 linkoptions(options)
91end
92
93return m
Note: See TracBrowser for help on using the repository browser.