Skip to content

Commit 1926e69

Browse files
committed
Only use premake for native projects and improve c# projects.
1 parent 0b270df commit 1926e69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+369
-259
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ src/generator/generator
2626
*.filters
2727
*.sln
2828
*.metagen
29-
*.csproj
3029
*.ilk
3130
*.manifest
3231
*.tmp
@@ -43,6 +42,7 @@ src/generator/generator
4342
/build/vs20*
4443
/build/gmake
4544
/build/headers
45+
/build/config.props
4646
/build/premake/premake5*
4747
/build/gen
4848
/deps/llvm

Directory.Build.props

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
11
<Project>
2+
<Import Project="build/config.props" />
3+
24
<PropertyGroup>
35
<RootDir>$(MSBuildThisFileDirectory)</RootDir>
46
<Platforms>x86;x64</Platforms>
57
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
6-
<BaseIntermediateOutputPath>$(RootDir)build\obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
7-
<TargetDir Condition="$(Configuration) != ''">$(RootDir)bin\$(Configuration)_$(Platform)</TargetDir>
8+
<BuildDir>$(RootDir)build\</BuildDir>
9+
<ObjDir>$(BuildDir)obj\</ObjDir>
10+
<GenDir>$(BuildDir)gen\</GenDir>
11+
<SrcDir>$(RootDir)src\</SrcDir>
12+
<BaseIntermediateOutputPath>$(ObjDir)$(MSBuildProjectName)\</BaseIntermediateOutputPath>
13+
<BaseOutputPath>$(RootDir)bin\</BaseOutputPath>
14+
<OutputPath>$(BaseOutputPath)$(Configuration)_$(PlatformTarget)\</OutputPath>
15+
<ActionDir>$(BuildDir)$(PremakeAction)\</ActionDir>
16+
<NativeProjectsDir>$(ActionDir)projects\</NativeProjectsDir>
17+
<TargetDir>$(OutputPath)</TargetDir>
818
<LangVersion>7.3</LangVersion>
19+
<WarningLevel>4</WarningLevel>
20+
<DotNetCmd>dotnet</DotNetCmd>
21+
<GeneratorFileExtension>dll</GeneratorFileExtension>
22+
<DotNetCmd Condition="'$(PlatformTarget)' == 'x86' AND Exists('$(MSBuildProgramFiles32)\dotnet\dotnet.exe')">"$(MSBuildProgramFiles32)\dotnet\dotnet.exe"</DotNetCmd>
23+
<DotNetCmd Condition="'$(PlatformTarget)' == 'x64' AND Exists('$(ProgramW6432)\dotnet\dotnet.exe')">"$(ProgramW6432)\dotnet\dotnet.exe"</DotNetCmd>
24+
</PropertyGroup>
25+
26+
<PropertyGroup Condition="'$(CPPSHARP_RELEASE)' != 'true'">
27+
<DebugSymbols>true</DebugSymbols>
28+
<DebugType>full</DebugType>
29+
<Optimize>false</Optimize>
30+
</PropertyGroup>
31+
32+
<PropertyGroup Condition="'$(DotNetCmd)' == 'dotnet' AND $(IsWindows)">
33+
<GeneratorFileExtension>exe</GeneratorFileExtension>
34+
<DotNetCmd></DotNetCmd>
935
</PropertyGroup>
1036
</Project>

build/Helpers.lua

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ msvc_cpp_defines = { }
5656
default_gcc_version = "9.0.0"
5757
generate_build_config = true
5858
premake.path = premake.path .. ";" .. path.join(builddir, "modules")
59+
targetframework = "netcoreapp3.1"
5960

6061
function string.starts(str, start)
6162
if str == nil then return end
@@ -73,6 +74,10 @@ end
7374
function SetupNativeProject()
7475
location (path.join(actionbuilddir, "projects"))
7576
files { "*.lua" }
77+
78+
if os.getenv("CPPSHARP_RELEASE") == "true" then
79+
symbols "off"
80+
end
7681

7782
filter { "configurations:Debug" }
7883
defines { "DEBUG" }
@@ -118,11 +123,17 @@ function SetupNativeProject()
118123
end
119124

120125
function SetupManagedProject()
126+
kind "SharedLib"
121127
language "C#"
122128
location "."
123129
filter {}
124130
end
125131

132+
function SetupExternalManagedProject(name)
133+
externalproject (name)
134+
SetupManagedProject()
135+
end
136+
126137
function IncludeDir(dir)
127138
local deps = os.matchdirs(dir .. "/*")
128139

@@ -230,3 +241,30 @@ function AddPlatformSpecificFiles(folder, filename)
230241
print "Unknown architecture"
231242
end
232243
end
244+
245+
function WriteConfigForMSBuild()
246+
local file = io.open("config.props", "w+")
247+
function writeProperty(name, value)
248+
file:write(" <" .. name .. ">" .. (value ~= nil and value or "") .. "</" .. name .. ">\n")
249+
end
250+
function writeBooleanProperty(name, value)
251+
writeProperty(name, value and "true" or "false")
252+
end
253+
254+
file:write("<!-- GENERATED FILE -->\n")
255+
file:write("<Project>\n")
256+
file:write(" <PropertyGroup>\n")
257+
writeProperty("PlatformTarget", target_architecture())
258+
writeProperty("TargetFramework", targetframework)
259+
writeProperty("Configuration", _OPTIONS["configuration"])
260+
writeBooleanProperty("IsWindows", os.istarget("windows"))
261+
writeBooleanProperty("IsLinux", os.istarget("linux"))
262+
writeBooleanProperty("IsMacOSX", os.istarget("macosx"))
263+
writeBooleanProperty("CI", os.getenv("CI") == "true")
264+
writeBooleanProperty("GenerateBuildConfig", generate_build_config == true)
265+
writeBooleanProperty("UseCXX11ABI", UseCxx11ABI())
266+
writeProperty("PremakeAction", _ACTION)
267+
file:write(" </PropertyGroup>\n")
268+
file:write("</Project>")
269+
file:close()
270+
end

build/Tests.lua

Lines changed: 13 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,15 @@ function SetupManagedTestProject()
4040
files { "*.lua" }
4141
end
4242

43-
function SetupTestGeneratorProject(name, depends)
44-
if not EnabledManagedProjects() then
45-
return
46-
end
47-
project(name .. ".Gen")
48-
SetupManagedTestProject()
49-
kind "ConsoleApp"
50-
enabledefaultnoneitems "false"
51-
52-
files { name .. ".cs" }
53-
dependson { name .. ".Native" }
54-
links { "CppSharp.Generator.Tests" }
55-
56-
if depends ~= nil then
57-
links { depends .. ".Gen" }
58-
end
59-
60-
local command = os.ishost("windows") and "type nul >" or "touch"
61-
postbuildcommands { command .. " " .. SafePath(path.join(objsdir, name .. ".Native", "timestamp.cs")) }
62-
postbuildcommands { command .. " " .. SafePath(path.join(objsdir, name .. ".Native", "timestamp.cpp")) }
43+
function SetupExternalManagedTestProject(name)
44+
externalproject (name)
45+
SetupManagedTestProject()
6346
end
6447

65-
function SetupTestGeneratorBuildEvent(name)
66-
local cmd = os.ishost("windows") and "" or "dotnet "
67-
local ext = os.ishost("windows") and "exe" or "dll"
68-
prebuildcommands { cmd .. SafePath(path.join("%{cfg.buildtarget.directory}", name .. ".Gen." .. ext)) }
48+
function SetupTestGeneratorProject(name, depends)
49+
if EnabledManagedProjects() then
50+
SetupExternalManagedTestProject(name .. ".Gen")
51+
end
6952
end
7053

7154
function SetupTestNativeProject(name, depends)
@@ -86,10 +69,6 @@ function SetupTestNativeProject(name, depends)
8669
if depends ~= nil then
8770
links { depends .. ".Native" }
8871
end
89-
90-
local command = os.ishost("windows") and "type nul >" or "touch"
91-
postbuildcommands { command .. " " .. SafePath(path.join(objsdir, name .. ".Native", "timestamp.cs")) }
92-
postbuildcommands { command .. " " .. SafePath(path.join(objsdir, name .. ".Native", "timestamp.cpp")) }
9372
end
9473

9574
function SetupTestProjectsCSharp(name, depends, extraFiles, suffix)
@@ -103,35 +82,9 @@ function SetupTestProjectsCSharp(name, depends, extraFiles, suffix)
10382
nm = name
10483
str = "Std"
10584
end
106-
project(name .. ".CSharp")
107-
SetupManagedTestProject()
108-
109-
dependson { name .. ".Gen", name .. ".Native", "CppSharp.Generator" }
110-
SetupTestGeneratorBuildEvent(name)
111-
enabledefaultnoneitems "false"
112-
113-
files
114-
{
115-
path.join(gendir, name, nm .. ".cs"),
116-
path.join(gendir, name, str .. ".cs"),
117-
path.join(objsdir, name .. ".Native", "timestamp.cs")
118-
}
119-
120-
links { "CppSharp.Runtime" }
121-
122-
if depends ~= nil then
123-
links { depends .. ".CSharp" }
124-
end
125-
126-
project(name .. ".Tests.CSharp")
127-
SetupManagedTestProject()
128-
129-
enabledefaultnoneitems "false"
130-
files { name .. ".Tests.cs" }
131-
132-
links { name .. ".CSharp", "CppSharp.Generator.Tests", "CppSharp.Runtime" }
133-
nuget { "Microsoft.NET.Test.Sdk:16.8.0" }
134-
dependson { name .. ".Native" }
85+
86+
SetupExternalManagedTestProject(name .. ".CSharp")
87+
SetupExternalManagedTestProject(name .. ".Tests.CSharp")
13588
end
13689

13790
function SetupTestProjectsCLI(name, extraFiles, suffix)
@@ -142,14 +95,11 @@ function SetupTestProjectsCLI(name, extraFiles, suffix)
14295
project(name .. ".CLI")
14396
SetupNativeProject()
14497

145-
enabledefaultcompileitems "false"
146-
enabledefaultnoneitems "false"
14798
kind "SharedLib"
14899
language "C++"
149100
clr "NetCore"
150101

151-
dependson { name .. ".Gen", name .. ".Native", "CppSharp.Generator" }
152-
SetupTestGeneratorBuildEvent(name)
102+
dependson { name .. ".Gen" }
153103

154104
if (suffix ~= nil) then
155105
nm = name .. suffix
@@ -174,16 +124,9 @@ function SetupTestProjectsCLI(name, extraFiles, suffix)
174124

175125
includedirs { path.join(testsdir, name), incdir }
176126
links { name .. ".Native" }
177-
files { path.join(objsdir, name .. ".Native", "timestamp.cpp") }
178-
179-
project(name .. ".Tests.CLI")
180-
SetupManagedTestProject()
181-
enabledefaultnoneitems "false"
182-
files { name .. ".Tests.cs" }
127+
files { path.join(objsdir, name .. ".Native") }
183128

184-
links { name .. ".CLI", "CppSharp.Generator.Tests" }
185-
dependson { name .. ".Native" }
186-
nuget { "Microsoft.NET.Test.Sdk:16.8.0" }
129+
SetupExternalManagedTestProject(name .. ".Tests.CLI")
187130
end
188131

189132
function IncludeExamples()

build/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ find_msbuild()
140140
if [ -x "$(command -v MSBuild.exe)" ]; then
141141
msbuild="MSBuild.exe"
142142
else
143-
msbuild="msbuild"
143+
msbuild="dotnet msbuild"
144144
fi
145145
}
146146

build/premake/premake.extensions.lua

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,16 @@ premake.api.register {
44
kind = "list:string",
55
}
66

7-
premake.api.register {
8-
name = "removecompilefiles",
9-
scope = "project",
10-
kind = "list:string",
11-
}
12-
13-
premake.api.register {
14-
name = "enabledefaultnoneitems",
15-
scope = "project",
16-
kind = "boolean",
17-
}
18-
19-
premake.override(premake.vstudio.dotnetbase.netcore, "enableDefaultCompileItems", function(base, cfg)
20-
base(cfg);
21-
22-
if cfg.enabledefaultnoneitems ~= nil then
23-
premake.w('<EnableDefaultNoneItems>%s</EnableDefaultNoneItems>', iif(cfg.enabledefaultnoneitems, "true", "false"))
24-
end
25-
end)
26-
27-
premake.override(premake.vstudio.dotnetbase, "files", function(base, prj)
28-
base(prj);
29-
30-
if prj.removecompilefiles ~= nil then
31-
for _, file in ipairs(prj.removecompilefiles) do
32-
premake.w("<Compile Remove=\"%s\" />", file)
33-
end
34-
end
35-
end)
36-
377
-- https://github.com/premake/premake-core/issues/1061#issuecomment-441417853
388
premake.override(premake.vstudio.sln2005, "projects", function(base, wks)
399
if wks.workspacefiles and #wks.workspacefiles > 0 then
4010
premake.push('Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{' .. os.uuid("Solution Items:"..wks.name) .. '}"')
4111
premake.push("ProjectSection(SolutionItems) = preProject")
42-
for _, file in ipairs(wks.workspacefiles) do
43-
file = path.rebase(file, ".", wks.location)
44-
premake.w(file.." = "..file)
12+
for _, pattern in ipairs(wks.workspacefiles) do
13+
local matches = os.matchfiles(pattern)
14+
for _, file in ipairs(matches) do
15+
premake.w(file.." = "..file)
16+
end
4517
end
4618
premake.pop("EndProjectSection")
4719
premake.pop("EndProject")

build/premake/premake.fixes.lua

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,3 @@ premake.override(premake.vstudio.vc2010, "targetFramework", function(oldfn, prj)
1010
oldfn(prj)
1111
end
1212
end)
13-
14-
-- https://github.com/premake/premake-core/issues/1549
15-
premake.override(premake.vstudio.cs2005.elements, "projectProperties", function(base, cfg)
16-
local calls = base(cfg);
17-
table.insert(calls, function(cfg)
18-
if cfg.clr == "Unsafe" then
19-
premake.w('<AllowUnsafeBlocks>true</AllowUnsafeBlocks>')
20-
end
21-
end)
22-
return calls;
23-
end)

build/premake5.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ include "Helpers.lua"
88
include "LLVM.lua"
99

1010
workspace "CppSharp"
11-
1211
configurations { _OPTIONS["configuration"] }
1312
platforms { target_architecture() }
14-
dotnetframework "netcoreapp3.1"
13+
dotnetframework (targetframework)
1514
enabledefaultcompileitems "true"
1615
characterset "Unicode"
1716
symbols "On"
@@ -35,6 +34,11 @@ workspace "CppSharp"
3534
end
3635
end
3736

37+
workspacefiles(path.join(builddir, "premake5.lua"))
38+
workspacefiles(path.join(builddir, "*.sh"))
39+
workspacefiles(path.join(rootdir, "tests/Test*.props"))
40+
WriteConfigForMSBuild()
41+
3842
group "Libraries"
3943
if EnableNativeProjects() then
4044
include (srcdir .. "/CppParser")

src/AST/CppSharp.AST.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netstandard2.1</TargetFramework>
4+
<PlatformTarget>AnyCPU</PlatformTarget>
5+
</PropertyGroup>
6+
</Project>

src/AST/premake5.lua

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
project "CppSharp.AST"
2-
3-
kind "SharedLib"
4-
language "C#"
5-
6-
SetupManagedProject()
1+
SetupExternalManagedProject("CppSharp.AST")

src/CLI/CppSharp.CLI.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
</PropertyGroup>
5+
6+
<ItemGroup>
7+
<ProjectReference Include="..\Generator\CppSharp.Generator.csproj" />
8+
</ItemGroup>
9+
</Project>

src/CLI/premake5.lua

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
project "CppSharp.CLI"
2-
3-
SetupManagedProject()
4-
5-
kind "ConsoleApp"
6-
language "C#"
7-
8-
links { "CppSharp.Generator" }
1+
SetupExternalManagedProject("CppSharp.CLI")

src/Core/CppSharp.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netstandard2.1</TargetFramework>
4+
<PlatformTarget>AnyCPU</PlatformTarget>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" PrivateAssets="All" />
9+
<PackageReference Include="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="2.3.2262-g94fae01e" PrivateAssets="All" />
10+
</ItemGroup>
11+
</Project>

0 commit comments

Comments
 (0)