@@ -74,6 +74,10 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
74
74
for _ , library := range ctx .ImportedLibraries {
75
75
libFolder := filepath .Join (libBaseFolder , library .Name )
76
76
utils .CopyDir (library .Folder , libFolder , extensions )
77
+ // Remove examples folder
78
+ if _ , err := os .Stat (filepath .Join (library .Folder , "examples" )); err == nil {
79
+ os .Remove (filepath .Join (library .Folder , "examples" ))
80
+ }
77
81
}
78
82
79
83
// Copy core + variant in use + preprocessed sketch in the correct folders
@@ -121,18 +125,27 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
121
125
cmakelist += "add_definitions (" + strings .Join (defines , " " ) + " " + strings .Join (linkerflags , " " ) + ")\n "
122
126
cmakelist += "include_directories (" + foldersContainingDotH + ")\n "
123
127
128
+ // Make link directories relative
129
+ // We can totally discard them since they mostly are outside the core folder
130
+ // If they are inside the core they are not getting copied :)
124
131
var relLinkDirectories []string
125
132
for _ , dir := range linkDirectories {
126
- relLinkDirectories = append (relLinkDirectories , strings .TrimPrefix (dir , cmakeFolder ))
133
+ if strings .Contains (dir , cmakeFolder ) {
134
+ relLinkDirectories = append (relLinkDirectories , strings .TrimPrefix (dir , cmakeFolder ))
135
+ }
127
136
}
137
+
138
+ // Add SO_PATHS option for libraries not getting found by pkg_config
139
+ cmakelist += "set(EXTRA_LIBS_DIRS \" \" CACHE STRING \" Additional paths for dynamic libraries\" )\n "
140
+
128
141
for i , lib := range libs {
129
142
// Dynamic libraries should be discovered by pkg_config
130
143
lib = strings .TrimPrefix (lib , "-l" )
131
144
libs [i ] = lib
132
- cmakelist += "pkg_search_module (" + strings .ToUpper (lib ) + "REQUIRED " + lib + ")\n "
133
- linkDirectories = append (linkDirectories , "${" + strings .ToUpper (lib )+ "_LIBRARY_DIRS}" )
145
+ cmakelist += "pkg_search_module (" + strings .ToUpper (lib ) + " " + lib + ")\n "
146
+ relLinkDirectories = append (relLinkDirectories , "${" + strings .ToUpper (lib )+ "_LIBRARY_DIRS}" )
134
147
}
135
- cmakelist += "link_directories (" + strings .Join (linkDirectories , " " ) + ")\n "
148
+ cmakelist += "link_directories (" + strings .Join (relLinkDirectories , " " ) + " ${SO_PATHS} )\n "
136
149
for _ , staticLibsFile := range staticLibsFiles {
137
150
// Static libraries are fully configured
138
151
lib := filepath .Base (staticLibsFile )
@@ -145,7 +158,11 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
145
158
cmakelist += "set_property(TARGET " + lib + " PROPERTY IMPORTED_LOCATION " + "${PROJECT_SOURCE_DIR}" + location + " )\n "
146
159
}
147
160
}
161
+ // Include source files
162
+ // TODO: remove .cpp and .h from libraries example folders
148
163
cmakelist += "file (GLOB_RECURSE SOURCES core/*.c* lib/*.c* sketch/*.c*)\n "
164
+
165
+ // Compile and link project
149
166
cmakelist += "add_executable (" + projectName + " ${SOURCES} ${SOURCES_LIBS})\n "
150
167
cmakelist += "target_link_libraries( " + projectName + " " + strings .Join (libs , " " ) + ")\n "
151
168
@@ -160,20 +177,20 @@ func extractCompileFlags(ctx *types.Context, receipe string, defines, libs, link
160
177
for _ , arg := range command .Args {
161
178
if strings .HasPrefix (arg , "-D" ) {
162
179
* defines = appendIfUnique (* defines , arg )
163
- } else {
164
- if strings . HasPrefix ( arg , "-l" ) {
165
- * libs = appendIfUnique ( * libs , arg )
166
- } else {
167
- if strings . HasPrefix ( arg , "-L" ) {
168
- * linkDirectories = appendIfUnique ( * linkDirectories , strings . TrimPrefix ( arg , "-L" ))
169
- } else {
170
- if strings . HasPrefix ( arg , "-" ) && ! strings .HasPrefix (arg , "-I" ) {
171
- // HACK : from linkerflags remove MMD
172
- if ! strings . HasPrefix ( arg , "-MMD" ) {
173
- * linkerflags = appendIfUnique ( * linkerflags , arg )
174
- }
175
- }
176
- }
180
+ continue
181
+ }
182
+ if strings . HasPrefix ( arg , "-l" ) {
183
+ * libs = appendIfUnique ( * libs , arg )
184
+ continue
185
+ }
186
+ if strings . HasPrefix ( arg , "-L" ) {
187
+ * linkDirectories = appendIfUnique ( * linkDirectories , strings .TrimPrefix (arg , "-L" ))
188
+ continue
189
+ }
190
+ if strings . HasPrefix ( arg , "-" ) && ! strings . HasPrefix ( arg , "-I" ) {
191
+ // HACK : from linkerflags remove MMD (no cache is produced)
192
+ if ! strings . HasPrefix ( arg , "-MMD" ) {
193
+ * linkerflags = appendIfUnique ( * linkerflags , arg )
177
194
}
178
195
}
179
196
}
0 commit comments