mitsuba/data/windows/genproj.py

72 lines
2.7 KiB
Python
Raw Normal View History

2011-02-16 23:30:05 +08:00
from lxml import etree
2011-06-01 08:23:57 +08:00
import os, string, shutil, uuid
2011-02-16 23:30:05 +08:00
doc2017 = etree.parse('data/windows/mitsuba-msvc2017.vcxproj.template')
doc2017_filters = etree.parse('data/windows/mitsuba-msvc2017.vcxproj.filters.template')
2011-02-16 23:30:05 +08:00
2011-06-01 08:23:57 +08:00
ns = {'n' : 'http://schemas.microsoft.com/developer/msbuild/2003'}
headers2017 = etree.XPath('/n:Project/n:ItemGroup[@Label="Header Files"]', namespaces = ns)(doc2017)[0]
sources2017 = etree.XPath('/n:Project/n:ItemGroup[@Label="Source Files"]', namespaces = ns)(doc2017)[0]
headers2017_filters = etree.XPath('/n:Project/n:ItemGroup[@Label="Header Files"]', namespaces = ns)(doc2017_filters)[0]
sources2017_filters = etree.XPath('/n:Project/n:ItemGroup[@Label="Source Files"]', namespaces = ns)(doc2017_filters)[0]
filters2017 = etree.XPath('/n:Project/n:ItemGroup[@Label="Filters"]', namespaces = ns)(doc2017_filters)[0]
def traverse(dirname, prefix):
2011-02-16 23:30:05 +08:00
for file in [file for file in os.listdir(dirname) if not file in ['.', '..']]:
filename = os.path.join(dirname, file)
if os.path.isdir(filename):
2011-06-01 08:23:57 +08:00
lastname = os.path.split(filename)[1]
# Visual Studio 2017 nodes
2011-06-01 08:23:57 +08:00
subprefix = os.path.join(prefix, lastname)
node2017 = etree.SubElement(filters2017, 'Filter')
node2017.set('Include', subprefix.replace('/', '\\'))
ui = etree.SubElement(node2017, 'UniqueIdentifier')
2011-06-01 08:23:57 +08:00
ui.text = '{' + str(uuid.uuid4()) + '}'
ui.tail = '\n\t\t'
node2017.tail = '\n\t\t'
node2017.text = '\n\t\t\t'
2011-06-01 08:23:57 +08:00
traverse(filename, subprefix)
2011-02-16 23:30:05 +08:00
else:
ext = os.path.splitext(filename)[1]
2011-06-01 08:23:57 +08:00
filename = '..\\' + filename.replace('/', '\\')
prefix = prefix.replace('/', '\\')
2011-02-16 23:30:05 +08:00
# Visual Studio 2017 nodes
2011-06-01 08:23:57 +08:00
if ext == '.cpp' or ext == '.c':
node = etree.SubElement(sources2017, 'ClCompile')
2011-06-01 08:23:57 +08:00
node.set('Include', filename)
node.tail = '\n\t\t'
node.text = '\n\t\t\t'
node = etree.SubElement(sources2017_filters, 'ClCompile')
2011-06-01 08:23:57 +08:00
node.set('Include', filename)
node.tail = '\n\t\t'
node.text = '\n\t\t\t'
filter = etree.SubElement(node, 'Filter')
filter.text = prefix
filter.tail = '\n\t\t'
elif ext == '.h' or ext == '.inl':
node = etree.SubElement(headers2017, 'ClInclude')
2011-06-01 08:23:57 +08:00
node.set('Include', filename)
node.tail = '\n\t\t'
node.text = '\n\t\t\t'
node = etree.SubElement(headers2017_filters, 'ClInclude')
2011-06-01 08:23:57 +08:00
node.set('Include', filename)
node.tail = '\n\t\t'
node.text = '\n\t\t\t'
filter = etree.SubElement(node, 'Filter')
filter.text = prefix
filter.tail = '\n\t\t'
traverse('src', 'Source Files')
traverse('include', 'Header Files')
2011-06-01 08:23:57 +08:00
of = open('build/mitsuba-msvc2017.vcxproj', 'w')
of.write(etree.tostring(doc2017, pretty_print=True))
2011-06-01 08:23:57 +08:00
of.close()
of = open('build/mitsuba-msvc2017.vcxproj.filters', 'w')
of.write(etree.tostring(doc2017_filters, pretty_print=True))
2011-02-16 23:30:05 +08:00
of.close()