diff --git a/build/Helpers.lua b/build/Helpers.lua index fcbdb90d..d80e0649 100644 --- a/build/Helpers.lua +++ b/build/Helpers.lua @@ -9,6 +9,11 @@ newoption { } } +newoption { + trigger = "no-cxx11-abi", + description = "disable cxx11 abi on gcc 4.9+" +} + explicit_target_architecture = _OPTIONS["arch"] function is_64_bits_mono_runtime() @@ -95,6 +100,12 @@ function SetupNativeProject() defines { "WIN32", "_WINDOWS" } filter {} + + if os.istarget("linux") then + if not UseCxx11ABI() then + defines { "_GLIBCXX_USE_CXX11_ABI=0" } + end + end end function SetupManagedProject() @@ -164,3 +175,20 @@ function StaticLinksOpt(libnames) links(existing_libnames) end + +function GccVersion() + local compiler = os.getenv("CXX") + if compiler == nil then + compiler = "gcc" + end + local out = os.outputof(compiler.." -v") + local version = string.match(out, "gcc version [0-9\\.]+") + return string.sub(version, 13) +end + +function UseCxx11ABI() + if os.istarget("linux") and GccVersion() >= '4.9.0' and _OPTIONS["no-cxx11-abi"] == nil then + return true + end + return false +end \ No newline at end of file diff --git a/build/scripts/LLVM.lua b/build/scripts/LLVM.lua index 939eca57..d40c420f 100644 --- a/build/scripts/LLVM.lua +++ b/build/scripts/LLVM.lua @@ -181,6 +181,14 @@ function cmake(gen, conf, builddir, options) os.chdir(builddir) local cmake = os.ishost("macosx") and "/Applications/CMake.app/Contents/bin/cmake" or "cmake" + + if options == nil then + options = "" + end + if os.istarget("linux") and _OPTIONS["no-cxx11-abi"] ~= nil then + options = options.." -DCMAKE_CXX_FLAGS='-D_GLIBCXX_USE_CXX11_ABI=0'" + end + local cmd = cmake .. " -G " .. '"' .. gen .. '"' .. ' -DLLVM_BUILD_TOOLS=false ' .. ' -DLLVM_ENABLE_LIBEDIT=false' diff --git a/src/CppParser/Bindings/CSharp/premake5.lua b/src/CppParser/Bindings/CSharp/premake5.lua index b645396e..1b006fe0 100644 --- a/src/CppParser/Bindings/CSharp/premake5.lua +++ b/src/CppParser/Bindings/CSharp/premake5.lua @@ -25,7 +25,11 @@ project "CppSharp.Parser.CSharp" end elseif os.istarget("linux") then - files { "x86_64-linux-gnu/**.cs" } + local abi = "" + if UseCxx11ABI() then + abi = "-cxx11abi" + end + files { "x86_64-linux-gnu"..abi.."/**.cs" } else print "Unknown architecture" end diff --git a/src/CppParser/premake5.lua b/src/CppParser/premake5.lua index d9d9ee1b..19ce8970 100644 --- a/src/CppParser/premake5.lua +++ b/src/CppParser/premake5.lua @@ -22,9 +22,6 @@ project "CppSharp.CppParser" linkoptions { "/ignore:4099" } -- LNK4099: linking object as if no debug info end - filter "system:linux" - defines { "_GLIBCXX_USE_CXX11_ABI=0" } - filter {} files @@ -65,7 +62,11 @@ project "Std-symbols" end elseif os.istarget("linux") then - files { "Bindings/CSharp/x86_64-linux-gnu/Std-symbols.cpp" } + local abi = "" + if UseCxx11ABI() then + abi = "-cxx11abi" + end + files { "Bindings/CSharp/x86_64-linux-gnu"..abi.."/Std-symbols.cpp" } else print "Unknown architecture" end