Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions pkg/maker/buildcontent.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func (c *Cbuild) CMakeTargetLinkLibrariesGlobal() string {

// set content
for _, library := range libraries {
content += "\n " + library
content += "\n " + quoteEntry(library)
}
content += "\n)"
return content
Expand All @@ -398,12 +398,27 @@ func (c *Cbuild) CMakeTargetLinkLibrariesGlobal() string {
func (c *Cbuild) CMakeTargetLinkLibraries(name string, scope string, libraries ...string) string {
content := "\ntarget_link_libraries(" + name + " " + scope
for _, library := range libraries {
content += "\n " + library
content += "\n " + quoteEntry(library)
}
content += "\n)"
return content
}

func quoteEntry(entry string) string {
trimmed := strings.TrimLeft(entry, " ")
if len(trimmed) == 0 {
return entry
}
if !strings.Contains(trimmed, " ") {
return entry
}
leadingSpaces := entry[:len(entry)-len(trimmed)]
if strings.HasPrefix(trimmed, "\"") && strings.HasSuffix(trimmed, "\"") {
return entry
}
return leadingSpaces + "\"" + trimmed + "\""
}

func (c *Cbuild) CMakeTargetCompileOptions(name string, scope string, lto bool, misc Misc, preIncludes []string, parent string) string {
content := "\ntarget_compile_options(" + name + " " + scope
content += "\n $<TARGET_PROPERTY:" + parent + ",INTERFACE_COMPILE_OPTIONS>"
Expand Down
14 changes: 14 additions & 0 deletions pkg/maker/buildcontent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,20 @@ add_dependencies(project.debug+target-executes
assert.Contains(linkerOptions, "--linkCPP-flag")
})

t.Run("test quote link libraries with spaces", func(t *testing.T) {
var cbuild maker.Cbuild
content := cbuild.CMakeTargetLinkLibraries("TARGET", "PUBLIC",
"libnospace.a",
" libnospace2.a",
" C:/Program Files/vendor/lib with spaces.a",
" \"C:/Program Files/vendor/already quoted.a\"")

assert.Contains(content, "\n libnospace.a")
assert.Contains(content, "\n libnospace2.a")
assert.Contains(content, "\n \"C:/Program Files/vendor/lib with spaces.a\"")
assert.Contains(content, "\n \"C:/Program Files/vendor/already quoted.a\"")
})

t.Run("test linker options with pre-processing", func(t *testing.T) {
var cbuild maker.Cbuild
define := make([]interface{}, 1)
Expand Down
1 change: 1 addition & 0 deletions test/data/solutions/blanks/project/libr ary.a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Dummy */
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ build:
files:
- file: main.c
category: sourceC
- file: libr ary.a
category: library
constructed-files:
- file: RTE/_AC6_X_ARMCM0_X/RTE_Components.h
category: header
Expand Down
1 change: 1 addition & 0 deletions test/data/solutions/blanks/project/project X.cproject.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ project:
- group: Source
files:
- file: ./main.c
- file: ./libr ary.a
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ target_link_libraries(${CONTEXT} PUBLIC
Group_Source
ARM_CMSIS_CORE_6_1_0
ARM_Device_Startup_C_Startup_2_2_0
"${SOLUTION_ROOT}/project/libr ary.a"
)

# Linker options
Expand Down
Loading