[tools][keil] 支持keil工程多个配置

由于项目中有不同需求的配置,此次提交可以通过templete模块文件来创建不同的配置,使用scons
--target=mkd5来生成工程的不同配置,本提交已在基本stm32\gd32测试

Signed-off-by: tjrong2 <tjrong2@163.com>
This commit is contained in:
tjrong2 2024-01-02 14:48:47 +08:00 committed by Meco Man
parent 0400fffafc
commit 6e5427e967
1 changed files with 97 additions and 79 deletions

View File

@ -216,6 +216,16 @@ def MDK45Project(tree, target, script):
out = open(target, 'w')
out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n')
#Addtion the name of OutputDir
for targcomoOp in root.findall('.//TargetCommonOption'):
OutputDir = targcomoOp.find('OutputDirectory')
OutputName = targcomoOp.find('OutputName')
#print(OutputDir.text)
#print(OutputName.text)
OutputDir.text += OutputName.text + '\\'
#print(OutputDir.text)
for child in root.findall('.//Target'):
CPPPATH = []
CPPDEFINES = []
LINKFLAGS = ''
@ -223,15 +233,18 @@ def MDK45Project(tree, target, script):
CCFLAGS = ''
CFLAGS = ''
ProjectFiles = []
groups = child.find('Groups')
if groups is None:
groups = SubElement(child,'Groups')
groups.clear() # clean old groups
# add group
groups = tree.find('Targets/Target/Groups')
if groups is None:
groups = SubElement(tree.find('Targets/Target'), 'Groups')
groups.clear() # clean old groups
#groups = tree.find('Targets/Target/Groups')
#if groups is None:
#groups = SubElement(tree.find('Targets/Target'), 'Groups')
#groups.clear() # clean old groups
for group in script:
group_tree = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path, group)
# get each include path
if 'CPPPATH' in group and group['CPPPATH']:
if CPPPATH:
@ -289,23 +302,28 @@ def MDK45Project(tree, target, script):
MDK4AddLibToGroup(ProjectFiles, group_tree, group['name'], lib_path, project_path)
else:
group_tree = MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path)
# write include path, definitions and link flags
IncludePath = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath')
IncludePath = child.find('TargetOption/TargetArmAds/Cads/VariousControls/IncludePath')
if(IncludePath.text != None):
IncludePath.text = IncludePath.text +';' + ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in set(CPPPATH)])
else:
IncludePath.text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in set(CPPPATH)])
Define = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define')
Define.text = ', '.join(set(CPPDEFINES))
Define = child.find('TargetOption/TargetArmAds/Cads/VariousControls/Define')
if(Define.text != None):
Define.text = Define.text +',' + ', '.join(set(CPPDEFINES))
else:
Define.text = ','.join(set(CPPDEFINES))
if 'c99' in CXXFLAGS or 'c99' in CCFLAGS or 'c99' in CFLAGS:
uC99 = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/uC99')
uC99 = child.find('TargetOption/TargetArmAds/Cads/uC99')
uC99.text = '1'
if 'gnu' in CXXFLAGS or 'gnu' in CCFLAGS or 'gnu' in CFLAGS:
uGnu = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/uGnu')
uGnu = child.find('TargetOption/TargetArmAds/Cads/uGnu')
uGnu.text = '1'
Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc')
Misc = child.find('TargetOption/TargetArmAds/LDads/Misc')
Misc.text = LINKFLAGS
xml_indent(root)