You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2019/01/02 10:41:53 UTC

[GitHub] michal-narajowski closed pull request #251: cmake: Include Builder Compiler Info and lflags from build packages

michal-narajowski closed pull request #251: cmake: Include Builder Compiler Info and lflags from build packages
URL: https://github.com/apache/mynewt-newt/pull/251
 
 
   

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/build.go b/newt/builder/build.go
index 9db22135..e0171f28 100644
--- a/newt/builder/build.go
+++ b/newt/builder/build.go
@@ -721,6 +721,10 @@ func (b *Builder) FetchSymbolMap() (error, *symbol.SymbolMap) {
 	return nil, loaderSm
 }
 
+func (b *Builder) GetCompilerInfo() *toolchain.CompilerInfo {
+	return b.compilerInfo
+}
+
 func (b *Builder) GetTarget() *target.Target {
 	return b.targetBuilder.GetTarget()
 }
diff --git a/newt/builder/cmake.go b/newt/builder/cmake.go
index b1f6da79..58a241a9 100644
--- a/newt/builder/cmake.go
+++ b/newt/builder/cmake.go
@@ -69,29 +69,33 @@ func extractIncludes(flags *[]string, includes *[]string, other *[]string) {
 	}
 }
 
-func CmakeSourceObjectWrite(w io.Writer, cj toolchain.CompilerJob, includeDirs *[]string) {
+func CmakeSourceObjectWrite(w io.Writer, cj toolchain.CompilerJob,
+	includeDirs *[]string, linkFlags *[]string) {
 	c := cj.Compiler
 
-	compileFlags := []string{}
+	flags := []string{}
 	otherFlags := []string{}
 
 	switch cj.CompilerType {
 	case toolchain.COMPILER_TYPE_C:
-		compileFlags = append(compileFlags, c.GetCompilerInfo().Cflags...)
-		compileFlags = append(compileFlags, c.GetLocalCompilerInfo().Cflags...)
+		flags = append(flags, c.GetCompilerInfo().Cflags...)
+		flags = append(flags, c.GetLocalCompilerInfo().Cflags...)
 	case toolchain.COMPILER_TYPE_ASM:
-		compileFlags = append(compileFlags, c.GetCompilerInfo().Cflags...)
-		compileFlags = append(compileFlags, c.GetLocalCompilerInfo().Cflags...)
-		compileFlags = append(compileFlags, c.GetCompilerInfo().Aflags...)
-		compileFlags = append(compileFlags, c.GetLocalCompilerInfo().Aflags...)
+		flags = append(flags, c.GetCompilerInfo().Cflags...)
+		flags = append(flags, c.GetLocalCompilerInfo().Cflags...)
+		flags = append(flags, c.GetCompilerInfo().Aflags...)
+		flags = append(flags, c.GetLocalCompilerInfo().Aflags...)
 	case toolchain.COMPILER_TYPE_CPP:
-		compileFlags = append(compileFlags, c.GetCompilerInfo().Cflags...)
-		compileFlags = append(compileFlags, c.GetLocalCompilerInfo().Cflags...)
-		compileFlags = append(compileFlags, c.GetCompilerInfo().CXXflags...)
-		compileFlags = append(compileFlags, c.GetLocalCompilerInfo().CXXflags...)
+		flags = append(flags, c.GetCompilerInfo().Cflags...)
+		flags = append(flags, c.GetLocalCompilerInfo().Cflags...)
+		flags = append(flags, c.GetCompilerInfo().CXXflags...)
+		flags = append(flags, c.GetLocalCompilerInfo().CXXflags...)
 	}
 
-	extractIncludes(&compileFlags, includeDirs, &otherFlags)
+	*linkFlags = append(*linkFlags, c.GetCompilerInfo().Lflags...)
+	*linkFlags = append(*linkFlags, c.GetLocalCompilerInfo().Lflags...)
+
+	extractIncludes(&flags, includeDirs, &otherFlags)
 	cj.Filename = trimProjectPath(cj.Filename)
 
 	// Sort and remove duplicate flags
@@ -106,7 +110,8 @@ func CmakeSourceObjectWrite(w io.Writer, cj toolchain.CompilerJob, includeDirs *
 	fmt.Fprintln(w)
 }
 
-func (b *Builder) CMakeBuildPackageWrite(w io.Writer, bpkg *BuildPackage) (*BuildPackage, error) {
+func (b *Builder) CMakeBuildPackageWrite(w io.Writer, bpkg *BuildPackage,
+	linkFlags *[]string) (*BuildPackage, error) {
 	entries, err := b.collectCompileEntriesBpkg(bpkg)
 	if err != nil {
 		return nil, err
@@ -126,7 +131,7 @@ func (b *Builder) CMakeBuildPackageWrite(w io.Writer, bpkg *BuildPackage) (*Buil
 			continue
 		}
 
-		CmakeSourceObjectWrite(w, s, &otherIncludes)
+		CmakeSourceObjectWrite(w, s, &otherIncludes, linkFlags)
 		s.Filename = trimProjectPath(s.Filename)
 		files = append(files, s.Filename)
 	}
@@ -152,12 +157,15 @@ func (b *Builder) CMakeBuildPackageWrite(w io.Writer, bpkg *BuildPackage) (*Buil
 
 func (b *Builder) CMakeTargetWrite(w io.Writer, targetCompiler *toolchain.Compiler) error {
 	bpkgs := b.sortedBuildPackages()
+	var compileFlags []string
+	var linkFlags []string
 
 	c := targetCompiler
+	c.AddInfo(b.GetCompilerInfo())
 
 	builtPackages := []*BuildPackage{}
 	for _, bpkg := range bpkgs {
-		builtPackage, err := b.CMakeBuildPackageWrite(w, bpkg)
+		builtPackage, err := b.CMakeBuildPackageWrite(w, bpkg, &linkFlags)
 		if err != nil {
 			return err
 		}
@@ -189,27 +197,40 @@ func (b *Builder) CMakeTargetWrite(w io.Writer, targetCompiler *toolchain.Compil
 			elfName, targetObjectsBuffer.String())
 	}
 
-	var flags []string
-	flags = append(flags, c.GetCompilerInfo().Cflags...)
-	flags = append(flags, c.GetLocalCompilerInfo().Cflags...)
-	flags = append(flags, c.GetCompilerInfo().CXXflags...)
-	flags = append(flags, c.GetLocalCompilerInfo().CXXflags...)
+	compileFlags = append(compileFlags, c.GetCompilerInfo().Cflags...)
+	compileFlags = append(compileFlags, c.GetLocalCompilerInfo().Cflags...)
+	compileFlags = append(compileFlags, c.GetCompilerInfo().CXXflags...)
+	compileFlags = append(compileFlags, c.GetLocalCompilerInfo().CXXflags...)
+	compileFlags = util.SortFields(compileFlags...)
 
 	fmt.Fprintf(w, `set_property(TARGET %s APPEND_STRING
 														PROPERTY
 														COMPILE_FLAGS
 														"%s")`,
 		elfName,
-		strings.Replace(strings.Join(flags, " "), "\"", "\\\\\\\"", -1))
+		strings.Replace(strings.Join(compileFlags, " "), "\"", "\\\\\\\"", -1))
 	fmt.Fprintln(w)
 
 	lFlags := append(c.GetCompilerInfo().Lflags, c.GetLocalCompilerInfo().Lflags...)
+	lFlags = append(lFlags, linkFlags...)
+	lFlags = util.SortFields(lFlags...)
+
 	for _, ld := range c.LinkerScripts {
 		lFlags = append(lFlags, "-T"+ld)
 	}
 
-	lFlags = append(lFlags, c.GetLocalCompilerInfo().Cflags...)
-	lFlags = append(lFlags, c.GetLocalCompilerInfo().CXXflags...)
+	var cFlags []string
+	cFlags = append(cFlags, c.GetCompilerInfo().Cflags...)
+	cFlags = append(cFlags, c.GetLocalCompilerInfo().Cflags...)
+	cFlags = util.SortFields(cFlags...)
+	lFlags = append(lFlags, cFlags...)
+
+	var cxxFlags []string
+	cxxFlags = append(cxxFlags, c.GetCompilerInfo().CXXflags...)
+	cxxFlags = append(cxxFlags, c.GetLocalCompilerInfo().CXXflags...)
+	cxxFlags = util.SortFields(cxxFlags...)
+	lFlags = append(lFlags, cxxFlags...)
+
 	fmt.Fprintf(w, `set_target_properties(%s
 							PROPERTIES
 							ARCHIVE_OUTPUT_DIRECTORY %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:
users@infra.apache.org


With regards,
Apache Git Services