Skip to content

Commit f27f3e3

Browse files
committed
Fix project generation logic for Rider to support all OS and all Cpp toolchains
1 parent 49cc57a commit f27f3e3

File tree

8 files changed

+88
-15
lines changed

8 files changed

+88
-15
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ indent_style = space
1515
[{*.{yml,yaml},.clang{-format,-tidy,d}}]
1616
indent_size = 2
1717
indent_style = space
18+
19+
[{*.props,*.vcxproj}]
20+
indent_style = space
21+
indent_size = 2

methods.py

+29-7
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,13 @@ def get_dependencies(file, env, exts, headers, sources, others):
12151215
activeItems.append(file)
12161216

12171217
if vs_configuration:
1218+
if not env.msvc:
1219+
# tell Rider at least not to use MSVC rules for the code analysis.
1220+
# theoretically env["CC"] can be accurately mapped to a PlatformToolset to have most accurate analysis rules
1221+
# like all *gcc are likely Linux, clang should be ClangOnLinux, ClangOnWindows, ClangOnMac
1222+
# I am not sure, if this may have recognizable impact, Unknown seem to work good for now
1223+
properties.append("<PlatformToolset>Unknown</PlatformToolset>")
1224+
12181225
vsconf = ""
12191226
for a in vs_configuration["arches"]:
12201227
if arch == a["architecture"]:
@@ -1234,12 +1241,11 @@ def get_dependencies(file, env, exts, headers, sources, others):
12341241
properties.append(
12351242
"<ActiveProjectItemList_%s>;%s;</ActiveProjectItemList_%s>" % (x, ";".join(itemlist[x]), x)
12361243
)
1237-
output = f"bin\\godot{env['PROGSUFFIX']}"
1244+
output = os.path.join("bin", f"godot{env['PROGSUFFIX']}")
12381245

12391246
with open("misc/msvs/props.template", "r", encoding="utf-8") as file:
12401247
props_template = file.read()
12411248

1242-
props_template = props_template.replace("%%VSCONF%%", vsconf)
12431249
props_template = props_template.replace("%%CONDITION%%", condition)
12441250
props_template = props_template.replace("%%PROPERTIES%%", "\n ".join(properties))
12451251
props_template = props_template.replace("%%EXTRA_ITEMS%%", "\n ".join(extraItems))
@@ -1252,6 +1258,7 @@ def get_dependencies(file, env, exts, headers, sources, others):
12521258

12531259
proplist = [str(j) for j in env["CPPPATH"]]
12541260
proplist += [str(j) for j in env.get("VSHINT_INCLUDES", [])]
1261+
proplist += [str(j) for j in get_default_include_paths(env)]
12551262
props_template = props_template.replace("%%INCLUDES%%", ";".join(proplist))
12561263

12571264
proplist = env["CCFLAGS"]
@@ -1287,17 +1294,17 @@ def get_dependencies(file, env, exts, headers, sources, others):
12871294

12881295
commands = "scons"
12891296
if len(common_build_prefix) == 0:
1290-
commands = "echo Starting SCons &amp;&amp; cmd /V /C " + commands
1297+
commands = "echo Starting SCons &amp;" + commands
12911298
else:
1292-
common_build_prefix[0] = "echo Starting SCons &amp;&amp; cmd /V /C " + common_build_prefix[0]
1299+
common_build_prefix[0] = "echo Starting SCons &amp;" + common_build_prefix[0]
12931300

1294-
cmd = " ^&amp; ".join(common_build_prefix + [" ".join([commands] + common_build_postfix)])
1301+
cmd = " ".join(common_build_prefix + [" ".join([commands] + common_build_postfix)])
12951302
props_template = props_template.replace("%%BUILD%%", cmd)
12961303

1297-
cmd = " ^&amp; ".join(common_build_prefix + [" ".join([commands] + cmd_rebuild)])
1304+
cmd = " ".join(common_build_prefix + [" ".join([commands] + cmd_rebuild)])
12981305
props_template = props_template.replace("%%REBUILD%%", cmd)
12991306

1300-
cmd = " ^&amp; ".join(common_build_prefix + [" ".join([commands] + cmd_clean)])
1307+
cmd = " ".join(common_build_prefix + [" ".join([commands] + cmd_clean)])
13011308
props_template = props_template.replace("%%CLEAN%%", cmd)
13021309

13031310
with open(
@@ -1586,3 +1593,18 @@ def to_raw_cstring(value: Union[str, List[str]]) -> str:
15861593
else:
15871594
# Wrap multiple segments in parenthesis to suppress `string-concatenation` warnings on clang.
15881595
return "({})".format(" ".join(f'R"<!>({segment.decode()})<!>"' for segment in split))
1596+
1597+
1598+
def get_default_include_paths(env):
1599+
if env.msvc:
1600+
return []
1601+
compiler = env.subst("$CXX")
1602+
target = os.path.join(env.Dir("#main").abspath, "main.cpp")
1603+
args = [compiler, target, "-x", "c++", "-v"]
1604+
ret = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
1605+
output = ret.stdout
1606+
match = re.search(r"#include <\.\.\.> search starts here:([\S\s]*)End of search list.", output)
1607+
if not match:
1608+
print_warning("Failed to find the include paths in the compiler output.")
1609+
return []
1610+
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+
<!-- Build/Rebuild/Clean targets for NMake are defined in MSVC, so we need to provide them, when using MSBuild without MSVC targets -->
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-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="17.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<PropertyGroup Condition="'$(GodotConfiguration)|$(GodotPlatform)'=='%%VSCONF%%'">
3+
<PropertyGroup Condition="%%CONDITION%%">
44
<NMakeBuildCommandLine>%%BUILD%%</NMakeBuildCommandLine>
55
<NMakeReBuildCommandLine>%%REBUILD%%</NMakeReBuildCommandLine>
66
<NMakeCleanCommandLine>%%CLEAN%%</NMakeCleanCommandLine>
@@ -18,6 +18,9 @@
1818
<ItemGroup Condition="%%CONDITION%%">
1919
%%EXTRA_ITEMS%%
2020
</ItemGroup>
21+
22+
<!-- Build/Rebuild/Clean targets for NMake are defined in MSVC, so we need to provide them, when using MSBuild without MSVC targets -->
23+
<Import Project="$(MSBuildProjectDirectory)/misc/msvs/nmake.substitution.props" Condition="%%CONDITION%% And !Exists('$(VCTargetsPath)\Microsoft.Cpp.targets')" />
2124
</Project>
2225
<!-- CHECKSUM
2326
%%HASH%%

misc/msvs/vcxproj.template

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@
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+
<PlatformToolset>v143</PlatformToolset> <!--Might be overridden in the platform specific import or Microsoft.Cpp.$(GodotPlatform).user.props -->
18+
<DefaultPlatformToolset Condition="'$(DefaultPlatformToolset)'==''"/> <!--Workaround until https://youtrack.jetbrains.com/issue/RIDER-123783 is resolved. -->
1819
<OutDir>$(SolutionDir)\bin\$(GodotPlatform)\$(GodotConfiguration)\</OutDir>
1920
<IntDir>obj\$(GodotPlatform)\$(GodotConfiguration)\</IntDir>
2021
<LayoutDir>$(OutDir)\Layout</LayoutDir>
2122
</PropertyGroup>
22-
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
23+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" Condition="Exists('$(VCTargetsPath)\Microsoft.Cpp.props') "/>
2324
<ImportGroup Label="ExtensionSettings">
2425
</ImportGroup>
2526
<ImportGroup Label="PropertySheets">
26-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(GodotPlatform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(GodotPlatform).user.props')" Label="LocalAppDataPlatform" />
27+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(GodotPlatform).user.props" Condition="Exists('$(UserRootDir)\Microsoft.Cpp.$(GodotPlatform).user.props')" Label="LocalAppDataPlatform" />
2728
</ImportGroup>
2829
<PropertyGroup Label="UserMacros" />
2930
<PropertyGroup>
@@ -34,7 +35,7 @@
3435
<ItemGroup Condition="'$(IncludeListImported)'==''">
3536
%%DEFAULT_ITEMS%%
3637
</ItemGroup>
37-
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
38+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" Condition="Exists('$(VCTargetsPath)\Microsoft.Cpp.targets') "/>
3839
<ImportGroup Label="ExtensionTargets">
3940
</ImportGroup>
4041
</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)