Skip to content

Commit 3d129c1

Browse files
committed
Fix cmake generation for difficult targets
1 parent a1c0431 commit 3d129c1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Diff for: src/arduino.cc/builder/create_cmake_rule.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
8585
if _, err := os.Stat(filepath.Join(libFolder, "examples")); err == nil {
8686
os.RemoveAll(filepath.Join(libFolder, "examples"))
8787
}
88+
// Remove stray folders contining incompatible libraries
89+
staticLibsExtensions := func(ext string) bool { return DOTAEXTENSION[ext] }
90+
mcu := ctx.BuildProperties[constants.BUILD_PROPERTIES_BUILD_MCU]
91+
var files []string
92+
utils.FindFilesInFolder(&files, filepath.Join(libFolder, "src"), staticLibsExtensions, true)
93+
for _, file := range files {
94+
if !strings.Contains(filepath.Dir(file), mcu) {
95+
os.RemoveAll(filepath.Dir(file))
96+
}
97+
}
8898
}
8999

90100
// Copy core + variant in use + preprocessed sketch in the correct folders
@@ -171,7 +181,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
171181

172182
// Compile and link project
173183
cmakelist += "add_executable (" + projectName + " ${SOURCES} ${SOURCES_LIBS})\n"
174-
cmakelist += "target_link_libraries( " + projectName + " " + strings.Join(libs, " ") + ")\n"
184+
cmakelist += "target_link_libraries( " + projectName + " -Wl,--as-needed " + strings.Join(libs, " ") + ")\n"
175185

176186
utils.WriteFile(cmakeFile, cmakelist)
177187

@@ -198,7 +208,7 @@ func extractCompileFlags(ctx *types.Context, receipe string, defines, libs, link
198208
*linkDirectories = appendIfUnique(*linkDirectories, strings.TrimPrefix(arg, "-L"))
199209
continue
200210
}
201-
if strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "-I") {
211+
if strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "-I") && !strings.HasPrefix(arg, "-o") {
202212
// HACK : from linkerflags remove MMD (no cache is produced)
203213
if !strings.HasPrefix(arg, "-MMD") {
204214
*linkerflags = appendIfUnique(*linkerflags, arg)

0 commit comments

Comments
 (0)