Skip to content

Commit

Permalink
Fix project generation logic for Rider to support any OS without MSVC…
Browse files Browse the repository at this point in the history
… toolchain
  • Loading branch information
van800 committed Mar 4, 2025
1 parent 0e3dbba commit 128509b
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ indent_style = space

[*.svg]
insert_final_newline = false

[{*.props,*.vcxproj}]
indent_style = space
indent_size = 2
25 changes: 19 additions & 6 deletions methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ def get_dependencies(file, env, exts, headers, sources, others):
properties.append(
"<ActiveProjectItemList_%s>;%s;</ActiveProjectItemList_%s>" % (x, ";".join(itemlist[x]), x)
)
output = f"bin\\godot{env['PROGSUFFIX']}"
output = os.path.join("bin", f"godot{env['PROGSUFFIX']}")

with open("misc/msvs/props.template", "r", encoding="utf-8") as file:
props_template = file.read()
Expand All @@ -1235,6 +1235,7 @@ def get_dependencies(file, env, exts, headers, sources, others):

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

proplist = env["CCFLAGS"]
Expand Down Expand Up @@ -1270,17 +1271,17 @@ def get_dependencies(file, env, exts, headers, sources, others):

commands = "scons"
if len(common_build_prefix) == 0:
commands = "echo Starting SCons &amp;&amp; cmd /V /C " + commands
commands = "echo Starting SCons &amp;" + commands
else:
common_build_prefix[0] = "echo Starting SCons &amp;&amp; cmd /V /C " + common_build_prefix[0]
common_build_prefix[0] = "echo Starting SCons &amp;" + common_build_prefix[0]

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

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

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

with open(
Expand Down Expand Up @@ -1554,3 +1555,15 @@ def to_raw_cstring(value: Union[str, List[str]]) -> str:
split += [segment]

return " ".join(f'R"<!>({x.decode()})<!>"' for x in split)


def get_default_include_paths(env):
compiler = env.subst("$CXX")
target = os.path.join(env.Dir("#main").abspath, "main.cpp")
args = [compiler, target, "-x", "c++", "-v"]
ret = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
output = ret.stdout
match = re.search(r"#include <\.\.\.> search starts here:([\S\s]*)End of search list.", output)
if not match:
return [] # msvc case
return [x.strip() for x in match[1].strip().splitlines()]
24 changes: 24 additions & 0 deletions misc/msvs/props.template
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@
<ItemGroup Condition="%%CONDITION%%">
%%EXTRA_ITEMS%%
</ItemGroup>

<!-- Required for Rider below this line-->
<PropertyGroup Condition=" '$(PlatformToolset)' == 'Clang' ">
<LocalDebuggerCommand Condition="'$(LocalDebuggerCommand)' == ''">$(NMakeOutput)</LocalDebuggerCommand>
<DefaultPlatformToolset>$(PlatformToolset)</DefaultPlatformToolset>
</PropertyGroup>

<Target Name="Build" Condition=" '$(PlatformToolset)' == 'Clang' ">
<Exec Command="$(NMakeBuildCommandLine)"/>
</Target>
<Target Name="Rebuild" Condition=" '$(PlatformToolset)' == 'Clang' ">
<Exec Command="$(NMakeReBuildCommandLine)"/>
</Target>
<Target Name="Clean" Condition=" '$(PlatformToolset)' == 'Clang' ">
<Exec Command="$(NMakeCleanCommandLine)"/>
</Target>

<ItemDefinitionGroup Condition=" '$(PlatformToolset)' == 'Clang' ">
<ClCompile>
<PreprocessorDefinitions>
$(NMakePreprocessorDefinitions)
</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
</Project>
<!-- CHECKSUM
%%HASH%%
Expand Down
9 changes: 5 additions & 4 deletions misc/msvs/vcxproj.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
<VCProjectUpgraderObjectName>NoUpgrade</VCProjectUpgraderObjectName>
</PropertyGroup>
%%PROPERTIES%%
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" Condition=" exists('$(VCTargetsPath)\Microsoft.Cpp.Default.props') "/>
<PropertyGroup Label="Configuration">
<ConfigurationType>Makefile</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset Condition="exists('$(VCTargetsPath)\Microsoft.Cpp.Default.props')">v143</PlatformToolset>
<PlatformToolset Condition="!exists('$(VCTargetsPath)\Microsoft.Cpp.Default.props')">CLang</PlatformToolset>
<OutDir>$(SolutionDir)\bin\$(GodotPlatform)\$(GodotConfiguration)\</OutDir>
<IntDir>obj\$(GodotPlatform)\$(GodotConfiguration)\</IntDir>
<LayoutDir>$(OutDir)\Layout</LayoutDir>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" Condition=" exists('$(VCTargetsPath)\Microsoft.Cpp.props') "/>
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
Expand All @@ -34,7 +35,7 @@
<ItemGroup Condition="'$(IncludeListImported)'==''">
%%DEFAULT_ITEMS%%
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" Condition=" exists('$(VCTargetsPath)\Microsoft.Cpp.targets') "/>
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Expand Down
11 changes: 11 additions & 0 deletions platform/linuxbsd/msvs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Tuples with the name of the arch
def get_platforms():
return [("arm64", "arm64"), ("x86_64", "x86_64")]


def get_configurations():
return ["editor", "template_debug", "template_release"]


def get_build_prefix(env):
return []
11 changes: 11 additions & 0 deletions platform/macos/msvs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Tuples with the name of the arch
def get_platforms():
return [("arm64", "arm64"), ("x86_64", "x86_64")]


def get_configurations():
return ["editor", "template_debug", "template_release"]


def get_build_prefix(env):
return []
8 changes: 6 additions & 2 deletions platform/windows/msvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ def get_configurations():


def get_build_prefix(env):
if not env.msvc:
return []
batch_file = methods.find_visual_c_batch_file(env)
return [
"cmd /V /C",
"set &quot;plat=$(PlatformTarget)&quot;",
"(if &quot;$(PlatformTarget)&quot;==&quot;x64&quot; (set &quot;plat=x86_amd64&quot;))",
f"call &quot;{batch_file}&quot; !plat!",
"^&amp; (if &quot;$(PlatformTarget)&quot;==&quot;x64&quot; (set &quot;plat=x86_amd64&quot;))",
f"^&amp; call &quot;{batch_file}&quot; !plat!",
"^&amp;",
]

0 comments on commit 128509b

Please sign in to comment.