| [20381] | 1 | local m = {}
|
|---|
| [27606] | 2 | m._VERSION = "1.1.2-dev"
|
|---|
| [20381] | 3 |
|
|---|
| [25938] | 4 | m.additional_pc_path = nil
|
|---|
| 5 | m.static_link_libs = false
|
|---|
| 6 |
|
|---|
| [20381] | 7 | local function os_capture(cmd)
|
|---|
| 8 | return io.popen(cmd, 'r'):read('*a'):gsub("\n", " ")
|
|---|
| 9 | end
|
|---|
| 10 |
|
|---|
| [22302] | 11 | function 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)
|
|---|
| 54 | end
|
|---|
| 55 |
|
|---|
| [22302] | 56 | function 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)
|
|---|
| 91 | end
|
|---|
| 92 |
|
|---|
| 93 | return m
|
|---|