fix:buding_keil_CPPDEFINES

This commit is contained in:
CYFS 2025-07-04 20:57:50 +08:00 committed by Rbb666
parent f4168669a7
commit 492e33dd3c
2 changed files with 11 additions and 25 deletions

View File

@ -805,13 +805,13 @@ def GenTargetProject(program = None):
from targets.keil import MDK2Project, MDK4Project, MDK5Project, ARMCC_Version
if os.path.isfile('template.uvprojx') and GetOption('target') not in ['mdk4']: # Keil5
MDK5Project(GetOption('project-name') + '.uvprojx', Projects)
MDK5Project(Env, GetOption('project-name') + '.uvprojx', Projects)
print("Keil5 project is generating...")
elif os.path.isfile('template.uvproj') and GetOption('target') not in ['mdk5']: # Keil4
MDK4Project(GetOption('project-name') + '.uvproj', Projects)
MDK4Project(Env, GetOption('project-name') + '.uvproj', Projects)
print("Keil4 project is generating...")
elif os.path.isfile('template.Uv2') and GetOption('target') not in ['mdk4', 'mdk5']: # Keil2
MDK2Project(GetOption('project-name') + '.Uv2', Projects)
MDK2Project(Env, GetOption('project-name') + '.Uv2', Projects)
print("Keil2 project is generating...")
else:
print ('No template project file found.')

View File

@ -216,7 +216,7 @@ def MDK4AddGroup(ProjectFiles, parent, name, files, project_path, group_scons):
return group
# The common part of making MDK4/5 project
def MDK45Project(tree, target, script):
def MDK45Project(env, tree, target, script):
project_path = os.path.dirname(os.path.abspath(target))
root = tree.getroot()
@ -224,7 +224,7 @@ def MDK45Project(tree, target, script):
out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n')
CPPPATH = []
CPPDEFINES = []
CPPDEFINES = env.get('CPPDEFINES', [])
LINKFLAGS = ''
CXXFLAGS = ''
CCFLAGS = ''
@ -246,13 +246,6 @@ def MDK45Project(tree, target, script):
else:
CPPPATH += group['CPPPATH']
# get each group's definitions
if 'CPPDEFINES' in group and group['CPPDEFINES']:
if CPPDEFINES:
CPPDEFINES += group['CPPDEFINES']
else:
CPPDEFINES = group['CPPDEFINES']
# get each group's link flags
if 'LINKFLAGS' in group and group['LINKFLAGS']:
if LINKFLAGS:
@ -313,7 +306,7 @@ def MDK45Project(tree, target, script):
out.write(etree.tostring(root, encoding='utf-8').decode())
out.close()
def MDK4Project(target, script):
def MDK4Project(env, target, script):
if os.path.isfile('template.uvproj') is False:
print ('Warning: The template project file [template.uvproj] not found!')
@ -321,7 +314,7 @@ def MDK4Project(target, script):
template_tree = etree.parse('template.uvproj')
MDK45Project(template_tree, target, script)
MDK45Project(env, template_tree, target, script)
# remove project.uvopt file
project_uvopt = os.path.abspath(target).replace('uvproj', 'uvopt')
@ -352,7 +345,7 @@ def monitor_log_file(log_file_path):
if empty_line_count > 30:
print("Timeout reached or too many empty lines, exiting log monitoring thread.")
break
def MDK5Project(target, script):
def MDK5Project(env, target, script):
if os.path.isfile('template.uvprojx') is False:
print ('Warning: The template project file [template.uvprojx] not found!')
@ -360,7 +353,7 @@ def MDK5Project(target, script):
template_tree = etree.parse('template.uvprojx')
MDK45Project(template_tree, target, script)
MDK45Project(env, template_tree, target, script)
# remove project.uvopt file
project_uvopt = os.path.abspath(target).replace('uvprojx', 'uvoptx')
@ -387,7 +380,7 @@ def MDK5Project(target, script):
else:
print('UV4.exe is not available, please check your keil installation')
def MDK2Project(target, script):
def MDK2Project(env, target, script):
template = open(os.path.join(os.path.dirname(__file__), 'template.Uv2'), 'r')
lines = template.readlines()
@ -407,7 +400,7 @@ def MDK2Project(target, script):
ProjectFiles = []
CPPPATH = []
CPPDEFINES = []
CPPDEFINES = env.get('CPPDEFINES', [])
LINKFLAGS = ''
CFLAGS = ''
@ -423,13 +416,6 @@ def MDK2Project(target, script):
else:
CPPPATH += group['CPPPATH']
# get each group's definitions
if 'CPPDEFINES' in group and group['CPPDEFINES']:
if CPPDEFINES:
CPPDEFINES += group['CPPDEFINES']
else:
CPPDEFINES = group['CPPDEFINES']
# get each group's link flags
if 'LINKFLAGS' in group and group['LINKFLAGS']:
if LINKFLAGS: