@@ -85,6 +85,16 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
85
85
if _ , err := os .Stat (filepath .Join (libFolder , "examples" )); err == nil {
86
86
os .RemoveAll (filepath .Join (libFolder , "examples" ))
87
87
}
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
+ }
88
98
}
89
99
90
100
// Copy core + variant in use + preprocessed sketch in the correct folders
@@ -171,7 +181,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
171
181
172
182
// Compile and link project
173
183
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 "
175
185
176
186
utils .WriteFile (cmakeFile , cmakelist )
177
187
@@ -198,7 +208,7 @@ func extractCompileFlags(ctx *types.Context, receipe string, defines, libs, link
198
208
* linkDirectories = appendIfUnique (* linkDirectories , strings .TrimPrefix (arg , "-L" ))
199
209
continue
200
210
}
201
- if strings .HasPrefix (arg , "-" ) && ! strings .HasPrefix (arg , "-I" ) {
211
+ if strings .HasPrefix (arg , "-" ) && ! strings .HasPrefix (arg , "-I" ) && ! strings . HasPrefix ( arg , "-o" ) {
202
212
// HACK : from linkerflags remove MMD (no cache is produced)
203
213
if ! strings .HasPrefix (arg , "-MMD" ) {
204
214
* linkerflags = appendIfUnique (* linkerflags , arg )
0 commit comments