michal-narajowski closed pull request #191: Cmake fixes URL: https://github.com/apache/mynewt-newt/pull/191
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/newt/builder/cmake.go b/newt/builder/cmake.go index 5c30a47f..cbaa036f 100644 --- a/newt/builder/cmake.go +++ b/newt/builder/cmake.go @@ -69,25 +69,6 @@ func extractIncludes(flags *[]string, includes *[]string, other *[]string) { } } -func removeDuplicates(elements []string) []string { - // Use map to record duplicates as we find them. - encountered := map[string]bool{} - result := []string{} - - for v := range elements { - if encountered[elements[v]] == true { - // Do not add duplicate. - } else { - // Record this element as an encountered element. - encountered[elements[v]] = true - // Append to result slice. - result = append(result, elements[v]) - } - } - // Return the new slice. - return result -} - func CmakeSourceObjectWrite(w io.Writer, cj toolchain.CompilerJob, includeDirs *[]string) { c := cj.Compiler @@ -111,6 +92,9 @@ func CmakeSourceObjectWrite(w io.Writer, cj toolchain.CompilerJob, includeDirs * extractIncludes(&compileFlags, includeDirs, &otherFlags) cj.Filename = trimProjectPath(cj.Filename) + // Sort and remove duplicate flags + otherFlags = util.SortFields(otherFlags...) + fmt.Fprintf(w, `set_property(SOURCE %s APPEND_STRING PROPERTY COMPILE_FLAGS @@ -229,7 +213,7 @@ func (b *Builder) CMakeTargetWrite(w io.Writer, targetCompiler *toolchain.Compil elfOutputDir, elfOutputDir, elfOutputDir, - strings.Join(lFlags, " ")) + strings.Replace(strings.Join(lFlags, " "), "\"", "\\\\\\\"", -1)) fmt.Fprintln(w) @@ -263,7 +247,8 @@ func CmakeCompilerInfoWrite(w io.Writer, archiveFile string, bpkg *BuildPackage, includes = append(includes, c.GetLocalCompilerInfo().Includes...) includes = append(includes, otherIncludes...) - includes = removeDuplicates(includes) + // Sort and remove duplicate flags + includes = util.SortFields(includes...) trimProjectPathSlice(includes) fmt.Fprintf(w, `set_target_properties(%s ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services