[update] support command: scons --target=xmake

This commit is contained in:
liukangcc 2022-05-04 18:10:09 +08:00 committed by guo
parent 6495df717f
commit b077e91cdf
3 changed files with 141 additions and 1 deletions

View File

@ -185,6 +185,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
'ses' : ('gcc', 'gcc'),
'cmake':('gcc', 'gcc'),
'cmake-armclang':('keil', 'armclang'),
'xmake':('gcc', 'gcc'),
'codelite' : ('gcc', 'gcc')}
tgt_name = GetOption('target')
@ -847,7 +848,9 @@ def GenTargetProject(program = None):
if GetOption('target') == 'cmake' or GetOption('target') == 'cmake-armclang':
from cmake import CMakeProject
CMakeProject(Env,Projects)
if GetOption('target') == 'xmake':
from xmake import XMakeProject
XMakeProject(Env, Projects)
def EndBuilding(target, program = None):

46
tools/xmake.lua Normal file
View File

@ -0,0 +1,46 @@
add_rules("mode.debug", "mode.release")
toolchain("${toolchain}")
set_kind("standalone")
set_sdkdir("${sdkdir}")
toolchain_end()
target("${target}")
set_kind("binary")
set_toolchains("${toolchain}")
add_files(
${src_path}
)
add_includedirs(
${inc_path}
)
add_defines(
${define}
)
add_cflags(
"${cflags}" ,{force = true}
)
add_cxxflags(
"${cxxflags}" ,{force = true}
)
add_asflags(
"${asflags}" ,{force = true}
)
add_ldflags(
"${ldflags}" ,{force = true}
)
set_targetdir("./")
set_filename("rtthread.elf")
after_build(function(target)
os.exec("${toolchain}-objcopy -O ihex rtthread.elf rtthread.hex")
os.exec("${toolchain}-objcopy -O binary rtthread.elf rtthread.bin")
os.exec("${toolchain}-size rtthread.elf")
end)

91
tools/xmake.py Normal file
View File

@ -0,0 +1,91 @@
"""
Utils for CMake
Author: https://github.com/klivelinux
"""
import os
import utils
from string import Template
import rtconfig
from utils import _make_path_relative
class XmakeProject:
def __init__(self, env, project):
self.env = env
self.project = project
self.sdkdir = ""
self.toolchain = ""
self.src_path = ""
self.inc_path = ""
self.cflags = ""
self.cxxflags = ""
self.ldflags = ""
self.asflags = ""
self.define = ""
def set_toolchain_path(self):
self.sdkdir = os.path.abspath(rtconfig.EXEC_PATH).replace('\\', "/")
# delete -
self.toolchain = rtconfig.PREFIX[:-1]
def set_target_config(self):
info = utils.ProjectInfo(self.env)
# 1. config src path
for group in self.project:
for f in group['src']:
# use relative path
path = _make_path_relative(os.getcwd(), os.path.normpath(f.rfile().abspath))
self.src_path += "\t\"{0}\",\n".format(path.replace("\\", "/"))
self.src_path = self.src_path[:-2]
# 2. config dir path
for i in info['CPPPATH']:
# use relative path
path = _make_path_relative(os.getcwd(), i)
self.inc_path += "\t\"{0}\",\n".format(path.replace("\\", "/"))
self.inc_path = self.inc_path[:-2]
# 3. config cflags
self.cflags = rtconfig.CFLAGS.replace('\\', "/").replace('\"', "\\\"")
# 4. config cxxflags
if 'CXXFLAGS' in dir(rtconfig):
self.cxxflags = rtconfig.CXXFLAGS.replace('\\', "/").replace('\"', "\\\"")
else:
self.cxxflags = self.cflags
# 5. config asflags
self.asflags = rtconfig.AFLAGS.replace('\\', "/").replace('\"', "\\\"")
# 6. config lflags
self.ldflags = rtconfig.LFLAGS.replace('\\', "/").replace('\"', "\\\"")
# 7. config define
for i in info['CPPDEFINES']:
self.define += "\t\"{0}\",\n".format(i)
self.define = self.define[:-2]
def generate_xmake_file(self):
if os.getenv('RTT_ROOT'):
RTT_ROOT = os.getenv('RTT_ROOT')
else:
RTT_ROOT = os.path.normpath(os.getcwd() + '/../../..')
template_path = os.path.join(RTT_ROOT, "tools", "xmake.lua")
with open(template_path, "r") as f:
data = f.read()
data = Template(data)
data = data.safe_substitute(toolchain=self.toolchain, sdkdir=self.sdkdir, src_path=self.src_path, inc_path=self.inc_path,
define=self.define, cflags=self.cflags, cxxflags=self.cxxflags, asflags=self.asflags,
ldflags=self.ldflags, target="rt-thread")
with open("xmake.lua", "w") as f:
f.write(data)
def XMakeProject(env,project):
print('Update setting files for xmake.lua...')
xmake_project = XmakeProject(env, project)
xmake_project.set_toolchain_path()
xmake_project.set_target_config()
xmake_project.generate_xmake_file()
print('Done!')
return