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 2018/09/05 08:57:17 UTC
[GitHub] michal-narajowski closed pull request #207: Add support for
specifying C++ compiler flags
michal-narajowski closed pull request #207: Add support for specifying C++ compiler flags
URL: https://github.com/apache/mynewt-newt/pull/207
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/buildpackage.go b/newt/builder/buildpackage.go
index df4f9d70..c89e6fde 100644
--- a/newt/builder/buildpackage.go
+++ b/newt/builder/buildpackage.go
@@ -143,6 +143,9 @@ func (bpkg *BuildPackage) CompilerInfo(
ci.Cflags = bpkg.rpkg.Lpkg.PkgY.GetValStringSlice("pkg.cflags", settings)
expandFlags(ci.Cflags)
+ ci.CXXflags = bpkg.rpkg.Lpkg.PkgY.GetValStringSlice("pkg.cxxflags", settings)
+ expandFlags(ci.CXXflags)
+
ci.Lflags = bpkg.rpkg.Lpkg.PkgY.GetValStringSlice("pkg.lflags", settings)
expandFlags(ci.Lflags)
diff --git a/newt/builder/cmake.go b/newt/builder/cmake.go
index 34bc0f0e..31bebc2f 100644
--- a/newt/builder/cmake.go
+++ b/newt/builder/cmake.go
@@ -87,6 +87,8 @@ func CmakeSourceObjectWrite(w io.Writer, cj toolchain.CompilerJob, includeDirs *
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...)
}
extractIncludes(&compileFlags, includeDirs, &otherFlags)
@@ -187,13 +189,18 @@ 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...)
+
fmt.Fprintf(w, `set_property(TARGET %s APPEND_STRING
PROPERTY
COMPILE_FLAGS
"%s")`,
elfName,
- strings.Replace(strings.Join(append(c.GetCompilerInfo().Cflags,
- c.GetLocalCompilerInfo().Cflags...), " "), "\"", "\\\\\\\"", -1))
+ strings.Replace(strings.Join(flags, " "), "\"", "\\\\\\\"", -1))
fmt.Fprintln(w)
lFlags := append(c.GetCompilerInfo().Lflags, c.GetLocalCompilerInfo().Lflags...)
@@ -202,6 +209,7 @@ func (b *Builder) CMakeTargetWrite(w io.Writer, targetCompiler *toolchain.Compil
}
lFlags = append(lFlags, c.GetLocalCompilerInfo().Cflags...)
+ lFlags = append(lFlags, c.GetLocalCompilerInfo().CXXflags...)
fmt.Fprintf(w, `set_target_properties(%s
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY %s
diff --git a/newt/cli/target_cmds.go b/newt/cli/target_cmds.go
index e7a4d1a0..6afb84a7 100644
--- a/newt/cli/target_cmds.go
+++ b/newt/cli/target_cmds.go
@@ -44,10 +44,10 @@ var targetForce bool = false
var amendDelete bool = false
// target variables that can have values amended with the amend command.
-var amendVars = []string{"aflags", "cflags", "lflags", "syscfg"}
+var amendVars = []string{"aflags", "cflags", "cxxflags", "lflags", "syscfg"}
var setVars = []string{"aflags", "app", "build_profile", "bsp", "cflags",
- "lflags", "loader", "syscfg"}
+ "cxxflags", "lflags", "loader", "syscfg"}
func resolveExistingTargetArg(arg string) (*target.Target, error) {
t := ResolveTarget(arg)
@@ -123,7 +123,7 @@ func amendSysCfg(value string, t *target.Target) error {
return nil
}
-//Process amend command for aflags, cflags, and lflags target variables.
+//Process amend command for aflags, cflags, cxxflags, and lflags target variables.
func amendBuildFlags(kv []string, t *target.Target) error {
pkgVar := "pkg." + kv[0]
curFlags := t.Package().PkgY.GetValStringSlice(pkgVar, nil)
@@ -209,6 +209,7 @@ func targetShowCmd(cmd *cobra.Command, args []string) {
kvPairs["syscfg"] = syscfg.KeyValueToStr(
target.Package().SyscfgY.GetValStringMapString("syscfg.vals", nil))
kvPairs["cflags"] = pkgVarSliceString(target.Package(), "pkg.cflags")
+ kvPairs["cxxflags"] = pkgVarSliceString(target.Package(), "pkg.cxxflags")
kvPairs["lflags"] = pkgVarSliceString(target.Package(), "pkg.lflags")
kvPairs["aflags"] = pkgVarSliceString(target.Package(), "pkg.aflags")
@@ -309,6 +310,7 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
t.Package().SyscfgY.Replace("syscfg.vals", kv)
} else if kv[0] == "target.cflags" ||
+ kv[0] == "target.cxxflags" ||
kv[0] == "target.lflags" ||
kv[0] == "target.aflags" {
@@ -402,6 +404,7 @@ func targetAmendCmd(cmd *cobra.Command, args []string) {
NewtUsage(cmd, err)
}
} else if kv[0] == "cflags" ||
+ kv[0] == "cxxflags" ||
kv[0] == "lflags" ||
kv[0] == "aflags" {
err = amendBuildFlags(kv, t)
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index 899f1003..95320b05 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -268,6 +268,7 @@ func (pkg *LocalPackage) Save() error {
file.WriteString(pkg.sequenceString("pkg.aflags"))
file.WriteString(pkg.sequenceString("pkg.cflags"))
+ file.WriteString(pkg.sequenceString("pkg.cxxflags"))
file.WriteString(pkg.sequenceString("pkg.lflags"))
return nil
diff --git a/newt/toolchain/compiler.go b/newt/toolchain/compiler.go
index b5d1b458..96476b3f 100644
--- a/newt/toolchain/compiler.go
+++ b/newt/toolchain/compiler.go
@@ -54,6 +54,7 @@ const (
type CompilerInfo struct {
Includes []string
Cflags []string
+ CXXflags []string
Lflags []string
Aflags []string
IgnoreFiles []*regexp.Regexp
@@ -148,6 +149,7 @@ func NewCompilerInfo() *CompilerInfo {
ci := &CompilerInfo{}
ci.Includes = []string{}
ci.Cflags = []string{}
+ ci.CXXflags = []string{}
ci.Lflags = []string{}
ci.Aflags = []string{}
ci.IgnoreFiles = []*regexp.Regexp{}
@@ -227,6 +229,7 @@ func (ci *CompilerInfo) AddCflags(cflags []string) {
func (ci *CompilerInfo) AddCompilerInfo(newCi *CompilerInfo) {
ci.Includes = append(ci.Includes, newCi.Includes...)
ci.Cflags = addFlags("cflag", ci.Cflags, newCi.Cflags)
+ ci.CXXflags = addFlags("cxxflag", ci.CXXflags, newCi.CXXflags)
ci.Lflags = addFlags("lflag", ci.Lflags, newCi.Lflags)
ci.Aflags = addFlags("aflag", ci.Aflags, newCi.Aflags)
ci.IgnoreFiles = append(ci.IgnoreFiles, newCi.IgnoreFiles...)
@@ -295,6 +298,7 @@ func (c *Compiler) load(compilerDir string, buildProfile string) error {
c.ocPath = yc.GetValString("compiler.path.objcopy", settings)
c.lclInfo.Cflags = loadFlags(yc, settings, "compiler.flags")
+ c.lclInfo.CXXflags = loadFlags(yc, settings, "compiler.cxx.flags")
c.lclInfo.Lflags = loadFlags(yc, settings, "compiler.ld.flags")
c.lclInfo.Aflags = loadFlags(yc, settings, "compiler.as.flags")
@@ -376,6 +380,11 @@ func (c *Compiler) cflagsStrings() []string {
return cflags
}
+func (c *Compiler) cxxflagsStrings() []string {
+ cxxflags := util.SortFields(c.info.CXXflags...)
+ return cxxflags
+}
+
func (c *Compiler) aflagsStrings() []string {
aflags := util.SortFields(c.info.Aflags...)
return aflags
@@ -425,7 +434,7 @@ func (c *Compiler) CompileFileCmd(file string, compilerType int) (
flags = append(c.cflagsStrings(), c.aflagsStrings()...)
case COMPILER_TYPE_CPP:
cmdName = c.cppPath
- flags = c.cflagsStrings()
+ flags = append(c.cflagsStrings(), c.cxxflagsStrings()...)
default:
return nil, util.NewNewtError("Unknown compiler type")
}
----------------------------------------------------------------
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