@@ -23,17 +23,22 @@ import (
23
23
24
24
properties "github.com/arduino/go-properties-orderedmap"
25
25
26
+ "github.com/arduino/arduino-cli/arduino/globals"
26
27
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
27
28
"github.com/arduino/arduino-cli/legacy/builder/constants"
28
29
"github.com/arduino/arduino-cli/legacy/builder/types"
29
30
"github.com/arduino/arduino-cli/legacy/builder/utils"
30
31
)
31
32
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
+ }
37
42
38
43
type ExportProjectCMake struct {
39
44
// Was there an error while compiling the sketch?
@@ -43,6 +48,17 @@ type ExportProjectCMake struct {
43
48
var lineMatcher = regexp .MustCompile (`^#line\s\d+\s"` )
44
49
45
50
func (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
+
46
62
if s .SketchError || ! canExportCmakeProject (ctx ) {
47
63
return nil
48
64
}
@@ -65,7 +81,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
65
81
cmakeFile := cmakeFolder .Join ("CMakeLists.txt" )
66
82
67
83
dynamicLibsFromPkgConfig := map [string ]bool {}
68
- extensions := func ( ext string ) bool { return VALID_EXPORT_EXTENSIONS [ ext ] }
84
+ extensions := stringArrayToLookupFunction ( validExportExtensions )
69
85
for _ , library := range ctx .ImportedLibraries {
70
86
// Copy used libraries in the correct folder
71
87
libDir := libBaseFolder .Join (library .Name )
@@ -90,7 +106,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
90
106
}
91
107
92
108
// 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 )
94
110
for _ , file := range files {
95
111
staticLibDir := file .Parent ()
96
112
if ! isStaticLib || ! strings .Contains (staticLibDir .String (), mcu ) {
@@ -126,7 +142,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
126
142
}
127
143
128
144
// 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 )
130
146
131
147
for _ , file := range sketchFiles {
132
148
input , err := file .ReadFile ()
@@ -160,11 +176,11 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
160
176
extractCompileFlags (ctx , "recipe.cpp.o.pattern" , & defines , & dynamicLibsFromGccMinusL , & linkerflags , & linkDirectories )
161
177
162
178
// 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 )
164
180
foldersContainingDotH := findUniqueFoldersRelative (headerFiles .AsStrings (), cmakeFolder .String ())
165
181
166
182
// 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 )
168
184
169
185
// Generate the CMakeLists global file
170
186
0 commit comments