Index: build/premake/extern_libs5.lua =================================================================== --- build/premake/extern_libs5.lua +++ build/premake/extern_libs5.lua @@ -265,7 +265,7 @@ else -- Support GLOOX_CONFIG for overriding the default (pkg-config --cflags gloox) -- i.e. on OSX where it gets set in update-workspaces.sh - pkgconfig.add_includes("gloox", os.getenv("GLOOX_CONFIG")) + pkgconfig.load("gloox", os.getenv("GLOOX_CONFIG")).add_includes() end end, link_settings = function() @@ -276,7 +276,7 @@ no_delayload = 1, }) else - pkgconfig.add_links("gloox", os.getenv("GLOOX_CONFIG")) + pkgconfig.load("gloox", os.getenv("GLOOX_CONFIG")).add_links() if os.istarget("macosx") then -- Manually add gnutls dependencies, those are not present in gloox's pkg-config @@ -333,7 +333,7 @@ else -- Support ICU_CONFIG for overriding the default (pkg-config --cflags icu-i18n) -- i.e. on OSX where it gets set in update-workspaces.sh - pkgconfig.add_includes("icu-i18n", os.getenv("ICU_CONFIG"), "--cppflags") + pkgconfig.load("icu-i18n", os.getenv("ICU_CONFIG")).add_includes("--cppflags") end end, link_settings = function() @@ -345,7 +345,7 @@ no_delayload = 1, }) else - pkgconfig.add_links("icu-i18n", os.getenv("ICU_CONFIG"), "--ldflags-searchpath --ldflags-libsonly --ldflags-system") + pkgconfig.load("icu-i18n", os.getenv("ICU_CONFIG")).add_links("--ldflags-searchpath --ldflags-libsonly --ldflags-system") end end, }, @@ -412,7 +412,7 @@ else -- Support XML2_CONFIG for overriding the default (pkg-config --cflags libxml-2.0) -- i.e. on OSX where it gets set in update-workspaces.sh - pkgconfig.add_includes("libxml-2.0", os.getenv("XML2_CONFIG")) + pkgconfig.load("libxml-2.0", os.getenv("XML2_CONFIG")).add_includes() end if os.istarget("macosx") then -- libxml2 needs _REENTRANT or __MT__ for thread support; @@ -429,7 +429,7 @@ links { "libxml2" } filter { } else - pkgconfig.add_links("libxml-2.0", os.getenv("XML2_CONFIG")) + pkgconfig.load("libxml-2.0", os.getenv("XML2_CONFIG")).add_links() end end, }, @@ -520,14 +520,14 @@ elseif not _OPTIONS["android"] then -- Support SDL2_CONFIG for overriding the default (pkg-config sdl2) -- i.e. on OSX where it gets set in update-workspaces.sh - pkgconfig.add_includes("sdl2", os.getenv("SDL2_CONFIG")) + pkgconfig.load("sdl2", os.getenv("SDL2_CONFIG")).add_includes() end end, link_settings = function() if os.istarget("windows") then add_default_lib_paths("sdl2") elseif not _OPTIONS["android"] then - pkgconfig.add_links("sdl2", os.getenv("SDL2_CONFIG")) + pkgconfig.load("sdl2", os.getenv("SDL2_CONFIG")).add_links() end end, }, @@ -535,7 +535,16 @@ compile_settings = function() if _OPTIONS["with-system-mozjs52"] then if not _OPTIONS["android"] then - pkgconfig.add_includes("mozjs-52") + -- Many linux distros package icu headers in with spidermonkey headers, but + -- do not provide compatible icu library files to go along with them. + -- + -- Attempting to use the spidermonkey-icu headers with a distro's + -- standard-icu lib files causes linking errors. + -- + -- Therefore, we set the spidermonkey includes directory to be searched + -- *after* the standard system includes so gcc/clang finds and includes + -- compatible icu headers. + pkgconfig.load("mozjs-52").add_includes_after_system() end else if os.istarget("windows") then @@ -557,7 +566,7 @@ if _OPTIONS["android"] then links { "mozjs-52" } else - pkgconfig.add_links("mozjs-52") + pkgconfig.load("mozjs-52").add_links() end else filter { "Debug", "action:vs2015" } @@ -623,7 +632,7 @@ -- wxwidgets does not come with a definition file for pkg-config, -- so we have to use wxwidgets' own config tool wx_config_path = os.getenv("WX_CONFIG") or "wx-config" - pkgconfig.add_includes(nil, wx_config_path, "--unicode=yes --cxxflags") + pkgconfig.load(nil, wx_config_path).add_includes("--unicode=yes --cxxflags") end end, link_settings = function() @@ -631,19 +640,19 @@ libdirs { libraries_dir.."wxwidgets/lib/vc_lib" } else wx_config_path = os.getenv("WX_CONFIG") or "wx-config" - pkgconfig.add_links(nil, wx_config_path, "--unicode=yes --libs std,gl") + pkgconfig.load(nil, wx_config_path).add_links("--unicode=yes --libs std,gl") end end, }, x11 = { compile_settings = function() if not os.istarget("windows") and not os.istarget("macosx") then - pkgconfig.add_includes("x11") + pkgconfig.load("x11").add_includes() end end, link_settings = function() if not os.istarget("windows") and not os.istarget("macosx") then - pkgconfig.add_links("x11") + pkgconfig.load("x11").add_links() end end, }, Index: build/premake/pkgconfig/pkgconfig.lua =================================================================== --- build/premake/pkgconfig/pkgconfig.lua +++ build/premake/pkgconfig/pkgconfig.lua @@ -1,11 +1,11 @@ local m = {} -m._VERSION = "1.1.0-dev" +m._VERSION = "1.2.1-dev" local function os_capture(cmd) return io.popen(cmd, 'r'):read('*a'):gsub("\n", " ") end -function m.add_includes(lib, alternative_cmd, alternative_flags) +local function find_includes(lib, alternative_cmd, alternative_flags) local result if not alternative_cmd then result = os_capture("pkg-config --cflags "..lib) @@ -34,12 +34,10 @@ end end - sysincludedirs(dirs) - forceincludes(files) - buildoptions(options) + return dirs, files, options end -function m.add_links(lib, alternative_cmd, alternative_flags) +local function find_links(lib, alternative_cmd, alternative_flags) local result if not alternative_cmd then result = os_capture("pkg-config --libs "..lib) @@ -69,9 +67,35 @@ end end - links(libs) - libdirs(dirs) - linkoptions(options) + return libs, dirs, options +end + +function m.load(lib, alternative_cmd) + + local meths = {} + + function meths.add_includes(alternative_flags) + local dirs, files, options = find_includes(lib, alternative_cmd, alternative_flags) + sysincludedirs(dirs) + forceincludes(files) + buildoptions(options) + end + + function meths.add_includes_after_system(alternative_flags) + local dirs, files, options = find_includes(lib, alternative_cmd, alternative_flags) + aftersysincludedirs(dirs) + forceincludes(files) + buildoptions(options) + end + + function meths.add_links(alternative_flags) + local libs, dirs, options = find_links(lib, alternative_cmd, alternative_flags) + links(libs) + libdirs(dirs) + linkoptions(options) + end + + return meths end return m Index: build/premake/premake5/modules/gmake/gmake_cpp.lua =================================================================== --- build/premake/premake5/modules/gmake/gmake_cpp.lua +++ build/premake/premake5/modules/gmake/gmake_cpp.lua @@ -521,7 +521,7 @@ function make.includes(cfg, toolset) - local includes = toolset.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs) + local includes = toolset.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs, cfg.aftersysincludedirs) _p(' INCLUDES +=%s', make.list(includes)) end Index: build/premake/premake5/modules/gmake2/gmake2_cpp.lua =================================================================== --- build/premake/premake5/modules/gmake2/gmake2_cpp.lua +++ build/premake/premake5/modules/gmake2/gmake2_cpp.lua @@ -436,7 +436,7 @@ function cpp.includes(cfg, toolset) - local includes = toolset.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs) + local includes = toolset.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs, cfg.aftersysincludedirs) p.outln('INCLUDES +=' .. gmake2.list(includes)) end Index: build/premake/premake5/src/_premake_init.lua =================================================================== --- build/premake/premake5/src/_premake_init.lua +++ build/premake/premake5/src/_premake_init.lua @@ -18,6 +18,13 @@ -- ----------------------------------------------------------------------------- + api.register { + name = "aftersysincludedirs", + scope = "config", + kind = "list:directory", + tokens = true, + } + api.register { name = "architecture", scope = "config", Index: build/premake/premake5/src/tools/clang.lua =================================================================== --- build/premake/premake5/src/tools/clang.lua +++ build/premake/premake5/src/tools/clang.lua @@ -168,10 +168,10 @@ -- An array of symbols with the appropriate flag decorations. -- - function clang.getincludedirs(cfg, dirs, sysdirs) + function clang.getincludedirs(cfg, dirs, sysdirs, aftersysdirs) -- Just pass through to GCC for now - local flags = gcc.getincludedirs(cfg, dirs, sysdirs) + local flags = gcc.getincludedirs(cfg, dirs, sysdirs, aftersysdirs) return flags end Index: build/premake/premake5/src/tools/gcc.lua =================================================================== --- build/premake/premake5/src/tools/gcc.lua +++ build/premake/premake5/src/tools/gcc.lua @@ -239,7 +239,7 @@ -- Decorate include file search paths for the GCC command line. -- - function gcc.getincludedirs(cfg, dirs, sysdirs) + function gcc.getincludedirs(cfg, dirs, sysdirs, aftersysdirs) local result = {} for _, dir in ipairs(dirs) do dir = project.getrelative(cfg.project, dir) @@ -249,6 +249,10 @@ dir = project.getrelative(cfg.project, dir) table.insert(result, '-isystem ' .. p.quoted(dir)) end + for _, dir in ipairs(aftersysdirs or {}) do + dir = project.getrelative(cfg.project, dir) + table.insert(result, '-idirafter ' .. p.quoted(dir)) + end return result end Index: build/premake/premake5/src/tools/msc.lua =================================================================== --- build/premake/premake5/src/tools/msc.lua +++ build/premake/premake5/src/tools/msc.lua @@ -217,13 +217,17 @@ -- Decorate include file search paths for the MSVC command line. -- - function msc.getincludedirs(cfg, dirs, sysdirs) + function msc.getincludedirs(cfg, dirs, sysdirs, aftersysdirs) local result = {} dirs = table.join(dirs, sysdirs) for _, dir in ipairs(dirs) do dir = project.getrelative(cfg.project, dir) table.insert(result, '-I' .. p.quoted(dir)) end + for _, dir in ipairs(aftersysdirs) do + dir = project.getrelative(cfg.project, dir) + table.insert(flags, '/INCLUDE:"' .. dir .. '"') + end return result end Index: build/premake/premake5/tests/tools/test_gcc.lua =================================================================== --- build/premake/premake5/tests/tools/test_gcc.lua +++ build/premake/premake5/tests/tools/test_gcc.lua @@ -619,6 +619,17 @@ end +-- +-- Check handling of search paths that come after the standard system search paths +-- + + function suite.includeDirs_onAfterSysIncludeDirs() + aftersysincludedirs { "/usr/local/include" } + prepare() + test.contains("-idirafter /usr/local/include", gcc.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs, cfg.aftersysincludedirs)) + end + + -- -- Check handling of link time optimization flag. --