Skip to content

Commit 7c72b2e

Browse files
committed
Fix project generation logic for Rider to support any OS without MSVC toolchain
1 parent 0e3dbba commit 7c72b2e

File tree

8 files changed

+81
-12
lines changed

8 files changed

+81
-12
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ indent_style = space
1818

1919
[*.svg]
2020
insert_final_newline = false
21+
22+
[{*.props,*.vcxproj}]
23+
indent_style = space
24+
indent_size = 2

methods.py

+24-6
Original file line numberDiff line numberDiff line change
@@ -1217,11 +1217,16 @@ def get_dependencies(file, env, exts, headers, sources, others):
12171217
properties.append(
12181218
"<ActiveProjectItemList_%s>;%s;</ActiveProjectItemList_%s>" % (x, ";".join(itemlist[x]), x)
12191219
)
1220-
output = f"bin\\godot{env['PROGSUFFIX']}"
1220+
output = os.path.join("bin", f"godot{env['PROGSUFFIX']}")
12211221

12221222
with open("misc/msvs/props.template", "r", encoding="utf-8") as file:
12231223
props_template = file.read()
12241224

1225+
toolset = "v143"
1226+
if not env.msvc:
1227+
toolset = "CLang"
1228+
props_template = props_template.replace("%%PlatformToolset%%", toolset)
1229+
12251230
props_template = props_template.replace("%%VSCONF%%", vsconf)
12261231
props_template = props_template.replace("%%CONDITION%%", condition)
12271232
props_template = props_template.replace("%%PROPERTIES%%", "\n ".join(properties))
@@ -1235,6 +1240,7 @@ def get_dependencies(file, env, exts, headers, sources, others):
12351240

12361241
proplist = [str(j) for j in env["CPPPATH"]]
12371242
proplist += [str(j) for j in env.get("VSHINT_INCLUDES", [])]
1243+
proplist += [str(j) for j in get_default_include_paths(env)]
12381244
props_template = props_template.replace("%%INCLUDES%%", ";".join(proplist))
12391245

12401246
proplist = env["CCFLAGS"]
@@ -1270,17 +1276,17 @@ def get_dependencies(file, env, exts, headers, sources, others):
12701276

12711277
commands = "scons"
12721278
if len(common_build_prefix) == 0:
1273-
commands = "echo Starting SCons &amp;&amp; cmd /V /C " + commands
1279+
commands = "echo Starting SCons &amp;" + commands
12741280
else:
1275-
common_build_prefix[0] = "echo Starting SCons &amp;&amp; cmd /V /C " + common_build_prefix[0]
1281+
common_build_prefix[0] = "echo Starting SCons &amp;" + common_build_prefix[0]
12761282

1277-
cmd = " ^&amp; ".join(common_build_prefix + [" ".join([commands] + common_build_postfix)])
1283+
cmd = " ".join(common_build_prefix + [" ".join([commands] + common_build_postfix)])
12781284
props_template = props_template.replace("%%BUILD%%", cmd)
12791285

1280-
cmd = " ^&amp; ".join(common_build_prefix + [" ".join([commands] + cmd_rebuild)])
1286+
cmd = " ".join(common_build_prefix + [" ".join([commands] + cmd_rebuild)])
12811287
props_template = props_template.replace("%%REBUILD%%", cmd)
12821288

1283-
cmd = " ^&amp; ".join(common_build_prefix + [" ".join([commands] + cmd_clean)])
1289+
cmd = " ".join(common_build_prefix + [" ".join([commands] + cmd_clean)])
12841290
props_template = props_template.replace("%%CLEAN%%", cmd)
12851291

12861292
with open(
@@ -1554,3 +1560,15 @@ def to_raw_cstring(value: Union[str, List[str]]) -> str:
15541560
split += [segment]
15551561

15561562
return " ".join(f'R"<!>({x.decode()})<!>"' for x in split)
1563+
1564+
1565+
def get_default_include_paths(env):
1566+
compiler = env.subst("$CXX")
1567+
target = os.path.join(env.Dir("#main").abspath, "main.cpp")
1568+
args = [compiler, target, "-x", "c++", "-v"]
1569+
ret = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
1570+
output = ret.stdout
1571+
match = re.search(r"#include <\.\.\.> search starts here:([\S\s]*)End of search list.", output)
1572+
if not match:
1573+
return [] # msvc case
1574+
return [x.strip() for x in match[1].strip().splitlines()]

misc/msvs/nmake.substitution.props

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<!-- NMake is Windows only, so we need to wrap everything useful for non-windows msbuild -->
4+
<PropertyGroup>
5+
<LocalDebuggerCommand Condition="'$(LocalDebuggerCommand)' == ''">$(NMakeOutput)</LocalDebuggerCommand>
6+
</PropertyGroup>
7+
8+
<Target Name="Build">
9+
<Exec Command="$(NMakeBuildCommandLine)"/>
10+
</Target>
11+
<Target Name="Rebuild">
12+
<Exec Command="$(NMakeReBuildCommandLine)"/>
13+
</Target>
14+
<Target Name="Clean">
15+
<Exec Command="$(NMakeCleanCommandLine)"/>
16+
</Target>
17+
</Project>

misc/msvs/props.template

+4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111
<NMakeAssemblySearchPath>$(NMakeAssemblySearchPath)</NMakeAssemblySearchPath>
1212
<NMakeForcedUsingAssemblies>$(NMakeForcedUsingAssemblies)</NMakeForcedUsingAssemblies>
1313
<AdditionalOptions>%%OPTIONS%% $(AdditionalOptions)</AdditionalOptions>
14+
<PlatformToolset>%%PlatformToolset%%</PlatformToolset>
1415
</PropertyGroup>
1516
<PropertyGroup Condition="%%CONDITION%%">
1617
%%PROPERTIES%%
1718
</PropertyGroup>
1819
<ItemGroup Condition="%%CONDITION%%">
1920
%%EXTRA_ITEMS%%
2021
</ItemGroup>
22+
23+
<!-- NMake is Windows only, so we need to wrap everything useful for non-windows msbuild -->
24+
<Import Project="$(MSBuildProjectDirectory)/misc/msvs/nmake.substitution.props" Condition="'$(GodotConfiguration)|$(GodotPlatform)'=='%%VSCONF%%' And '$(OS)' != 'Windows_NT'" />
2125
</Project>
2226
<!-- CHECKSUM
2327
%%HASH%%

misc/msvs/vcxproj.template

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
<VCProjectUpgraderObjectName>NoUpgrade</VCProjectUpgraderObjectName>
1111
</PropertyGroup>
1212
%%PROPERTIES%%
13-
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
13+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" Condition=" exists('$(VCTargetsPath)\Microsoft.Cpp.Default.props') "/>
1414
<PropertyGroup Label="Configuration">
1515
<ConfigurationType>Makefile</ConfigurationType>
1616
<UseOfMfc>false</UseOfMfc>
17-
<PlatformToolset>v143</PlatformToolset>
17+
<DefaultPlatformToolset Condition="'$(DefaultPlatformToolset)'==''"/>
1818
<OutDir>$(SolutionDir)\bin\$(GodotPlatform)\$(GodotConfiguration)\</OutDir>
1919
<IntDir>obj\$(GodotPlatform)\$(GodotConfiguration)\</IntDir>
2020
<LayoutDir>$(OutDir)\Layout</LayoutDir>
2121
</PropertyGroup>
22-
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
22+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" Condition=" exists('$(VCTargetsPath)\Microsoft.Cpp.Default.props') "/>
2323
<ImportGroup Label="ExtensionSettings">
2424
</ImportGroup>
2525
<ImportGroup Label="PropertySheets">
@@ -34,7 +34,7 @@
3434
<ItemGroup Condition="'$(IncludeListImported)'==''">
3535
%%DEFAULT_ITEMS%%
3636
</ItemGroup>
37-
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
37+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" Condition=" exists('$(VCTargetsPath)\Microsoft.Cpp.Default.props') "/>
3838
<ImportGroup Label="ExtensionTargets">
3939
</ImportGroup>
4040
</Project>

platform/linuxbsd/msvs.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Tuples with the name of the arch
2+
def get_platforms():
3+
return [("arm64", "arm64"), ("x86_64", "x86_64")]
4+
5+
6+
def get_configurations():
7+
return ["editor", "template_debug", "template_release"]
8+
9+
10+
def get_build_prefix(env):
11+
return []

platform/macos/msvs.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Tuples with the name of the arch
2+
def get_platforms():
3+
return [("arm64", "arm64"), ("x86_64", "x86_64")]
4+
5+
6+
def get_configurations():
7+
return ["editor", "template_debug", "template_release"]
8+
9+
10+
def get_build_prefix(env):
11+
return []

platform/windows/msvs.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ def get_configurations():
1212

1313

1414
def get_build_prefix(env):
15+
if not env.msvc:
16+
return []
1517
batch_file = methods.find_visual_c_batch_file(env)
1618
return [
19+
"cmd /V /C",
1720
"set &quot;plat=$(PlatformTarget)&quot;",
18-
"(if &quot;$(PlatformTarget)&quot;==&quot;x64&quot; (set &quot;plat=x86_amd64&quot;))",
19-
f"call &quot;{batch_file}&quot; !plat!",
21+
"^&amp; (if &quot;$(PlatformTarget)&quot;==&quot;x64&quot; (set &quot;plat=x86_amd64&quot;))",
22+
f"^&amp; call &quot;{batch_file}&quot; !plat!",
23+
"^&amp;",
2024
]

0 commit comments

Comments
 (0)