Browse Source

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
typeloc_clang
Joao Matos 6 years ago committed by João Matos
parent
commit
4fcfe4e4eb
  1. 32
      build/Helpers.lua
  2. 1
      build/LLVM.lua
  3. 3
      build/Tests.lua
  4. 1
      build/premake5.lua
  5. 19
      build/scripts/ClangToolset.cmake
  6. 47
      build/scripts/LLVM.lua
  7. 7
      src/CppParser/Bootstrap/Bootstrap.cs
  8. 6
      src/CppParser/Bootstrap/premake5.lua
  9. 2
      src/Parser/premake5.lua

32
build/Helpers.lua

@ -12,7 +12,7 @@ newoption { @@ -12,7 +12,7 @@ newoption {
newoption {
trigger = "no-cxx11-abi",
description = "disable cxx11 abi on gcc 4.9+"
description = "disable C++-11 ABI on GCC 4.9+"
}
explicit_target_architecture = _OPTIONS["arch"]
@ -40,7 +40,15 @@ if not _OPTIONS["arch"] then @@ -40,7 +40,15 @@ if not _OPTIONS["arch"] then
_OPTIONS["arch"] = target_architecture()
end
action = _ACTION or ""
-- Uncomment to enable Roslyn compiler.
--[[
premake.override(premake.tools.dotnet, "gettoolname", function(base, cfg, tool)
if tool == "csc" then
return "csc"
end
return base(cfg, tool)
end)
]]
basedir = path.getdirectory(_PREMAKE_COMMAND)
depsdir = path.getabsolute("../deps");
@ -50,7 +58,7 @@ bindir = path.getabsolute("../bin"); @@ -50,7 +58,7 @@ bindir = path.getabsolute("../bin");
examplesdir = path.getabsolute("../examples");
testsdir = path.getabsolute("../tests");
builddir = path.getabsolute("./" .. action);
builddir = path.getabsolute("./" .. _ACTION);
if _ARGS[1] then
builddir = path.getabsolute("./" .. _ARGS[1]);
end
@ -72,6 +80,7 @@ msvc_cpp_defines = { } @@ -72,6 +80,7 @@ msvc_cpp_defines = { }
generate_build_config = true
function string.starts(str, start)
if str == nil then return end
return string.sub(str, 1, string.len(start)) == start
end
@ -99,6 +108,9 @@ function SetupNativeProject() @@ -99,6 +108,9 @@ function SetupNativeProject()
buildoptions { gcc_buildflags }
links { "stdc++" }
filter { "toolset:clang", "system:not macosx" }
linkoptions { "-fuse-ld=/usr/bin/ld.lld" }
filter { "system:macosx", "language:C++" }
buildoptions { gcc_buildflags, "-stdlib=libc++" }
links { "c++" }
@ -116,12 +128,6 @@ function SetupNativeProject() @@ -116,12 +128,6 @@ function SetupNativeProject()
systemversion("latest")
filter {}
if os.istarget("linux") then
if not UseCxx11ABI() then
defines { "_GLIBCXX_USE_CXX11_ABI=0" }
end
end
end
function SetupManagedProject()
@ -195,6 +201,11 @@ function StaticLinksOpt(libnames) @@ -195,6 +201,11 @@ function StaticLinksOpt(libnames)
links(existing_libnames)
end
function UseClang()
local compiler = os.getenv("CXX")
return string.match(compiler, "clang")
end
function GccVersion()
local compiler = os.getenv("CXX")
if compiler == nil then
@ -202,6 +213,9 @@ function GccVersion() @@ -202,6 +213,9 @@ function GccVersion()
end
local out = os.outputof(compiler.." -v")
local version = string.match(out, "gcc version [0-9\\.]+")
if version == nil then
version = string.match(out, "clang version [0-9\\.]+")
end
return string.sub(version, 13)
end

1
build/LLVM.lua

@ -10,6 +10,7 @@ local LLVMRootDirRelease = "" @@ -10,6 +10,7 @@ local LLVMRootDirRelease = ""
require "scripts/LLVM"
function SearchLLVM()
local basedir = path.getdirectory(_PREMAKE_COMMAND)
LLVMRootDirDebug = basedir .. "/scripts/" .. get_llvm_package_name(nil, "Debug")
LLVMRootDirRelease = basedir .. "/scripts/" .. get_llvm_package_name()

3
build/Tests.lua

@ -190,6 +190,9 @@ function SetupTestProjectsCSharp(name, depends, extraFiles, suffix) @@ -190,6 +190,9 @@ function SetupTestProjectsCSharp(name, depends, extraFiles, suffix)
LinkNUnit()
links { "CppSharp.Runtime" }
filter { "action:netcore" }
dotnetframework "netcoreapp2.0"
end
function SetupTestProjectsCLI(name, extraFiles, suffix)

1
build/premake5.lua

@ -30,6 +30,7 @@ solution "CppSharp" @@ -30,6 +30,7 @@ solution "CppSharp"
include (srcdir .. "/AST")
include (srcdir .. "/CppParser")
include (srcdir .. "/CppParser/Bindings")
include (srcdir .. "/CppParser/Bootstrap")
include (srcdir .. "/CppParser/ParserGen")
include (srcdir .. "/Parser")
include (srcdir .. "/CLI")

19
build/scripts/ClangToolset.cmake

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
SET (CMAKE_C_COMPILER "/usr/bin/clang")
SET (CMAKE_C_FLAGS "-Wall -std=c99")
SET (CMAKE_C_FLAGS_DEBUG "-glldb")
SET (CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET (CMAKE_C_FLAGS_RELEASE "-O4 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -glldb")
SET (CMAKE_CXX_COMPILER "/usr/bin/clang++")
SET (CMAKE_CXX_FLAGS "-Wall")
SET (CMAKE_CXX_FLAGS_DEBUG "-glldb")
SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -glldb")
SET (CMAKE_AR "/usr/bin/llvm-ar")
SET (CMAKE_LINKER "/usr/bin/llvm-ld")
SET (CMAKE_NM "/usr/bin/llvm-nm")
SET (CMAKE_OBJDUMP "/usr/bin/llvm-objdump")
SET (CMAKE_RANLIB "/usr/bin/llvm-ranlib")

47
build/scripts/LLVM.lua

@ -2,6 +2,7 @@ require "Build" @@ -2,6 +2,7 @@ require "Build"
require "Utils"
require "../Helpers"
local basedir = path.getdirectory(_PREMAKE_COMMAND)
local llvm = path.getabsolute(basedir .. "/../deps/llvm")
-- 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) @@ -112,15 +113,19 @@ function get_llvm_package_name(rev, conf, arch)
local toolset = get_toolset_configuration_name(arch)
table.insert(components, toolset)
if os.istarget("linux") then
local version = GccVersion()
if version < "5.0.0" then
-- Minor version matters only with gcc 4.8/4.9
version = string.match(version, "%d+.%d+")
else
version = string.match(version, "%d+")
end
table.insert(components, "gcc-"..version)
if os.istarget("linux") then
if UseClang() then
table.insert(components, "clang")
else
local version = GccVersion()
if version < "5.0.0" then
-- Minor version matters only with gcc 4.8/4.9
version = string.match(version, "%d+.%d+")
else
version = string.match(version, "%d+")
end
table.insert(components, "gcc-"..version)
end
end
if not conf then
@ -129,12 +134,6 @@ function get_llvm_package_name(rev, conf, arch) @@ -129,12 +134,6 @@ function get_llvm_package_name(rev, conf, arch)
table.insert(components, conf)
if os.istarget("linux") then
if GccVersion() >= "4.9.0" and not UseCxx11ABI() then
table.insert(components, "no-cxx11")
end
end
return table.concat(components, "-")
end
@ -216,14 +215,14 @@ function cmake(gen, conf, builddir, options) @@ -216,14 +215,14 @@ function cmake(gen, conf, builddir, options)
if options == nil then
options = ""
end
if not UseCxx11ABI() then
options = options.." -DCMAKE_CXX_FLAGS='-D_GLIBCXX_USE_CXX11_ABI=0'"
if UseClang() then
local cmake = path.join(basedir, "scripts", "ClangToolset.cmake")
options = options .. " -DLLVM_USE_LINKER=/usr/bin/ld.lld"
end
local cmd = cmake .. " -G " .. '"' .. gen .. '"'
.. ' -DCLANG_BUILD_TOOLS=false'
.. ' -DCLANG_INSTALL_SCANBUILD=false'
.. ' -DCLANG_INSTALL_SCANVIEW=false'
.. ' -DCLANG_TOOL_CLANG_DIFF_BUILD=false'
.. ' -DCLANG_TOOL_CLANG_FUNC_MAPPING_BUILD=false'
.. ' -DCLANG_TOOL_CLANG_IMPORT_TEST_BUILD=false'
@ -231,9 +230,9 @@ function cmake(gen, conf, builddir, options) @@ -231,9 +230,9 @@ function cmake(gen, conf, builddir, options)
.. ' -DCLANG_TOOL_CLANG_REFACTOR_BUILD=false'
.. ' -DCLANG_TOOL_CLANG_RENAME_BUILD=false'
.. ' -DCLANG_TOOL_DRIVER_BUILD=false'
.. ' -DCLANG_TOOL_HANDLE_CXX_BUILD=false'
.. ' -DCLANG_TOOL_HANDLE_LLVM_BUILD=false'
.. ' -DLLVM_BUILD_TOOLS=false'
.. ' -DLLVM_BUILD_TOOLS=false'
.. ' -DLLVM_ENABLE_DUMP=true'
.. ' -DLLVM_ENABLE_DUMP=true'
.. ' -DLLVM_ENABLE_LIBEDIT=false'
.. ' -DLLVM_ENABLE_ZLIB=false'
.. ' -DLLVM_ENABLE_TERMINFO=false'
@ -278,12 +277,10 @@ function cmake(gen, conf, builddir, options) @@ -278,12 +277,10 @@ function cmake(gen, conf, builddir, options)
.. ' -DLLVM_TOOL_LLVM_LINK_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_LTO_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_LTO2_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MCMARKUP_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MC_ASSEMBLE_FUZZER_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MC_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MC_DISASSEMBLE_FUZZER_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MCA_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MC_FUZZER_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MODEXTRACT_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_MT_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_NM_BUILD=false'
@ -291,7 +288,6 @@ function cmake(gen, conf, builddir, options) @@ -291,7 +288,6 @@ function cmake(gen, conf, builddir, options)
.. ' -DLLVM_TOOL_LLVM_OBJDUMP_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_OPT_FUZZER_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_OPT_REPORT_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_PDBDUMP_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_PDBUTIL_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_PROFDATA_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_PDBUTIL_BUILD=false'
@ -308,7 +304,6 @@ function cmake(gen, conf, builddir, options) @@ -308,7 +304,6 @@ function cmake(gen, conf, builddir, options)
.. ' -DLLVM_TOOL_LLVM_UNDNAME_BUILD=false'
.. ' -DLLVM_TOOL_LLVM_XRAY_BUILD=false'
.. ' -DLLVM_TOOL_LTO_BUILD=false'
.. ' -DLLVM_TOOL_MSBUILD_BUILD=false'
.. ' -DLLVM_TOOL_OBJ2YAML_BUILD=false'
.. ' -DLLVM_TOOL_OPT_BUILD=false'
.. ' -DLLVM_TOOL_OPT_VIEWER_BUILD=false'

7
src/CppParser/Bootstrap/Bootstrap.cs

@ -19,8 +19,7 @@ namespace CppSharp @@ -19,8 +19,7 @@ namespace CppSharp
{
var path = Path.Combine(directory.FullName, dir);
if (Directory.Exists(path) &&
Directory.Exists(Path.Combine(directory.FullName, "patches")))
if (Directory.Exists(path))
return path;
directory = directory.Parent;
@ -33,9 +32,7 @@ namespace CppSharp @@ -33,9 +32,7 @@ namespace CppSharp
{
driver.Options.GeneratorKind = GeneratorKind.CSharp;
driver.Options.DryRun = true;
driver.ParserOptions.SetupXcode();
driver.ParserOptions.MicrosoftMode = false;
driver.ParserOptions.TargetTriple = "i686-apple-darwin12.4.0";
driver.ParserOptions.Setup();
var module = driver.Options.AddModule("CppSharp");

6
src/CppParser/Bootstrap/premake5.lua

@ -7,7 +7,9 @@ project "CppSharp.Parser.Bootstrap" @@ -7,7 +7,9 @@ project "CppSharp.Parser.Bootstrap"
debugdir "."
files { "Bootstrap.cs", "*.lua" }
links { "CppSharp", "CppSharp.AST", "CppSharp.Generator", "System", "System.Core" }
links { "CppSharp", "CppSharp.AST", "CppSharp.Generator", "CppSharp.Parser" }
filter { "action:not netcore" }
links { "System", "System.Core" }
SetupParser()

2
src/Parser/premake5.lua

@ -11,7 +11,7 @@ local function GenerateBuildConfig() @@ -11,7 +11,7 @@ local function GenerateBuildConfig()
file:close()
end
if generate_build_config == true then
if generate_build_config == true and _ACTION then
GenerateBuildConfig()
end

Loading…
Cancel
Save