mirror of
https://github.com/phodina/ProjectConverter.git
synced 2026-04-30 19:09:16 +08:00
Script now generates CMakeLists.txt file.
This commit is contained in:
parent
c830beeedf
commit
2f08c0188f
48
cmake.py
48
cmake.py
@ -1,14 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import datetime
|
||||
import platform
|
||||
import datetime
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
class CMake (object):
|
||||
|
||||
def __init__(self, data):
|
||||
def __init__(self, project):
|
||||
|
||||
self.project = project
|
||||
self.context = {}
|
||||
|
||||
def populateCMake (self):
|
||||
@ -20,12 +21,32 @@ class CMake (object):
|
||||
fpu = '-mfpu=fpv5-sp-d16 -mfloat-abi=softfp'
|
||||
fpu = ''
|
||||
|
||||
core = '-mcpu=cortex-m4'
|
||||
core = ''
|
||||
|
||||
if 'STM32F0' in self.project['chip']:
|
||||
core = '-mcpu=cortex-m0'
|
||||
elif 'STM32F1' in self.project['chip']:
|
||||
core = '-mcpu=cortex-m3'
|
||||
elif 'STM32F2' in self.project['chip']:
|
||||
core = '-mcpu=cortex-m3'
|
||||
elif 'STM32F3' in self.project['chip']:
|
||||
core = '-mcpu=cortex-m4'
|
||||
elif 'STM32F4' in self.project['chip']:
|
||||
core = '-mcpu=cortex-m4'
|
||||
elif 'STM32F7' in self.project['chip']:
|
||||
core = '-mcpu=cortex-m7'
|
||||
elif 'STM32L0' in self.project['chip']:
|
||||
core = '-mcpu=cortex-m0'
|
||||
elif 'STM32L1' in self.project['chip']:
|
||||
core = '-mcpu=cortex-m3'
|
||||
elif 'STM32L4' in self.project['chip']:
|
||||
core = '-mcpu=cortex-m4'
|
||||
|
||||
cmake['version'] = '3.1'
|
||||
cmake['project'] = self.root.Project.attrib['Name']
|
||||
cmake['project'] = self.project['name']
|
||||
cmake['incs'] = []
|
||||
cmake['incs'].append('inc')
|
||||
for inc in self.project['incs']:
|
||||
cmake['incs'].append(inc)
|
||||
cmake['srcs'] = []
|
||||
cmake['srcs'].append({'path':'src','var':'DIR_SRC'})
|
||||
|
||||
@ -40,13 +61,15 @@ class CMake (object):
|
||||
cmake['linker_script'] = 'stm32.ld'
|
||||
cmake['linker_path'] = 'libopencm3/lib'
|
||||
cmake['defines'] = []
|
||||
cmake['defines'].append(self.root.MCU.attrib['Family'])
|
||||
for define in self.project['defs']:
|
||||
cmake['defines'].append(define)
|
||||
|
||||
cmake['libs'] = []
|
||||
cmake['libs'].append({'name':'opencm3_' + self.root.MCU.attrib['Family'].lower(),'path':'libopencm3/lib'})
|
||||
#cmake['libs'].append({'name':'opencm3_' + self.root.MCU.attrib['Family'].lower(),'path':'libopencm3/lib'})
|
||||
|
||||
self.context['cmake'] = cmake
|
||||
|
||||
self.generateFile(self,'CMakeLists.txt')
|
||||
self.generateFile('CMakeLists.txt')
|
||||
|
||||
print ('Created file CMakeLists.txt')
|
||||
|
||||
@ -55,14 +78,15 @@ class CMake (object):
|
||||
if (pathDst == ''):
|
||||
pathDst = pathSrc
|
||||
|
||||
self.context['file'] = os.path.basename(pathSrc)
|
||||
print (os.getcwd())
|
||||
self.context['file'] = os.path.basename(str(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)
|
||||
template = env.get_template(str(pathSrc))
|
||||
|
||||
generated_code = template.render(self.context)
|
||||
|
||||
@ -77,6 +101,4 @@ class CMake (object):
|
||||
f.write(str.encode(generated_code))
|
||||
else:
|
||||
# Different OS than Windows or Linux
|
||||
pass
|
||||
|
||||
|
||||
pass
|
||||
11
converter.py
11
converter.py
@ -1,11 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import argparse
|
||||
import cmake
|
||||
import ewpproject
|
||||
import uvprojxproject
|
||||
|
||||
# TODO: add Cmake and jinja2 support
|
||||
|
||||
def findFile (path,fileext):
|
||||
|
||||
f = ''
|
||||
@ -35,6 +34,10 @@ if __name__ == '__main__':
|
||||
project = ewpproject.EWPProject(args.path,file)
|
||||
project.parseProject()
|
||||
project.displaySummary()
|
||||
|
||||
cmakefile = cmake.CMake(project.getProject())
|
||||
cmakefile.populateCMake()
|
||||
|
||||
else:
|
||||
print ('No project *.ewp file found')
|
||||
|
||||
@ -46,6 +49,10 @@ if __name__ == '__main__':
|
||||
project = uvprojxproject.UVPROJXProject(args.path,file)
|
||||
project.parseProject()
|
||||
project.displaySummary()
|
||||
|
||||
cmakefile = cmake.CMake(project.getProject())
|
||||
cmakefile.populateCMake()
|
||||
|
||||
else:
|
||||
print ('No project *.uvprojx file found')
|
||||
else:
|
||||
|
||||
@ -43,7 +43,7 @@ class EWPProject (object):
|
||||
self.project['incs'].append(d.text)
|
||||
|
||||
for i in range(0, len(self.project['incs'])):
|
||||
self.project['incs'][i] = self.project['incs'][i].replace('$PROJ_DIR$', self.path)
|
||||
self.project['incs'][i] = self.project['incs'][i].replace('$PROJ_DIR$/..', self.path)
|
||||
|
||||
|
||||
def displaySummary(self):
|
||||
@ -87,4 +87,7 @@ class EWPProject (object):
|
||||
elif element.tag == 'file':
|
||||
print ('File: ' + element.name)
|
||||
group['files'].append(element.name)
|
||||
|
||||
|
||||
def getProject(self):
|
||||
|
||||
return self.project
|
||||
@ -5,20 +5,21 @@ class UVPROJXProject (object):
|
||||
|
||||
def __init__(self, path, xmlFile):
|
||||
|
||||
self.project = {}
|
||||
self.xmlFile = xmlFile
|
||||
xmltree = objectify.parse(xmlFile)
|
||||
self.root = xmltree.getroot()
|
||||
|
||||
def parseProject (self):
|
||||
|
||||
self.projectName = self.root.Targets.Target.TargetName
|
||||
self.chip = self.root.Targets.Target.TargetOption.TargetCommonOption.Device
|
||||
self.svd = self.root.Targets.Target.TargetOption.TargetCommonOption.SFDFile
|
||||
self.includes = self.root.Targets.Target.TargetOption.TargetArmAds.Cads.VariousControls.IncludePath.text.split(';')
|
||||
self.memories = self.root.Targets.Target.TargetOption.TargetCommonOption.Cpu
|
||||
self.defines = self.root.Targets.Target.TargetOption.TargetArmAds.Cads.VariousControls.Define.text.split(',')
|
||||
self.project['name'] = self.root.Targets.Target.TargetName
|
||||
self.project['chip'] = self.root.Targets.Target.TargetOption.TargetCommonOption.Device
|
||||
self.project['svd'] = self.root.Targets.Target.TargetOption.TargetCommonOption.SFDFile
|
||||
self.project['incs'] = self.root.Targets.Target.TargetOption.TargetArmAds.Cads.VariousControls.IncludePath.text.split(';')
|
||||
self.project['mems'] = self.root.Targets.Target.TargetOption.TargetCommonOption.Cpu
|
||||
self.project['defs'] = self.root.Targets.Target.TargetOption.TargetArmAds.Cads.VariousControls.Define.text.split(',')
|
||||
|
||||
self.sources = []
|
||||
self.project['srcs'] = []
|
||||
for element in self.root.Targets.Target.Groups.getchildren():
|
||||
|
||||
print ('GroupName: ' + element.GroupName.text)
|
||||
@ -29,10 +30,14 @@ class UVPROJXProject (object):
|
||||
|
||||
def displaySummary(self):
|
||||
|
||||
print ('Project Name:' + self.projectName)
|
||||
print ('Project chip:' + self.chip)
|
||||
print ('Project svd:' + self.svd)
|
||||
print ('Project includes: ' + ' '.join(self.includes))
|
||||
print ('Project defines: ' + ' '.join(self.defines))
|
||||
print ('Project: ' + self.memories)
|
||||
print ('Project Name:' + self.project['name'])
|
||||
print ('Project chip:' + self.project['chip'])
|
||||
print ('Project svd:' + self.project['svd'])
|
||||
print ('Project includes: ' + ' '.join(self.project['incs']))
|
||||
print ('Project defines: ' + ' '.join(self.project['defs']))
|
||||
print ('Project: ' + self.project['mems'])
|
||||
|
||||
def getProject(self):
|
||||
|
||||
return self.project
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user