Skip to content

Commit 4fcfe4e

Browse files
committed
Build changes.
- Added support for building with Clang and LLD - Switched to use csc.exe Roslyn compiler under Mono - Disable most of the support for explicit pre-C++11 ABI since we do not need it anymore
1 parent 302565d commit 4fcfe4e

File tree

9 files changed

+75
-43
lines changed

9 files changed

+75
-43
lines changed

build/Helpers.lua

+23-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ newoption {
1212

1313
newoption {
1414
trigger = "no-cxx11-abi",
15-
description = "disable cxx11 abi on gcc 4.9+"
15+
description = "disable C++-11 ABI on GCC 4.9+"
1616
}
1717

1818
explicit_target_architecture = _OPTIONS["arch"]
@@ -40,7 +40,15 @@ if not _OPTIONS["arch"] then
4040
_OPTIONS["arch"] = target_architecture()
4141
end
4242

43-
action = _ACTION or ""
43+
-- Uncomment to enable Roslyn compiler.
44+
--[[
45+
premake.override(premake.tools.dotnet, "gettoolname", function(base, cfg, tool)
46+
if tool == "csc" then
47+
return "csc"
48+
end
49+
return base(cfg, tool)
50+
end)
51+
]]
4452

4553
basedir = path.getdirectory(_PREMAKE_COMMAND)
4654
depsdir = path.getabsolute("../deps");
@@ -50,7 +58,7 @@ bindir = path.getabsolute("../bin");
5058
examplesdir = path.getabsolute("../examples");
5159
testsdir = path.getabsolute("../tests");
5260

53-
builddir = path.getabsolute("./" .. action);
61+
builddir = path.getabsolute("./" .. _ACTION);
5462
if _ARGS[1] then
5563
builddir = path.getabsolute("./" .. _ARGS[1]);
5664
end
@@ -72,6 +80,7 @@ msvc_cpp_defines = { }
7280
generate_build_config = true
7381

7482
function string.starts(str, start)
83+
if str == nil then return end
7584
return string.sub(str, 1, string.len(start)) == start
7685
end
7786

@@ -99,6 +108,9 @@ function SetupNativeProject()
99108
buildoptions { gcc_buildflags }
100109
links { "stdc++" }
101110

111+
filter { "toolset:clang", "system:not macosx" }
112+
linkoptions { "-fuse-ld=/usr/bin/ld.lld" }
113+
102114
filter { "system:macosx", "language:C++" }
103115
buildoptions { gcc_buildflags, "-stdlib=libc++" }
104116
links { "c++" }
@@ -116,12 +128,6 @@ function SetupNativeProject()
116128
systemversion("latest")
117129

118130
filter {}
119-
120-
if os.istarget("linux") then
121-
if not UseCxx11ABI() then
122-
defines { "_GLIBCXX_USE_CXX11_ABI=0" }
123-
end
124-
end
125131
end
126132

127133
function SetupManagedProject()
@@ -195,13 +201,21 @@ function StaticLinksOpt(libnames)
195201
links(existing_libnames)
196202
end
197203

204+
function UseClang()
205+
local compiler = os.getenv("CXX")
206+
return string.match(compiler, "clang")
207+
end
208+
198209
function GccVersion()
199210
local compiler = os.getenv("CXX")
200211
if compiler == nil then
201212
compiler = "gcc"
202213
end
203214
local out = os.outputof(compiler.." -v")
204215
local version = string.match(out, "gcc version [0-9\\.]+")
216+
if version == nil then
217+
version = string.match(out, "clang version [0-9\\.]+")
218+
end
205219
return string.sub(version, 13)
206220
end
207221

build/LLVM.lua

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ local LLVMRootDirRelease = ""
1010
require "scripts/LLVM"
1111

1212
function SearchLLVM()
13+
local basedir = path.getdirectory(_PREMAKE_COMMAND)
1314
LLVMRootDirDebug = basedir .. "/scripts/" .. get_llvm_package_name(nil, "Debug")
1415
LLVMRootDirRelease = basedir .. "/scripts/" .. get_llvm_package_name()
1516

build/Tests.lua

+3
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ function SetupTestProjectsCSharp(name, depends, extraFiles, suffix)
190190

191191
LinkNUnit()
192192
links { "CppSharp.Runtime" }
193+
194+
filter { "action:netcore" }
195+
dotnetframework "netcoreapp2.0"
193196
end
194197

195198
function SetupTestProjectsCLI(name, extraFiles, suffix)

build/premake5.lua

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ solution "CppSharp"
3030
include (srcdir .. "/AST")
3131
include (srcdir .. "/CppParser")
3232
include (srcdir .. "/CppParser/Bindings")
33+
include (srcdir .. "/CppParser/Bootstrap")
3334
include (srcdir .. "/CppParser/ParserGen")
3435
include (srcdir .. "/Parser")
3536
include (srcdir .. "/CLI")

build/scripts/ClangToolset.cmake

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
SET (CMAKE_C_COMPILER "/usr/bin/clang")
2+
SET (CMAKE_C_FLAGS "-Wall -std=c99")
3+
SET (CMAKE_C_FLAGS_DEBUG "-glldb")
4+
SET (CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
5+
SET (CMAKE_C_FLAGS_RELEASE "-O4 -DNDEBUG")
6+
SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -glldb")
7+
8+
SET (CMAKE_CXX_COMPILER "/usr/bin/clang++")
9+
SET (CMAKE_CXX_FLAGS "-Wall")
10+
SET (CMAKE_CXX_FLAGS_DEBUG "-glldb")
11+
SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
12+
SET (CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG")
13+
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -glldb")
14+
15+
SET (CMAKE_AR "/usr/bin/llvm-ar")
16+
SET (CMAKE_LINKER "/usr/bin/llvm-ld")
17+
SET (CMAKE_NM "/usr/bin/llvm-nm")
18+
SET (CMAKE_OBJDUMP "/usr/bin/llvm-objdump")
19+
SET (CMAKE_RANLIB "/usr/bin/llvm-ranlib")

build/scripts/LLVM.lua

+21-26
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ require "Build"
22
require "Utils"
33
require "../Helpers"
44

5+
local basedir = path.getdirectory(_PREMAKE_COMMAND)
56
local llvm = path.getabsolute(basedir .. "/../deps/llvm")
67

78
-- Prevent premake from inserting /usr/lib64 search path on linux. GCC does not need this path specified
@@ -112,15 +113,19 @@ function get_llvm_package_name(rev, conf, arch)
112113
local toolset = get_toolset_configuration_name(arch)
113114
table.insert(components, toolset)
114115

115-
if os.istarget("linux") then
116-
local version = GccVersion()
117-
if version < "5.0.0" then
118-
-- Minor version matters only with gcc 4.8/4.9
119-
version = string.match(version, "%d+.%d+")
120-
else
121-
version = string.match(version, "%d+")
122-
end
123-
table.insert(components, "gcc-"..version)
116+
if os.istarget("linux") then
117+
if UseClang() then
118+
table.insert(components, "clang")
119+
else
120+
local version = GccVersion()
121+
if version < "5.0.0" then
122+
-- Minor version matters only with gcc 4.8/4.9
123+
version = string.match(version, "%d+.%d+")
124+
else
125+
version = string.match(version, "%d+")
126+
end
127+
table.insert(components, "gcc-"..version)
128+
end
124129
end
125130

126131
if not conf then
@@ -129,12 +134,6 @@ function get_llvm_package_name(rev, conf, arch)
129134

130135
table.insert(components, conf)
131136

132-
if os.istarget("linux") then
133-
if GccVersion() >= "4.9.0" and not UseCxx11ABI() then
134-
table.insert(components, "no-cxx11")
135-
end
136-
end
137-
138137
return table.concat(components, "-")
139138
end
140139

@@ -216,24 +215,24 @@ function cmake(gen, conf, builddir, options)
216215
if options == nil then
217216
options = ""
218217
end
219-
if not UseCxx11ABI() then
220-
options = options.." -DCMAKE_CXX_FLAGS='-D_GLIBCXX_USE_CXX11_ABI=0'"
218+
219+
if UseClang() then
220+
local cmake = path.join(basedir, "scripts", "ClangToolset.cmake")
221+
options = options .. " -DLLVM_USE_LINKER=/usr/bin/ld.lld"
221222
end
222223

223224
local cmd = cmake .. " -G " .. '"' .. gen .. '"'
224225
.. ' -DCLANG_BUILD_TOOLS=false'
225-
.. ' -DCLANG_INSTALL_SCANBUILD=false'
226-
.. ' -DCLANG_INSTALL_SCANVIEW=false'
227226
.. ' -DCLANG_TOOL_CLANG_DIFF_BUILD=false'
228227
.. ' -DCLANG_TOOL_CLANG_FUNC_MAPPING_BUILD=false'
229228
.. ' -DCLANG_TOOL_CLANG_IMPORT_TEST_BUILD=false'
230229
.. ' -DCLANG_TOOL_CLANG_OFFLOAD_BUNDLER_BUILD=false'
231230
.. ' -DCLANG_TOOL_CLANG_REFACTOR_BUILD=false'
232231
.. ' -DCLANG_TOOL_CLANG_RENAME_BUILD=false'
233232
.. ' -DCLANG_TOOL_DRIVER_BUILD=false'
234-
.. ' -DCLANG_TOOL_HANDLE_CXX_BUILD=false'
235-
.. ' -DCLANG_TOOL_HANDLE_LLVM_BUILD=false'
236-
.. ' -DLLVM_BUILD_TOOLS=false'
233+
.. ' -DLLVM_BUILD_TOOLS=false'
234+
.. ' -DLLVM_ENABLE_DUMP=true'
235+
.. ' -DLLVM_ENABLE_DUMP=true'
237236
.. ' -DLLVM_ENABLE_LIBEDIT=false'
238237
.. ' -DLLVM_ENABLE_ZLIB=false'
239238
.. ' -DLLVM_ENABLE_TERMINFO=false'
@@ -278,20 +277,17 @@ function cmake(gen, conf, builddir, options)
278277
.. ' -DLLVM_TOOL_LLVM_LINK_BUILD=false'
279278
.. ' -DLLVM_TOOL_LLVM_LTO_BUILD=false'
280279
.. ' -DLLVM_TOOL_LLVM_LTO2_BUILD=false'
281-
.. ' -DLLVM_TOOL_LLVM_MCMARKUP_BUILD=false'
282280
.. ' -DLLVM_TOOL_LLVM_MC_ASSEMBLE_FUZZER_BUILD=false'
283281
.. ' -DLLVM_TOOL_LLVM_MC_BUILD=false'
284282
.. ' -DLLVM_TOOL_LLVM_MC_DISASSEMBLE_FUZZER_BUILD=false'
285283
.. ' -DLLVM_TOOL_LLVM_MCA_BUILD=false'
286-
.. ' -DLLVM_TOOL_LLVM_MC_FUZZER_BUILD=false'
287284
.. ' -DLLVM_TOOL_LLVM_MODEXTRACT_BUILD=false'
288285
.. ' -DLLVM_TOOL_LLVM_MT_BUILD=false'
289286
.. ' -DLLVM_TOOL_LLVM_NM_BUILD=false'
290287
.. ' -DLLVM_TOOL_LLVM_OBJCOPY_BUILD=false'
291288
.. ' -DLLVM_TOOL_LLVM_OBJDUMP_BUILD=false'
292289
.. ' -DLLVM_TOOL_LLVM_OPT_FUZZER_BUILD=false'
293290
.. ' -DLLVM_TOOL_LLVM_OPT_REPORT_BUILD=false'
294-
.. ' -DLLVM_TOOL_LLVM_PDBDUMP_BUILD=false'
295291
.. ' -DLLVM_TOOL_LLVM_PDBUTIL_BUILD=false'
296292
.. ' -DLLVM_TOOL_LLVM_PROFDATA_BUILD=false'
297293
.. ' -DLLVM_TOOL_LLVM_PDBUTIL_BUILD=false'
@@ -308,7 +304,6 @@ function cmake(gen, conf, builddir, options)
308304
.. ' -DLLVM_TOOL_LLVM_UNDNAME_BUILD=false'
309305
.. ' -DLLVM_TOOL_LLVM_XRAY_BUILD=false'
310306
.. ' -DLLVM_TOOL_LTO_BUILD=false'
311-
.. ' -DLLVM_TOOL_MSBUILD_BUILD=false'
312307
.. ' -DLLVM_TOOL_OBJ2YAML_BUILD=false'
313308
.. ' -DLLVM_TOOL_OPT_BUILD=false'
314309
.. ' -DLLVM_TOOL_OPT_VIEWER_BUILD=false'

src/CppParser/Bootstrap/Bootstrap.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ static string GetSourceDirectory(string dir)
1919
{
2020
var path = Path.Combine(directory.FullName, dir);
2121

22-
if (Directory.Exists(path) &&
23-
Directory.Exists(Path.Combine(directory.FullName, "patches")))
22+
if (Directory.Exists(path))
2423
return path;
2524

2625
directory = directory.Parent;
@@ -33,9 +32,7 @@ public void Setup(Driver driver)
3332
{
3433
driver.Options.GeneratorKind = GeneratorKind.CSharp;
3534
driver.Options.DryRun = true;
36-
driver.ParserOptions.SetupXcode();
37-
driver.ParserOptions.MicrosoftMode = false;
38-
driver.ParserOptions.TargetTriple = "i686-apple-darwin12.4.0";
35+
driver.ParserOptions.Setup();
3936

4037
var module = driver.Options.AddModule("CppSharp");
4138

src/CppParser/Bootstrap/premake5.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ project "CppSharp.Parser.Bootstrap"
77
debugdir "."
88

99
files { "Bootstrap.cs", "*.lua" }
10-
links { "CppSharp", "CppSharp.AST", "CppSharp.Generator", "System", "System.Core" }
10+
links { "CppSharp", "CppSharp.AST", "CppSharp.Generator", "CppSharp.Parser" }
11+
12+
filter { "action:not netcore" }
13+
links { "System", "System.Core" }
1114

1215
SetupParser()
13-

src/Parser/premake5.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ local function GenerateBuildConfig()
1111
file:close()
1212
end
1313

14-
if generate_build_config == true then
14+
if generate_build_config == true and _ACTION then
1515
GenerateBuildConfig()
1616
end
1717

0 commit comments

Comments
 (0)