Index: build/premake/extern_libs5.lua =================================================================== --- build/premake/extern_libs5.lua +++ build/premake/extern_libs5.lua @@ -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.add_includes("mozjs-52", nil, nil, true) end else if os.istarget("windows") then Index: build/premake/pkgconfig/pkgconfig.lua =================================================================== --- build/premake/pkgconfig/pkgconfig.lua +++ build/premake/pkgconfig/pkgconfig.lua @@ -5,7 +5,7 @@ return io.popen(cmd, 'r'):read('*a'):gsub("\n", " ") end -function m.add_includes(lib, alternative_cmd, alternative_flags) +function m.add_includes(lib, alternative_cmd, alternative_flags, after_system_includes) local result if not alternative_cmd then result = os_capture("pkg-config --cflags "..lib) @@ -34,7 +34,11 @@ end end - sysincludedirs(dirs) + if not after_system_includes then + sysincludedirs(dirs) + else + aftersysincludedirs(dirs) + end forceincludes(files) buildoptions(options) end 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 @@ -1104,6 +1104,13 @@ tokens = true, } + api.register { + name = "aftersysincludedirs", + scope = "config", + kind = "list:directory", + tokens = true, + } + api.register { name = "syslibdirs", 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,9 +217,9 @@ -- 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) + dirs = table.join(dirs, sysdirs, aftersysdirs) for _, dir in ipairs(dirs) do dir = project.getrelative(cfg.project, dir) table.insert(result, '-I' .. p.quoted(dir)) 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. --