Skip to content

Commit 36834ef

Browse files
committed
scons: Add CodeLite target
1 parent 3ff0c07 commit 36834ef

File tree

4 files changed

+286
-2
lines changed

4 files changed

+286
-2
lines changed

tools/building.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
208208
AddOption('--target',
209209
dest = 'target',
210210
type = 'string',
211-
help = 'set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk/ses/makefile/eclipse')
211+
help = 'set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk/ses/makefile/eclipse/codelite')
212212
AddOption('--stackanalysis',
213213
dest = 'stackanalysis',
214214
action = 'store_true',
@@ -256,7 +256,8 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
256256
'cdk':('gcc', 'gcc'),
257257
'makefile':('gcc', 'gcc'),
258258
'eclipse':('gcc', 'gcc'),
259-
'ses' : ('gcc', 'gcc')}
259+
'ses' : ('gcc', 'gcc'),
260+
'codelite' : ('gcc', 'gcc')}
260261
tgt_name = GetOption('target')
261262

262263
if tgt_name:
@@ -872,6 +873,10 @@ def GenTargetProject(program = None):
872873
if GetOption('target') == 'eclipse':
873874
from eclipse import TargetEclipse
874875
TargetEclipse(Env, GetOption('reset-project-config'), GetOption('project-name'))
876+
877+
if GetOption('target') == 'codelite':
878+
from codelite import TargetCodelite
879+
TargetCodelite(Projects, program)
875880

876881

877882
def EndBuilding(target, program = None):

tools/codelite.py

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
#
2+
# File : codelite.py
3+
# This file is part of RT-Thread RTOS
4+
# COPYRIGHT (C) 2006 - 2020, RT-Thread Development Team
5+
#
6+
# This program is free software; you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation; either version 2 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License along
17+
# with this program; if not, write to the Free Software Foundation, Inc.,
18+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
#
20+
# Change Logs:
21+
# Date Author Notes
22+
# 2020-10-14 LiuMin Add copyright information
23+
#
24+
25+
import os
26+
import sys
27+
import string
28+
import building
29+
import rtconfig
30+
31+
import xml.etree.ElementTree as etree
32+
from xml.etree.ElementTree import SubElement
33+
from utils import _make_path_relative
34+
from utils import xml_indent
35+
36+
import utils
37+
38+
fs_encoding = sys.getfilesystemencoding()
39+
40+
def CLSetCFlags(root, flags):
41+
node = root.find('Settings').find('Configuration').find('Compiler')
42+
node.attrib['C_Options'] = flags
43+
44+
def CLSetCxxFlags(root, flags):
45+
node = root.find('Settings').find('Configuration').find('Compiler')
46+
node.attrib['Options'] = flags
47+
48+
def CLSetAsFlags(root, flags):
49+
node = root.find('Settings').find('Configuration').find('Compiler')
50+
node.attrib['Assembler'] = flags
51+
52+
def CLAddIncludePath(root, path):
53+
node = root.find('Settings').find('Configuration').find('Compiler')
54+
node = SubElement(node, 'IncludePath')
55+
node.attrib['Value'] = path
56+
57+
def CLAddPreprocessor(root, value):
58+
node = root.find('Settings').find('Configuration').find('Compiler')
59+
node = SubElement(node, 'Preprocessor')
60+
node.attrib['Value'] = value
61+
62+
63+
def CLSetLdFlags(root, flags):
64+
node = root.find('Settings').find('Configuration').find('Linker')
65+
node.attrib['Options'] = flags
66+
67+
def CLAddLibrary_path(root, path):
68+
node = root.find('Settings').find('Configuration').find('Linker')
69+
node = SubElement(node, 'LibraryPath')
70+
node.attrib['Value'] = path
71+
72+
def CLAddLibrary(root, lib):
73+
node = root.find('Settings').find('Configuration').find('Linker')
74+
node = SubElement(node, 'Library')
75+
node.attrib['Value'] = lib
76+
77+
def CLAddFile(root, file_path):
78+
file_path = file_path.replace('\\', '/')
79+
80+
dir_list = file_path.split('/')
81+
dir_list.pop()
82+
if not len(dir_list):
83+
dir_list.append(os.path.abspath('.').replace('\\', '/').split('/')[-1])
84+
85+
parent = root
86+
for dir_name in dir_list:
87+
if dir_name == '..':
88+
continue
89+
90+
node = None
91+
nodes = parent.findall('VirtualDirectory')
92+
for iter in nodes:
93+
if iter.attrib['Name'] == dir_name:
94+
node = iter
95+
break
96+
if node is None:
97+
node = SubElement(parent, 'VirtualDirectory')
98+
node.attrib['Name'] = dir_name
99+
parent = node
100+
101+
if parent != root:
102+
node = SubElement(parent, 'File')
103+
node.attrib['Name'] = file_path
104+
105+
def CLAddHeaderFiles(parent, program, project_path):
106+
utils.source_ext = []
107+
utils.source_ext = ["h"]
108+
for item in program:
109+
utils.walk_children(item)
110+
utils.source_list.sort()
111+
112+
for f in utils.source_list:
113+
path = _make_path_relative(project_path, f)
114+
CLAddFile(parent, path)
115+
116+
def CLAddCFiles(parent, files, project_path):
117+
for f in files:
118+
fn = f.rfile()
119+
name = fn.name
120+
path = os.path.dirname(fn.abspath)
121+
122+
path = _make_path_relative(project_path, path)
123+
path = os.path.join(path, name)
124+
CLAddFile(parent, path)
125+
126+
127+
128+
def CLGenWorkspace(project_name, project_path):
129+
if os.path.isfile('template.workspace'):
130+
tree = etree.parse('template.workspace')
131+
else:
132+
tree = etree.parse(os.path.join(os.path.dirname(__file__), 'template.workspace'))
133+
134+
root = tree.getroot()
135+
root.attrib['Name'] = project_name
136+
137+
node = root.find('Project')
138+
node.attrib['Name'] = project_name
139+
node.attrib['Path'] = project_name + '.project'
140+
141+
node = root.find('BuildMatrix').find('WorkspaceConfiguration').find('Project')
142+
node.attrib['Name'] = project_name
143+
144+
out = open(project_name + '.workspace', 'w')
145+
out.write('<?xml version="1.0" encoding="UTF-8"?>\n')
146+
xml_indent(root)
147+
out.write(etree.tostring(root, encoding='utf-8'))
148+
out.close()
149+
150+
def TargetCodelite(script, program):
151+
project_name = os.path.abspath('.').replace('\\', '/').split('/')[-1]
152+
#project_name.replace('-', '_')
153+
project_path = os.path.abspath('.')
154+
CLGenWorkspace(project_name, project_path)
155+
156+
if os.path.isfile('template.project'):
157+
tree = etree.parse('template.project')
158+
else:
159+
tree = etree.parse(os.path.join(os.path.dirname(__file__), 'template.project'))
160+
161+
root = tree.getroot()
162+
root.attrib['Name'] = project_name
163+
164+
out = open(project_name + '.project', 'w')
165+
out.write('<?xml version="1.0" encoding="UTF-8"?>\n')
166+
167+
# add files
168+
for group in script:
169+
CLAddCFiles(root, group['src'], project_path)
170+
# add header file
171+
CLAddHeaderFiles(root, program, project_path)
172+
173+
# SECTION 2.
174+
# write head include path
175+
176+
if 'CPPPATH' in building.Env:
177+
cpp_path = building.Env['CPPPATH']
178+
paths = set()
179+
for path in cpp_path:
180+
inc = _make_path_relative(project_path, os.path.normpath(path))
181+
paths.add(inc) #.replace('\\', '/')
182+
183+
paths = [i for i in paths]
184+
paths.sort()
185+
186+
# write include path, definitions
187+
for elem in tree.iter(tag='Compiler'):
188+
break
189+
190+
for path in paths:
191+
CLAddIncludePath(root, path)
192+
193+
194+
#print building.Env.get('LIBPATH', [])
195+
#print building.Env.get('LIBS', [])
196+
197+
CLSetCFlags(root, building.Env.get('CCFLAGS', []))
198+
CLSetCxxFlags(root, building.Env.get('CCFLAGS', []))
199+
CLSetAsFlags(root, building.Env.get('ASFLAGS', []))
200+
CLSetLdFlags(root, building.Env.get('LINKFLAGS', []))
201+
202+
for macro in building.Env.get('CPPDEFINES', []):
203+
for d in macro:
204+
CLAddPreprocessor(root, d)
205+
206+
xml_indent(root)
207+
out.write(etree.tostring(root, encoding='utf-8'))
208+
out.close()

tools/template.project

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CodeLite_Project Name="project" Version="11000" InternalType="">
3+
<Description/>
4+
<Dependencies/>
5+
<Settings Type="Executable">
6+
<GlobalSettings>
7+
<Compiler Options="" C_Options="" Assembler="">
8+
<IncludePath Value="."/>
9+
</Compiler>
10+
<Linker Options="">
11+
<LibraryPath Value="."/>
12+
</Linker>
13+
<ResourceCompiler Options=""/>
14+
</GlobalSettings>
15+
<Configuration Name="Debug" CompilerType="Cross GCC ( arm-none-eabi )" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
16+
<Compiler Options="" C_Options="" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
17+
</Compiler>
18+
<Linker Options="" Required="yes">
19+
</Linker>
20+
<ResourceCompiler Options="" Required="no"/>
21+
<General OutputFile="$(IntermediateDirectory)/$(ProjectName).elf" IntermediateDirectory="$(ConfigurationName)" Command="$(OutputFile)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
22+
<BuildSystem Name="Default"/>
23+
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
24+
<![CDATA[]]>
25+
</Environment>
26+
<Debugger IsRemote="yes" RemoteHostName="127.0.0.1" RemoteHostPort="2331" DebuggerPath="" IsExtended="no">
27+
<DebuggerSearchPaths/>
28+
<PostConnectCommands>monitor reset
29+
monitor halt
30+
load</PostConnectCommands>
31+
<StartupCommands/>
32+
</Debugger>
33+
<PreBuild/>
34+
<PostBuild>
35+
<Command Enabled="yes">arm-none-eabi-objcopy -O ihex $(IntermediateDirectory)/$(ProjectName).elf $(IntermediateDirectory)/$(ProjectName).hex</Command>
36+
<Command Enabled="yes">arm-none-eabi-objcopy -I ihex -O binary $(IntermediateDirectory)/$(ProjectName).hex $(IntermediateDirectory)/$(ProjectName).bin</Command>
37+
<Command Enabled="yes">arm-none-eabi-size $(IntermediateDirectory)/$(ProjectName).elf</Command>
38+
</PostBuild>
39+
<CustomBuild Enabled="no">
40+
<RebuildCommand/>
41+
<CleanCommand/>
42+
<BuildCommand/>
43+
<PreprocessFileCommand/>
44+
<SingleFileCommand/>
45+
<MakefileGenerationCommand/>
46+
<ThirdPartyToolName/>
47+
<WorkingDirectory/>
48+
</CustomBuild>
49+
<AdditionalRules>
50+
<CustomPostBuild/>
51+
<CustomPreBuild/>
52+
</AdditionalRules>
53+
<Completion EnableCpp11="no" EnableCpp14="no">
54+
<ClangCmpFlagsC/>
55+
<ClangCmpFlags/>
56+
<ClangPP/>
57+
<SearchPaths/>
58+
</Completion>
59+
</Configuration>
60+
</Settings>
61+
</CodeLite_Project>

tools/template.workspace

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CodeLite_Workspace Name="project" Database="" Version="10000">
3+
<Project Name="project" Path="project.project" Active="Yes"/>
4+
<BuildMatrix>
5+
<WorkspaceConfiguration Name="Debug" Selected="yes">
6+
<Environment/>
7+
<Project Name="project" ConfigName="Debug"/>
8+
</WorkspaceConfiguration>
9+
</BuildMatrix>
10+
</CodeLite_Workspace>

0 commit comments

Comments
 (0)