vsproject.py updates

Add multithreaded compilation flag
Fix autogenerated portions being output all on one line
Fix irrelevant bug where filters may not be added if there aren't any source files in that directory, but subdirectories do have source files
This commit is contained in:
jacob1 2019-08-10 16:20:03 -04:00
parent 41d54857f2
commit 25b7021f2a

View File

@ -1,4 +1,5 @@
import os
from pathlib import Path
import uuid
cl_compile = []
@ -7,14 +8,22 @@ source_dirs = set()
for root, subdirs, files in os.walk('src'):
for file in [os.path.join(root, f) for f in files]:
lowerfile = file.lower()
add_source_dir = False
if lowerfile.endswith('.cpp') or lowerfile.endswith('.c'):
cl_compile.append(file)
source_dirs.add(os.path.dirname(file))
add_source_dir = True
if lowerfile.endswith('.hpp') or lowerfile.endswith('.h'):
cl_include.append(file)
add_source_dir = True
if add_source_dir:
path = Path(root)
for i in range(len(path.parents) - 1):
parent = path.parents[i]
if not str(parent) in source_dirs:
source_dirs.add(str(parent))
source_dirs.add(os.path.dirname(file))
sln = open('The-Powder-Toy.sln', 'w')
sln = open("The-Powder-Toy.sln", 'w')
sln.write(r"""Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.40629.0
@ -42,7 +51,7 @@ EndGlobal
""")
sln.close()
vcxproj = open('The-Powder-Toy.vcxproj', 'w')
vcxproj = open("The-Powder-Toy.vcxproj", 'w')
vcxproj.write(r"""<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
@ -120,6 +129,7 @@ vcxproj.write(r"""<?xml version="1.0" encoding="utf-8"?>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level1</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<Optimization>Disabled</Optimization>
<FloatingPointModel>Fast</FloatingPointModel>
<TreatWarningAsError>true</TreatWarningAsError>
@ -137,6 +147,7 @@ vcxproj.write(r"""<?xml version="1.0" encoding="utf-8"?>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<WarningLevel>Level1</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<FloatingPointModel>Fast</FloatingPointModel>
<TreatWarningAsError>true</TreatWarningAsError>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
@ -156,6 +167,7 @@ vcxproj.write(r"""<?xml version="1.0" encoding="utf-8"?>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<WarningLevel>Level1</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<FloatingPointModel>Fast</FloatingPointModel>
<TreatWarningAsError>true</TreatWarningAsError>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
@ -180,8 +192,8 @@ vcxproj.write(r"""<?xml version="1.0" encoding="utf-8"?>
<ClCompile Include="data\images.cpp" />
<ClCompile Include="generated\ElementClasses.cpp" />
<ClCompile Include="generated\ToolClasses.cpp" />
""")
vcxproj.write(''.join([('<ClCompile Include="' + p + '" />') for p in cl_compile]))
""")
vcxproj.write('\n '.join([('<ClCompile Include="' + p + '" />') for p in cl_compile]))
vcxproj.write(r"""
</ItemGroup>
<ItemGroup>
@ -195,8 +207,8 @@ vcxproj.write(r"""
<ClInclude Include="generated\ElementClasses.h" />
<ClInclude Include="generated\ToolClasses.h" />
<ClInclude Include="resources\resource.h" />
""")
vcxproj.write(''.join([('<ClInclude Include="' + p + '" />') for p in cl_include]))
""")
vcxproj.write('\n '.join([('<ClInclude Include="' + p + '" />') for p in cl_include]))
vcxproj.write(r"""
</ItemGroup>
<ItemGroup>
@ -221,7 +233,7 @@ vcxproj.write(r"""
""")
vcxproj.close()
filters = open('The-Powder-Toy.vcxproj.filters', 'w')
filters = open("The-Powder-Toy.vcxproj.filters", 'w')
filters.write(r"""<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
@ -239,8 +251,8 @@ filters.write(r"""<?xml version="1.0" encoding="utf-8"?>
<Filter Include="generated">
<UniqueIdentifier>{bfb47e29-68f3-48bd-86c2-46b9f63d2597}</UniqueIdentifier>
</Filter>
""")
filters.write(''.join([('<Filter Include="' + p + '"><UniqueIdentifier>{' + str(uuid.uuid4()) + '}</UniqueIdentifier></Filter>') for p in source_dirs]))
""")
filters.write('\n '.join([('<Filter Include="' + p + '">\n <UniqueIdentifier>{' + str(uuid.uuid4()) + '}</UniqueIdentifier>\n </Filter>') for p in source_dirs]))
filters.write(r"""
</ItemGroup>
<ItemGroup>
@ -250,8 +262,8 @@ filters.write(r"""
<ClCompile Include="generated\ToolClasses.cpp">
<Filter>generated</Filter>
</ClCompile>
""")
filters.write(''.join([('<ClCompile Include="' + p + '"><Filter>' + os.path.dirname(p) + '</Filter></ClCompile>') for p in cl_compile]))
""")
filters.write('\n '.join([('<ClCompile Include="' + p + '">\n <Filter>' + os.path.dirname(p) + '</Filter>\n </ClCompile>') for p in cl_compile]))
filters.write(r"""
</ItemGroup>
<ItemGroup>
@ -285,8 +297,8 @@ filters.write(r"""
<ClInclude Include="data\Shaders.h">
<Filter>data</Filter>
</ClInclude>
""")
filters.write(''.join([('<ClInclude Include="' + p + '"><Filter>' + os.path.dirname(p) + '</Filter></ClInclude>') for p in cl_include]))
""")
filters.write('\n '.join([('<ClInclude Include="' + p + '">\n <Filter>' + os.path.dirname(p) + '</Filter>\n </ClInclude>') for p in cl_include]))
filters.write(r"""
<ClInclude Include="resources\resource.h">
<Filter>resources</Filter>