@@ -23,17 +23,22 @@ import (
2323
2424 properties "github.com/arduino/go-properties-orderedmap"
2525
26+ "github.com/arduino/arduino-cli/arduino/globals"
2627 "github.com/arduino/arduino-cli/legacy/builder/builder_utils"
2728 "github.com/arduino/arduino-cli/legacy/builder/constants"
2829 "github.com/arduino/arduino-cli/legacy/builder/types"
2930 "github.com/arduino/arduino-cli/legacy/builder/utils"
3031)
3132
32- var VALID_EXPORT_EXTENSIONS = map [string ]bool {".h" : true , ".c" : true , ".hpp" : true , ".hh" : true , ".cpp" : true , ".S" : true , ".a" : true , ".properties" : true }
33-
34- var ValidExportExtensions = []string {".h" , ".c" , ".hpp" , ".hh" , ".cpp" , ".S" , ".a" , ".properties" }
35- var DotHExtension = []string {".h" , ".hh" , ".hpp" }
36- var DotAExtension = []string {".a" }
33+ func stringArrayToLookupFunction (in []string ) func (string ) bool {
34+ out := map [string ]bool {}
35+ for _ , i := range in {
36+ out [i ] = true
37+ }
38+ return func (s string ) bool {
39+ return out [s ]
40+ }
41+ }
3742
3843type ExportProjectCMake struct {
3944 // Was there an error while compiling the sketch?
@@ -43,6 +48,17 @@ type ExportProjectCMake struct {
4348var lineMatcher = regexp .MustCompile (`^#line\s\d+\s"` )
4449
4550func (s * ExportProjectCMake ) Run (ctx * types.Context ) error {
51+ var validExportExtensions = []string {".a" , ".properties" }
52+ for ext := range globals .SourceFilesValidExtensions {
53+ validExportExtensions = append (validExportExtensions , ext )
54+ }
55+ var dotHExtension = []string {}
56+ for ext := range globals .HeaderFilesValidExtensions {
57+ validExportExtensions = append (validExportExtensions , ext )
58+ dotHExtension = append (dotHExtension , ext )
59+ }
60+ var dotAExtension = []string {".a" }
61+
4662 if s .SketchError || ! canExportCmakeProject (ctx ) {
4763 return nil
4864 }
@@ -65,7 +81,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
6581 cmakeFile := cmakeFolder .Join ("CMakeLists.txt" )
6682
6783 dynamicLibsFromPkgConfig := map [string ]bool {}
68- extensions := func ( ext string ) bool { return VALID_EXPORT_EXTENSIONS [ ext ] }
84+ extensions := stringArrayToLookupFunction ( validExportExtensions )
6985 for _ , library := range ctx .ImportedLibraries {
7086 // Copy used libraries in the correct folder
7187 libDir := libBaseFolder .Join (library .Name )
@@ -90,7 +106,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
90106 }
91107
92108 // Remove stray folders contining incompatible or not needed libraries archives
93- files , _ := utils .FindFilesInFolder (libDir .Join ("src" ), true , DotAExtension )
109+ files , _ := utils .FindFilesInFolder (libDir .Join ("src" ), true , dotAExtension )
94110 for _ , file := range files {
95111 staticLibDir := file .Parent ()
96112 if ! isStaticLib || ! strings .Contains (staticLibDir .String (), mcu ) {
@@ -126,7 +142,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
126142 }
127143
128144 // remove "#line 1 ..." from exported c_make folder sketch
129- sketchFiles , _ := utils .FindFilesInFolder (cmakeFolder .Join ("sketch" ), false , ValidExportExtensions )
145+ sketchFiles , _ := utils .FindFilesInFolder (cmakeFolder .Join ("sketch" ), false , validExportExtensions )
130146
131147 for _ , file := range sketchFiles {
132148 input , err := file .ReadFile ()
@@ -160,11 +176,11 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
160176 extractCompileFlags (ctx , "recipe.cpp.o.pattern" , & defines , & dynamicLibsFromGccMinusL , & linkerflags , & linkDirectories )
161177
162178 // Extract folders with .h in them for adding in include list
163- headerFiles , _ := utils .FindFilesInFolder (cmakeFolder , true , DotHExtension )
179+ headerFiles , _ := utils .FindFilesInFolder (cmakeFolder , true , dotHExtension )
164180 foldersContainingDotH := findUniqueFoldersRelative (headerFiles .AsStrings (), cmakeFolder .String ())
165181
166182 // Extract folders with .a in them for adding in static libs paths list
167- staticLibs , _ := utils .FindFilesInFolder (cmakeFolder , true , DotAExtension )
183+ staticLibs , _ := utils .FindFilesInFolder (cmakeFolder , true , dotAExtension )
168184
169185 // Generate the CMakeLists global file
170186
0 commit comments