@@ -389,7 +389,7 @@ func (c *Cbuild) CMakeTargetLinkLibrariesGlobal() string {
389389
390390 // set content
391391 for _ , library := range libraries {
392- content += "\n " + library
392+ content += "\n " + quoteEntry ( library )
393393 }
394394 content += "\n )"
395395 return content
@@ -398,12 +398,27 @@ func (c *Cbuild) CMakeTargetLinkLibrariesGlobal() string {
398398func (c * Cbuild ) CMakeTargetLinkLibraries (name string , scope string , libraries ... string ) string {
399399 content := "\n target_link_libraries(" + name + " " + scope
400400 for _ , library := range libraries {
401- content += "\n " + library
401+ content += "\n " + quoteEntry ( library )
402402 }
403403 content += "\n )"
404404 return content
405405}
406406
407+ func quoteEntry (entry string ) string {
408+ trimmed := strings .TrimLeft (entry , " " )
409+ if len (trimmed ) == 0 {
410+ return entry
411+ }
412+ if ! strings .Contains (trimmed , " " ) {
413+ return entry
414+ }
415+ leadingSpaces := entry [:len (entry )- len (trimmed )]
416+ if strings .HasPrefix (trimmed , "\" " ) && strings .HasSuffix (trimmed , "\" " ) {
417+ return entry
418+ }
419+ return leadingSpaces + "\" " + trimmed + "\" "
420+ }
421+
407422func (c * Cbuild ) CMakeTargetCompileOptions (name string , scope string , lto bool , misc Misc , preIncludes []string , parent string ) string {
408423 content := "\n target_compile_options(" + name + " " + scope
409424 content += "\n $<TARGET_PROPERTY:" + parent + ",INTERFACE_COMPILE_OPTIONS>"
0 commit comments