Skip to content

Commit 1cac2e0

Browse files
committed
Enable cxx11 abi for GCC 4.9+ on linux.
GCC version is checked, if version is 4.8 or lower then cxx11 ABI is disabled. Added new `--no-cxx11-abi` option. It explicitly disables cxx11 ABI even on new compilers. This option is also taken into account when building LLVM.
1 parent a097cdd commit 1cac2e0

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

build/Helpers.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ newoption {
99
}
1010
}
1111

12+
newoption {
13+
trigger = "no-cxx11-abi",
14+
description = "disable cxx11 abi on gcc 4.9+"
15+
}
16+
1217
explicit_target_architecture = _OPTIONS["arch"]
1318

1419
function is_64_bits_mono_runtime()
@@ -95,6 +100,12 @@ function SetupNativeProject()
95100
defines { "WIN32", "_WINDOWS" }
96101

97102
filter {}
103+
104+
if os.istarget("linux") then
105+
if not UseCxx11ABI() then
106+
defines { "_GLIBCXX_USE_CXX11_ABI=0" }
107+
end
108+
end
98109
end
99110

100111
function SetupManagedProject()
@@ -164,3 +175,20 @@ function StaticLinksOpt(libnames)
164175

165176
links(existing_libnames)
166177
end
178+
179+
function GccVersion()
180+
local compiler = os.getenv("CXX")
181+
if compiler == nil then
182+
compiler = "gcc"
183+
end
184+
local out = os.outputof(compiler.." -v")
185+
local version = string.match(out, "gcc version [0-9\\.]+")
186+
return string.sub(version, 13)
187+
end
188+
189+
function UseCxx11ABI()
190+
if os.istarget("linux") and GccVersion() >= '4.9.0' and _OPTIONS["no-cxx11-abi"] == nil then
191+
return true
192+
end
193+
return false
194+
end

build/scripts/LLVM.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ function cmake(gen, conf, builddir, options)
181181
os.chdir(builddir)
182182
local cmake = os.ishost("macosx") and "/Applications/CMake.app/Contents/bin/cmake"
183183
or "cmake"
184+
185+
if options == nil then
186+
options = ""
187+
end
188+
if os.istarget("linux") and _OPTIONS["no-cxx11-abi"] ~= nil then
189+
options = options.." -DCMAKE_CXX_FLAGS='-D_GLIBCXX_USE_CXX11_ABI=0'"
190+
end
191+
184192
local cmd = cmake .. " -G " .. '"' .. gen .. '"'
185193
.. ' -DLLVM_BUILD_TOOLS=false '
186194
.. ' -DLLVM_ENABLE_LIBEDIT=false'

src/CppParser/Bindings/CSharp/premake5.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ project "CppSharp.Parser.CSharp"
2525
end
2626

2727
elseif os.istarget("linux") then
28-
files { "x86_64-linux-gnu/**.cs" }
28+
local abi = ""
29+
if UseCxx11ABI() then
30+
abi = "-cxx11abi"
31+
end
32+
files { "x86_64-linux-gnu"..abi.."/**.cs" }
2933
else
3034
print "Unknown architecture"
3135
end

src/CppParser/premake5.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ project "CppSharp.CppParser"
2222
linkoptions { "/ignore:4099" } -- LNK4099: linking object as if no debug info
2323
end
2424

25-
filter "system:linux"
26-
defines { "_GLIBCXX_USE_CXX11_ABI=0" }
27-
2825
filter {}
2926

3027
files
@@ -65,7 +62,11 @@ project "Std-symbols"
6562
end
6663

6764
elseif os.istarget("linux") then
68-
files { "Bindings/CSharp/x86_64-linux-gnu/Std-symbols.cpp" }
65+
local abi = ""
66+
if UseCxx11ABI() then
67+
abi = "-cxx11abi"
68+
end
69+
files { "Bindings/CSharp/x86_64-linux-gnu"..abi.."/Std-symbols.cpp" }
6970
else
7071
print "Unknown architecture"
7172
end

0 commit comments

Comments
 (0)