4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-02-21 01:07:18 +08:00

[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

View File

@ -216,97 +216,115 @@ def MDK45Project(tree, target, script):
out = open(target, 'w') out = open(target, 'w')
out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n') out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n')
CPPPATH = [] #Addtion the name of OutputDir
CPPDEFINES = [] for targcomoOp in root.findall('.//TargetCommonOption'):
LINKFLAGS = '' OutputDir = targcomoOp.find('OutputDirectory')
CXXFLAGS = '' OutputName = targcomoOp.find('OutputName')
CCFLAGS = '' #print(OutputDir.text)
CFLAGS = '' #print(OutputName.text)
ProjectFiles = [] OutputDir.text += OutputName.text + '\\'
#print(OutputDir.text)
# add group for child in root.findall('.//Target'):
groups = tree.find('Targets/Target/Groups') CPPPATH = []
if groups is None: CPPDEFINES = []
groups = SubElement(tree.find('Targets/Target'), 'Groups') LINKFLAGS = ''
groups.clear() # clean old groups CXXFLAGS = ''
for group in script: CCFLAGS = ''
group_tree = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path, group) CFLAGS = ''
ProjectFiles = []
groups = child.find('Groups')
if groups is None:
groups = SubElement(child,'Groups')
groups.clear() # clean old groups
# get each include path # add group
if 'CPPPATH' in group and group['CPPPATH']: #groups = tree.find('Targets/Target/Groups')
if CPPPATH: #if groups is None:
CPPPATH += group['CPPPATH'] #groups = SubElement(tree.find('Targets/Target'), 'Groups')
else: #groups.clear() # clean old groups
CPPPATH += group['CPPPATH'] 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:
CPPPATH += group['CPPPATH']
else:
CPPPATH += group['CPPPATH']
# get each group's definitions # get each group's definitions
if 'CPPDEFINES' in group and group['CPPDEFINES']: if 'CPPDEFINES' in group and group['CPPDEFINES']:
if CPPDEFINES: if CPPDEFINES:
CPPDEFINES += group['CPPDEFINES'] CPPDEFINES += group['CPPDEFINES']
else: else:
CPPDEFINES = group['CPPDEFINES'] CPPDEFINES = group['CPPDEFINES']
# get each group's link flags # get each group's link flags
if 'LINKFLAGS' in group and group['LINKFLAGS']: if 'LINKFLAGS' in group and group['LINKFLAGS']:
if LINKFLAGS: if LINKFLAGS:
LINKFLAGS += ' ' + group['LINKFLAGS'] LINKFLAGS += ' ' + group['LINKFLAGS']
else: else:
LINKFLAGS += group['LINKFLAGS'] LINKFLAGS += group['LINKFLAGS']
# get each group's CXXFLAGS flags # get each group's CXXFLAGS flags
if 'CXXFLAGS' in group and group['CXXFLAGS']: if 'CXXFLAGS' in group and group['CXXFLAGS']:
if CXXFLAGS: if CXXFLAGS:
CXXFLAGS += ' ' + group['CXXFLAGS'] CXXFLAGS += ' ' + group['CXXFLAGS']
else: else:
CXXFLAGS += group['CXXFLAGS'] CXXFLAGS += group['CXXFLAGS']
# get each group's CCFLAGS flags # get each group's CCFLAGS flags
if 'CCFLAGS' in group and group['CCFLAGS']: if 'CCFLAGS' in group and group['CCFLAGS']:
if CCFLAGS: if CCFLAGS:
CCFLAGS += ' ' + group['CCFLAGS'] CCFLAGS += ' ' + group['CCFLAGS']
else: else:
CCFLAGS += group['CCFLAGS'] CCFLAGS += group['CCFLAGS']
# get each group's CFLAGS flags # get each group's CFLAGS flags
if 'CFLAGS' in group and group['CFLAGS']: if 'CFLAGS' in group and group['CFLAGS']:
if CFLAGS: if CFLAGS:
CFLAGS += ' ' + group['CFLAGS'] CFLAGS += ' ' + group['CFLAGS']
else: else:
CFLAGS += group['CFLAGS'] CFLAGS += group['CFLAGS']
# get each group's LIBS flags # get each group's LIBS flags
if 'LIBS' in group and group['LIBS']: if 'LIBS' in group and group['LIBS']:
for item in group['LIBS']: for item in group['LIBS']:
lib_path = '' lib_path = ''
for path_item in group['LIBPATH']: for path_item in group['LIBPATH']:
full_path = os.path.join(path_item, item + '.lib') full_path = os.path.join(path_item, item + '.lib')
if os.path.isfile(full_path): # has this library if os.path.isfile(full_path): # has this library
lib_path = full_path lib_path = full_path
break break
if lib_path != '': if lib_path != '':
if group_tree != None: if group_tree != None:
MDK4AddLibToGroup(ProjectFiles, group_tree, group['name'], lib_path, project_path) MDK4AddLibToGroup(ProjectFiles, group_tree, group['name'], lib_path, project_path)
else: else:
group_tree = MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path) group_tree = MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path)
# write include path, definitions and link flags
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)])
# write include path, definitions and link flags Define = child.find('TargetOption/TargetArmAds/Cads/VariousControls/Define')
IncludePath = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath') if(Define.text != None):
IncludePath.text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in set(CPPPATH)]) Define.text = Define.text +',' + ', '.join(set(CPPDEFINES))
else:
Define.text = ','.join(set(CPPDEFINES))
Define = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define') if 'c99' in CXXFLAGS or 'c99' in CCFLAGS or 'c99' in CFLAGS:
Define.text = ', '.join(set(CPPDEFINES)) uC99 = child.find('TargetOption/TargetArmAds/Cads/uC99')
uC99.text = '1'
if 'c99' in CXXFLAGS or 'c99' in CCFLAGS or 'c99' in CFLAGS: if 'gnu' in CXXFLAGS or 'gnu' in CCFLAGS or 'gnu' in CFLAGS:
uC99 = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/uC99') uGnu = child.find('TargetOption/TargetArmAds/Cads/uGnu')
uC99.text = '1' uGnu.text = '1'
if 'gnu' in CXXFLAGS or 'gnu' in CCFLAGS or 'gnu' in CFLAGS: Misc = child.find('TargetOption/TargetArmAds/LDads/Misc')
uGnu = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/uGnu') Misc.text = LINKFLAGS
uGnu.text = '1'
Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc')
Misc.text = LINKFLAGS
xml_indent(root) xml_indent(root)
out.write(etree.tostring(root, encoding='utf-8').decode()) out.write(etree.tostring(root, encoding='utf-8').decode())