Added CMake support. Rewritten EWPProject to store project information into dictionary which will be passed to CMake as single data structure. Same

will be true for UVPROJXProject.
This commit is contained in:
cylon 2016-09-02 18:32:41 +02:00
parent 7ab01684c4
commit c830beeedf
3 changed files with 127 additions and 19 deletions

82
cmake.py Normal file
View File

@ -0,0 +1,82 @@
# -*- coding: utf-8 -*-
import os
import datetime
import platform
from jinja2 import Environment, FileSystemLoader
class CMake (object):
def __init__(self, data):
self.context = {}
def populateCMake (self):
""" Generate CMakeList.txt file for building the project
"""
# For debug run cmake -DCMAKE_BUILD_TYPE=Debug or Release
cmake = {}
fpu = '-mfpu=fpv5-sp-d16 -mfloat-abi=softfp'
fpu = ''
core = '-mcpu=cortex-m4'
cmake['version'] = '3.1'
cmake['project'] = self.root.Project.attrib['Name']
cmake['incs'] = []
cmake['incs'].append('inc')
cmake['srcs'] = []
cmake['srcs'].append({'path':'src','var':'DIR_SRC'})
cmake['cxx'] = 'false'
cmake['c_flags'] = '-g -Wextra -Wshadow -Wimplicit-function-declaration -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes -fno-common -ffunction-sections -fdata-sections -MD -Wall -Wundef -mthumb ' + core + ' ' + fpu
cmake['cxx_flags'] = '-Wextra -Wshadow -Wredundant-decls -Weffc++ -fno-common -ffunction-sections -fdata-sections -MD -Wall -Wundef -mthumb ' + core + ' ' + fpu
cmake['asm_flags'] = '-g -mthumb ' + core + ' ' + fpu + ' -x assembler-with-cpp'
cmake['linker_flags'] = '-g -Wl,--gc-sections -Wl,-Map=' + cmake['project'] + '.map --static -nostartfiles -Wl,--start-group -specs=nosys.specs -lc -lgcc -lnosys -Wl,--end-group -mthumb ' + core + ' ' + fpu
cmake['linker_script'] = 'stm32.ld'
cmake['linker_path'] = 'libopencm3/lib'
cmake['defines'] = []
cmake['defines'].append(self.root.MCU.attrib['Family'])
cmake['libs'] = []
cmake['libs'].append({'name':'opencm3_' + self.root.MCU.attrib['Family'].lower(),'path':'libopencm3/lib'})
self.context['cmake'] = cmake
self.generateFile(self,'CMakeLists.txt')
print ('Created file CMakeLists.txt')
def generateFile (self, pathSrc, pathDst='', author='Pegasus', version='v1.0.0', licence='licence.txt', template_dir='../PegasusTemplates'):
if (pathDst == ''):
pathDst = pathSrc
self.context['file'] = os.path.basename(pathSrc)
self.context['author'] = author
self.context['date'] = datetime.date.today().strftime('%d, %b %Y')
self.context['version'] = version
self.context['licence'] = licence
env = Environment(loader=FileSystemLoader(template_dir),trim_blocks=True,lstrip_blocks=True)
template = env.get_template(pathSrc)
generated_code = template.render(self.context)
if platform.system() == 'Window':
with open(pathDst, 'wb') as f:
f.write(generated_code)
elif platform.system() == 'Linux':
with open(pathDst, 'wb') as f:
f.write(str.encode(generated_code))
else:
# Different OS than Windows or Linux
pass

View File

@ -6,6 +6,7 @@ class EWPProject (object):
def __init__(self, path, xmlFile):
self.project = {}
self.path = path
self.xmlFile = xmlFile
xmltree = objectify.parse(xmlFile)
@ -13,15 +14,16 @@ class EWPProject (object):
def parseProject(self):
self.projectName = self.root.configuration.name
self.project['name'] = self.root.configuration.name
self.chip = ''
self.project['chip'] = ''
#TODO: parse into tree structure
self.searchGroups(self.root)
#TODO: parse into tree structure
self.project['srcs'] = []
self.searchGroups(self.root, self.project['srcs'])
self.defines = []
self.includes = []
self.project['defs'] = []
self.project['incs'] = []
for element in self.root.configuration.getchildren():
@ -30,34 +32,59 @@ class EWPProject (object):
if e.tag == 'option':
if e.name.text == 'OGChipSelectEditMenu':
self.chip = e.state
self.project['chip'] = e.state
elif e.name.text == 'CCDefines':
for d in e.getchildren():
if d.tag == 'state' and d.text != None:
self.defines.append(d.text)
self.project['defs'].append(d.text)
elif e.name.text == 'CCIncludePath2':
for d in e.getchildren():
if d.tag == 'state' and d.text != None:
self.includes.append(d.text)
self.project['incs'].append(d.text)
for i in range(0, len(self.includes)):
self.includes[i] = self.includes[i].replace('$PROJ_DIR$', self.path)
for i in range(0, len(self.project['incs'])):
self.project['incs'][i] = self.project['incs'][i].replace('$PROJ_DIR$', self.path)
def displaySummary(self):
print ('Project Name:' + self.projectName)
print ('Project chip:' + self.chip)
print ('Project includes: ' + ' '.join(self.includes))
print ('Project defines: ' + ' '.join(self.defines))
print ('Project Name:' + self.project['name'])
print ('Project chip:' + self.project['chip'])
print ('Project includes: ' + ' '.join(self.project['incs']))
print ('Project defines: ' + ' '.join(self.project['defs']))
def searchGroups(self, xml):
#print ('Groups: ')
#print (self.sources)
#for src in self.sources:
# self.printGroups(src)
def printGroups(self, group):
print ('Group name:' + group['name'])
for file in group['files']:
print ('File: ' + file)
for g in group['groups']:
self.printGroups(g)
def searchGroups(self, xml, sources):
group = {}
group['name'] = ''
group['files'] = []
group['groups'] = []
for element in xml.getchildren():
if element.tag == 'group':
self.searchGroups(element)
group['name'] = element.name
print ('File: ' + group['name'])
self.searchGroups(element,group['groups'])
sources.append(group)
elif element.tag == 'file':
print (element.name)
print ('File: ' + element.name)
group['files'].append(element.name)

View File

@ -21,7 +21,6 @@ class UVPROJXProject (object):
self.sources = []
for element in self.root.Targets.Target.Groups.getchildren():
print ('GroupName: ' + element.GroupName.text)
if hasattr(element,'Files'):
for file in element.Files.getchildren():