Skip to content

Commit d5b8d29

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

File tree

6 files changed

+98
-5
lines changed

6 files changed

+98
-5
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

+39-1
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ 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()
@@ -1389,6 +1389,21 @@ def get_dependencies(file, env, exts, headers, sources, others):
13891389
proj_template = proj_template.replace("%%DEFAULT_ITEMS%%", "\n ".join(all_items))
13901390
proj_template = proj_template.replace("%%PROPERTIES%%", "\n ".join(properties))
13911391

1392+
toolset = "v143"
1393+
if not env.msvc:
1394+
toolset = "CLang"
1395+
proj_template = proj_template.replace("%%PlatformToolset%%", toolset)
1396+
1397+
if not env.msvc:
1398+
proplist = [str(j) for j in env["CPPPATH"]]
1399+
proplist += [str(j) for j in env.get("VSHINT_INCLUDES", [])]
1400+
proplist += [str(j) for j in get_default_include_directories(env)]
1401+
proj_template = proj_template.replace("%%INCLUDES%%", ";".join(proplist))
1402+
1403+
proplist = [format_key_value(v) for v in list(env["CPPDEFINES"])]
1404+
proplist += [format_key_value(j) for j in env.get("VSHINT_DEFINES", [])]
1405+
proj_template = proj_template.replace("%%DEFINES%%", ";".join(proplist))
1406+
13921407
with open(f"{project_name}.vcxproj", "w", encoding="utf-8", newline="\r\n") as f:
13931408
f.write(proj_template)
13941409

@@ -1554,3 +1569,26 @@ def to_raw_cstring(value: Union[str, List[str]]) -> str:
15541569
split += [segment]
15551570

15561571
return " ".join(f'R"<!>({x.decode()})<!>"' for x in split)
1572+
1573+
1574+
def get_default_include_directories(env):
1575+
output = subprocess.Popen(
1576+
[env["CXX"], "-x", "c++", "-E", "-v", "-"],
1577+
stdin=subprocess.DEVNULL,
1578+
stdout=subprocess.DEVNULL,
1579+
stderr=subprocess.PIPE,
1580+
)
1581+
stderr = output.stderr.read().decode()
1582+
start = False
1583+
paths = []
1584+
for line in stderr.splitlines():
1585+
line = line.strip() # Remove leading/trailing spaces
1586+
if not start:
1587+
if line == "#include <...> search starts here:":
1588+
start = True
1589+
elif start:
1590+
if line == "End of search list.":
1591+
break
1592+
else:
1593+
paths.append(os.path.abspath(line))
1594+
return paths

misc/msvs/props.template

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<NMakeReBuildCommandLine>%%REBUILD%%</NMakeReBuildCommandLine>
66
<NMakeCleanCommandLine>%%CLEAN%%</NMakeCleanCommandLine>
77
<NMakeOutput Condition="'$(NMakeOutput)' == ''">%%OUTPUT%%</NMakeOutput>
8+
<LocalDebuggerCommand>$(NMakeOutput)</LocalDebuggerCommand>
89
<NMakePreprocessorDefinitions>%%DEFINES%%;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
910
<NMakeIncludeSearchPath>%%INCLUDES%%;$(NMakeIncludeSearchPath)</NMakeIncludeSearchPath>
1011
<NMakeForcedIncludes>$(NMakeForcedIncludes)</NMakeForcedIncludes>

misc/msvs/vcxproj.template

+30-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
<VCProjectUpgraderObjectName>NoUpgrade</VCProjectUpgraderObjectName>
1111
</PropertyGroup>
1212
%%PROPERTIES%%
13-
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
1413
<PropertyGroup Label="Configuration">
1514
<ConfigurationType>Makefile</ConfigurationType>
1615
<UseOfMfc>false</UseOfMfc>
17-
<PlatformToolset>v143</PlatformToolset>
16+
<PlatformToolset>%%PlatformToolset%%</PlatformToolset>
17+
<DefaultPlatformToolset>$(PlatformToolset)</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.Default.props" Condition=" '$(PlatformToolset)' != 'Clang' "/>
23+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" Condition=" '$(PlatformToolset)' != 'Clang' "/>
2324
<ImportGroup Label="ExtensionSettings">
2425
</ImportGroup>
2526
<ImportGroup Label="PropertySheets">
@@ -34,9 +35,34 @@
3435
<ItemGroup Condition="'$(IncludeListImported)'==''">
3536
%%DEFAULT_ITEMS%%
3637
</ItemGroup>
37-
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
38+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" Condition=" '$(PlatformToolset)' != 'Clang' "/>
3839
<ImportGroup Label="ExtensionTargets">
3940
</ImportGroup>
41+
42+
<Target Name="Build" Condition=" '$(PlatformToolset)' == 'Clang' ">
43+
<Exec Command="scons vsproj=yes dev_build=yes" Condition="'$(OS)' != 'Windows_NT'"/>
44+
<Exec Command="scons use_mingw=yes use_llvm=yes vsproj=yes dev_build=yes" Condition="'$(OS)' == 'Windows_NT'"/>
45+
</Target>
46+
<Target Name="Rebuild" Condition=" '$(PlatformToolset)' == 'Clang' ">
47+
<Exec Command="scons --no-cache vsproj=yes dev_build=yes" Condition="'$(OS)' != 'Windows_NT'"/>
48+
<Exec Command="scons --no-cache use_mingw=yes use_llvm=yes vsproj=yes dev_build=yes" Condition="'$(OS)' == 'Windows_NT'"/>
49+
</Target>
50+
<Target Name="Clean" Condition=" '$(PlatformToolset)' == 'Clang' ">
51+
<Exec Command="scons --clean vsproj=yes dev_build=yes" Condition="'$(OS)' != 'Windows_NT'"/>
52+
<Exec Command="scons --clean use_mingw=yes use_llvm=yes vsproj=yes dev_build=yes" Condition="'$(OS)' == 'Windows_NT'"/>
53+
</Target>
54+
55+
<ItemDefinitionGroup Condition=" '$(PlatformToolset)' == 'Clang' ">
56+
<ClCompile>
57+
<AdditionalIncludeDirectories>
58+
%%INCLUDES%%;
59+
%(AdditionalIncludeDirectories)
60+
</AdditionalIncludeDirectories>
61+
<PreprocessorDefinitions>
62+
%%DEFINES%%;%(PreprocessorDefinitions)
63+
</PreprocessorDefinitions>
64+
</ClCompile>
65+
</ItemDefinitionGroup>
4066
</Project>
4167
<!-- CHECKSUM
4268
%%HASH%%

platform/linuxbsd/msvs.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
# results are not needed on Mac and Linux
11+
def get_build_prefix(env):
12+
return []

platform/macos/msvs.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
# results are not needed on Mac and Linux
11+
def get_build_prefix(env):
12+
return []

0 commit comments

Comments
 (0)