Skip to content

Commit 8cf6e3f

Browse files
authored
Allow passing a -target-framework option to build.sh (#1718)
Closes #1717.
1 parent 5715df5 commit 8cf6e3f

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

build/Helpers.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ newoption {
4343
description = "Only generate configuration file",
4444
}
4545

46+
newoption {
47+
trigger = "target-framework",
48+
description = ".NET target framework version",
49+
}
50+
4651
rootdir = path.getabsolute("../")
4752
srcdir = path.join(rootdir, "src");
4853
incdir = path.join(rootdir, "include");
@@ -61,7 +66,17 @@ msvc_cpp_defines = { }
6166
default_gcc_version = "9.0.0"
6267
generate_build_config = true
6368
premake.path = premake.path .. ";" .. path.join(builddir, "modules")
64-
targetframework = "net6.0"
69+
70+
function string.isempty(s)
71+
return s == nil or s == ''
72+
end
73+
74+
local function target_framework()
75+
local value = _OPTIONS["target-framework"]
76+
return string.isempty(value) and "net6.0" or value
77+
end
78+
79+
targetframework = target_framework()
6580

6681
function string.starts(str, start)
6782
if str == nil then return end

build/build.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ vs=vs2019
66
configuration=Release
77
build_only=false
88
ci=false
9+
target_framework=
910
verbosity=minimal
1011
rootdir="$builddir/.."
1112
bindir="$rootdir/bin"
@@ -46,18 +47,18 @@ build()
4647

4748
generate_config()
4849
{
49-
"$builddir/premake.sh" --file="$builddir/premake5.lua" $vs --os=$os --arch=$platform --configuration=$configuration --config_only
50+
"$builddir/premake.sh" --file="$builddir/premake5.lua" $vs --os=$os --arch=$platform --configuration=$configuration --target-framework=$target_framework --config_only
5051
}
5152

5253
generate()
5354
{
5455
download_llvm
5556

5657
if [ "$os" = "linux" ] || [ "$os" = "macosx" ]; then
57-
"$builddir/premake.sh" --file="$builddir/premake5.lua" gmake2 --os=$os --arch=$platform --configuration=$configuration "$@"
58+
"$builddir/premake.sh" --file="$builddir/premake5.lua" gmake2 --os=$os --arch=$platform --configuration=$configuration --target-framework=$target_framework "$@"
5859
fi
5960

60-
"$builddir/premake.sh" --file="$builddir/premake5.lua" $vs --os=$os --arch=$platform --configuration=$configuration
61+
"$builddir/premake.sh" --file="$builddir/premake5.lua" $vs --os=$os --arch=$platform --configuration=$configuration --target-framework=$target_framework
6162
}
6263

6364
restore()
@@ -194,6 +195,11 @@ while [[ $# > 0 ]]; do
194195
os=$2
195196
shift
196197
;;
198+
-target-framework)
199+
target_framework=$2
200+
echo $target_framework
201+
shift
202+
;;
197203
-ci)
198204
ci=true
199205
export CI=true

docs/GettingStarted.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ The following steps should be called from the VS developer command prompt.
4444
<sh> build.sh generate -configuration Release -platform x64
4545
```
4646

47+
> :information_source: You can use the `-target-framework` option to target any valid .NET target framework.
48+
4749
2. Compile the VS projects
4850

4951
You can open `CppSharp.sln` and hit F5 or compile via the command line:
@@ -82,6 +84,8 @@ When opening the solution for the first time on a more recent version than Visua
8284
./build.sh generate -configuration Release -platform x64
8385
```
8486
87+
> :information_source: You can use the `-target-framework` option to target any valid .NET target framework.
88+
8589
2. Compile the csproj files and makefiles
8690
8791
```

src/CLI/CppSharp.CLI.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>net6.0</TargetFramework>
54
</PropertyGroup>
65

76
<ItemGroup>

0 commit comments

Comments
 (0)