Skip to content

Commit 9ab22de

Browse files
authored
[cbuild2cmake] Improve link libraries handling
1 parent fc328af commit 9ab22de

File tree

30 files changed

+1592
-22
lines changed

30 files changed

+1592
-22
lines changed

cmd/cbuild2cmake/commands/root_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,20 @@ set(OUTPUTS_1
255255
assert.False(mismatch)
256256
})
257257

258+
t.Run("test library rtos", func(t *testing.T) {
259+
cmd := commands.NewRootCmd()
260+
testCaseRoot := testRoot + "/run/solutions/library-rtos"
261+
cbuildIdxFile := testCaseRoot + "/solution.cbuild-idx.yml"
262+
cmd.SetArgs([]string{cbuildIdxFile, "--debug"})
263+
err := cmd.Execute()
264+
assert.Nil(err)
265+
266+
// check golden references
267+
err, mismatch := inittest.CompareFiles(testCaseRoot+"/ref", testCaseRoot+"/tmp")
268+
assert.Nil(err)
269+
assert.False(mismatch)
270+
})
271+
258272
t.Run("test executes", func(t *testing.T) {
259273
cmd := commands.NewRootCmd()
260274
testCaseRoot := testRoot + "/run/solutions/executes"

pkg/maker/contextlists.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (m *Maker) CreateContextCMakeLists(index int) error {
5858
// Libraries
5959
var libraries []string
6060
libraries = append(libraries, cbuild.ListGroupsAndComponents()...)
61-
libraries = append(libraries, cbuild.BuildDescType.Misc.Library...)
61+
libraries = append(libraries, cbuild.GetLinkLibraries()...)
6262

6363
// Linker options
6464
if outputType == "elf" {
@@ -141,7 +141,7 @@ add_library(${CONTEXT}_GLOBAL INTERFACE)
141141
# Add groups and components
142142
include("groups.cmake")
143143
include("components.cmake")
144-
` + cbuild.CMakeTargetLinkLibraries("${CONTEXT}", "PUBLIC", libraries...) + RescanLinkLibraries("${CONTEXT}", cbuild.Toolchain) + `
144+
` + cbuild.CMakeTargetLinkLibraries("${CONTEXT}", "PUBLIC", libraries...) + `
145145
` + linkerOptions + customCommands + `
146146
`
147147
// Update CMakeLists.txt
@@ -242,6 +242,7 @@ func (c *Cbuild) CMakeCreateGroupRecursively(parent string, groups []Groups,
242242
}
243243
// target_link_libraries
244244
libraries = append(libraries, buildFiles.Library...)
245+
c.LibraryGlobal = append(c.LibraryGlobal, buildFiles.Library...)
245246
libraries = append(libraries, buildFiles.Object...)
246247
if len(libraries) > 0 {
247248
content += c.CMakeTargetLinkLibraries(name, scope, libraries...)
@@ -328,6 +329,7 @@ func (c *Cbuild) CMakeCreateComponents(contextDir string) error {
328329
}
329330
// target_link_libraries
330331
libraries = append(libraries, buildFiles.Library...)
332+
c.LibraryGlobal = append(c.LibraryGlobal, buildFiles.Library...)
331333
libraries = append(libraries, buildFiles.Object...)
332334
if len(libraries) > 0 {
333335
content += c.CMakeTargetLinkLibraries(name, scope, libraries...)
@@ -351,11 +353,13 @@ func (c *Cbuild) CMakeCreateComponents(contextDir string) error {
351353
return err
352354
}
353355

354-
func RescanLinkLibraries(name string, compiler string) string {
355-
var content string
356-
if compiler == "GCC" {
357-
content += "\nget_target_property(LINK_LIBRARIES " + name + " LINK_LIBRARIES)"
358-
content += "\nset_target_properties(" + name + " PROPERTIES LINK_LIBRARIES \"-Wl,--start-group;${LINK_LIBRARIES};-Wl,--end-group\")"
356+
func (c *Cbuild) GetLinkLibraries() (libraries []string) {
357+
libraries = c.BuildDescType.Misc.Library
358+
// rescan libraries: special handling for GCC
359+
if c.Toolchain == "GCC" && (len(c.BuildDescType.Misc.Library)+len(c.LibraryGlobal)) > 1 {
360+
libraries = append(libraries, c.LibraryGlobal...)
361+
libraries = append([]string{"-Wl,--start-group"}, libraries...)
362+
libraries = append(libraries, "-Wl,--end-group")
359363
}
360-
return content
364+
return
361365
}

pkg/maker/parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type Cbuild struct {
7575
ContextRoot string
7676
Languages []string
7777
PreIncludeGlobal []string
78+
LibraryGlobal []string
7879
IncludeGlobal LanguageMap
7980
UserIncGlobal LanguageMap
8081
BuildGroups []string

test/data/solutions/build-asm/ref/project.GCC+ARMCM0/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ target_link_libraries(${CONTEXT} PUBLIC
6969
ARM_CMSIS_CORE_6_0_0
7070
ARM_Device_Startup_C_Startup_2_2_0
7171
)
72-
get_target_property(LINK_LIBRARIES ${CONTEXT} LINK_LIBRARIES)
73-
set_target_properties(${CONTEXT} PROPERTIES LINK_LIBRARIES "-Wl,--start-group;${LINK_LIBRARIES};-Wl,--end-group")
7472

7573
# Linker options
7674
target_link_options(${CONTEXT} PUBLIC

test/data/solutions/build-c/ref/project.GCC+ARMCM0/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ target_link_libraries(${CONTEXT} PUBLIC
6363
Group_Source
6464
ARM_CMSIS_CORE_6_0_0
6565
ARM_Device_Startup_C_Startup_2_2_0
66+
-Wl,--start-group
6667
-lm
6768
-lc
69+
-Wl,--end-group
6870
)
69-
get_target_property(LINK_LIBRARIES ${CONTEXT} LINK_LIBRARIES)
70-
set_target_properties(${CONTEXT} PROPERTIES LINK_LIBRARIES "-Wl,--start-group;${LINK_LIBRARIES};-Wl,--end-group")
7171

7272
# Linker options
7373
target_link_options(${CONTEXT} PUBLIC

test/data/solutions/build-cpp/ref/project.GCC+ARMCM55/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ target_link_libraries(${CONTEXT} PUBLIC
7676
ARM_CMSIS_CORE_6_0_0
7777
ARM_Device_Startup_C_Startup_2_2_0
7878
)
79-
get_target_property(LINK_LIBRARIES ${CONTEXT} LINK_LIBRARIES)
80-
set_target_properties(${CONTEXT} PROPERTIES LINK_LIBRARIES "-Wl,--start-group;${LINK_LIBRARIES};-Wl,--end-group")
8179

8280
# Linker options
8381
target_link_options(${CONTEXT} PUBLIC

test/data/solutions/include-define/ref/project.GCC+ARMCM0/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ target_link_libraries(${CONTEXT} PUBLIC
7878
ARM_CMSIS_CORE_6_0_0
7979
ARM_Device_Startup_C_Startup_2_2_0
8080
)
81-
get_target_property(LINK_LIBRARIES ${CONTEXT} LINK_LIBRARIES)
82-
set_target_properties(${CONTEXT} PROPERTIES LINK_LIBRARIES "-Wl,--start-group;${LINK_LIBRARIES};-Wl,--end-group")
8381

8482
# Linker options
8583
target_link_options(${CONTEXT} PUBLIC

test/data/solutions/language-scope/ref/project.GCC+ARMCM0/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ target_link_libraries(${CONTEXT} PUBLIC
7979
ARM_CMSIS_CORE_6_0_0
8080
ARM_Device_Startup_C_Startup_2_2_0
8181
ARM_RteTest_LanguageAndScope_0_9_9
82+
-Wl,--start-group
8283
-lm
8384
-lc
85+
-Wl,--end-group
8486
)
85-
get_target_property(LINK_LIBRARIES ${CONTEXT} LINK_LIBRARIES)
86-
set_target_properties(${CONTEXT} PROPERTIES LINK_LIBRARIES "-Wl,--start-group;${LINK_LIBRARIES};-Wl,--end-group")
8787

8888
# Linker options
8989
target_link_options(${CONTEXT} PUBLIC
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "RTE_Components.h"
2+
#include CMSIS_device_header
3+
#include "cmsis_os2.h"
4+
5+
int main(void) {
6+
osKernelInitialize(); // Initialize CMSIS-RTOS2
7+
osKernelStart(); // Start thread execution
8+
return 0;
9+
}
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
build:
2+
generated-by: csolution version 2.5.0
3+
solution: ../solution.csolution.yml
4+
project: project.cproject.yml
5+
context: project.AC6+ARMCM0
6+
compiler: AC6
7+
device: ARMCM0
8+
device-pack: ARM::[email protected]
9+
processor:
10+
fpu: off
11+
core: Cortex-M0
12+
packs:
13+
- pack: ARM::[email protected]
14+
path: ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0
15+
- pack: ARM::[email protected]
16+
path: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0
17+
- pack: ARM::[email protected]
18+
path: ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.1.0
19+
misc:
20+
ASM:
21+
- -masm=auto
22+
C:
23+
- -std=gnu11
24+
- -Wno-macro-redefined
25+
- -Wno-pragma-pack
26+
- -Wno-parentheses-equality
27+
- -Wno-license-management
28+
CPP:
29+
- -Wno-macro-redefined
30+
- -Wno-pragma-pack
31+
- -Wno-parentheses-equality
32+
- -Wno-license-management
33+
Link:
34+
- --entry=Reset_Handler
35+
- --map
36+
- --info summarysizes
37+
- --summary_stderr
38+
- --diag_suppress=L6314W
39+
define:
40+
- ARMCM0
41+
- _RTE_
42+
define-asm:
43+
- ARMCM0
44+
- _RTE_
45+
add-path:
46+
- RTE/CMSIS
47+
- RTE/_AC6_ARMCM0
48+
- ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0/Include
49+
- ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Include
50+
- ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/RTOS2/Include
51+
- ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.1.0/Device/ARMCM0/Include
52+
add-path-asm:
53+
- RTE/CMSIS
54+
- RTE/_AC6_ARMCM0
55+
- ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0/Include
56+
- ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Include
57+
- ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/RTOS2/Include
58+
- ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.1.0/Device/ARMCM0/Include
59+
output-dirs:
60+
intdir: ../tmp
61+
outdir: ../out/project/ARMCM0/AC6
62+
rtedir: RTE
63+
output:
64+
- type: elf
65+
file: project.axf
66+
components:
67+
- component: ARM::CMSIS:[email protected]
68+
condition: ARMv6_7_8-M Device
69+
from-pack: ARM::[email protected]
70+
selected-by: ARM::CMSIS:CORE
71+
files:
72+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Include
73+
category: include
74+
version: 6.1.0
75+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Include/tz_context.h
76+
category: header
77+
version: 6.1.0
78+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Template/ARMv8-M/main_s.c
79+
category: sourceC
80+
attr: template
81+
version: 1.1.1
82+
select: Secure mode 'main' module for ARMv8-M
83+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Core/Template/ARMv8-M/tz_context.c
84+
category: sourceC
85+
attr: template
86+
version: 1.1.1
87+
select: RTOS Context Management (TrustZone for ARMv8-M)
88+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/Documentation/html/Core/index.html
89+
category: doc
90+
version: 6.1.0
91+
- component: ARM::CMSIS:OS Tick:[email protected]
92+
condition: OS Tick SysTick
93+
from-pack: ARM::[email protected]
94+
selected-by: ARM::CMSIS:OS Tick
95+
files:
96+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/RTOS2/Include/os_tick.h
97+
category: api
98+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/RTOS2/Source/os_systick.c
99+
category: sourceC
100+
version: 1.0.5
101+
- component: ARM::CMSIS:RTOS2:Keil RTX5&[email protected]
102+
condition: RTX5
103+
from-pack: ARM::[email protected]
104+
selected-by: ARM::CMSIS:RTOS2:Keil RTX5&Library
105+
files:
106+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS/6.1.0/CMSIS/RTOS2/Include/cmsis_os2.h
107+
category: api
108+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0/Documentation/index.html
109+
category: doc
110+
version: 5.9.0
111+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0/Include/rtx_os.h
112+
category: header
113+
version: 5.9.0
114+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0/Library/ARM/RTX_V6M.lib
115+
category: library
116+
version: 5.9.0
117+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0/RTX5.scvd
118+
category: other
119+
version: 5.9.0
120+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0/Source/rtx_lib.c
121+
category: source
122+
version: 5.9.0
123+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0/Template/Events.c
124+
category: source
125+
attr: template
126+
version: 2.0.0
127+
select: RTX Events
128+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0/Template/MemPool.c
129+
category: source
130+
attr: template
131+
version: 2.0.0
132+
select: RTX Memory Pool
133+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0/Template/MsgQueue.c
134+
category: source
135+
attr: template
136+
version: 2.0.0
137+
select: RTX Message Queue
138+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0/Template/Mutex.c
139+
category: source
140+
attr: template
141+
version: 2.0.0
142+
select: RTX Mutex
143+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0/Template/Semaphore.c
144+
category: source
145+
attr: template
146+
version: 2.0.0
147+
select: RTX Semaphore
148+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0/Template/Thread.c
149+
category: source
150+
attr: template
151+
version: 2.0.0
152+
select: RTX Thread
153+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0/Template/Timer.c
154+
category: source
155+
attr: template
156+
version: 2.0.1
157+
select: RTX Timer
158+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0/Template/main.c
159+
category: source
160+
attr: template
161+
version: 2.1.0
162+
select: RTX 'main' function
163+
- file: ${CMSIS_PACK_ROOT}/ARM/CMSIS-RTX/5.9.0/Template/svc_user.c
164+
category: source
165+
attr: template
166+
version: 1.0.0
167+
select: RTX SVC User Table
168+
- file: RTE/CMSIS/RTX_Config.c
169+
category: source
170+
attr: config
171+
version: 5.2.0
172+
- file: RTE/CMSIS/RTX_Config.h
173+
category: header
174+
attr: config
175+
version: 5.6.0
176+
- component: ARM::Device:Startup&C [email protected]
177+
condition: ARMCM0 CMSIS
178+
from-pack: ARM::[email protected]
179+
selected-by: ARM::Device:Startup&C Startup
180+
files:
181+
- file: ${CMSIS_PACK_ROOT}/ARM/Cortex_DFP/1.1.0/Device/ARMCM0/Include/ARMCM0.h
182+
category: header
183+
version: 2.2.0
184+
- file: RTE/Device/ARMCM0/ARMCM0_ac6.sct
185+
category: linkerScript
186+
attr: config
187+
version: 1.0.0
188+
- file: RTE/Device/ARMCM0/startup_ARMCM0.c
189+
category: sourceC
190+
attr: config
191+
version: 2.0.3
192+
- file: RTE/Device/ARMCM0/system_ARMCM0.c
193+
category: sourceC
194+
attr: config
195+
version: 1.0.0
196+
linker:
197+
script: RTE/Device/ARMCM0/ARMCM0_ac6.sct
198+
groups:
199+
- group: Source
200+
files:
201+
- file: main.c
202+
category: sourceC
203+
constructed-files:
204+
- file: RTE/_AC6_ARMCM0/RTE_Components.h
205+
category: header
206+
licenses:
207+
- license: Apache-2.0
208+
packs:
209+
- pack: ARM::[email protected]
210+
- pack: ARM::[email protected]
211+
- pack: ARM::[email protected]
212+
components:
213+
- component: ::CMSIS:OS Tick(API)
214+
- component: ::CMSIS:RTOS2(API)
215+
- component: ARM::CMSIS:[email protected]
216+
- component: ARM::CMSIS:OS Tick:[email protected]
217+
- component: ARM::CMSIS:RTOS2:Keil RTX5&[email protected]
218+
- component: ARM::Device:Startup&C [email protected]

0 commit comments

Comments
 (0)