@@ -168,10 +168,12 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
168168 // Add SO_PATHS option for libraries not getting found by pkg_config
169169 cmakelist += "set(EXTRA_LIBS_DIRS \" \" CACHE STRING \" Additional paths for dynamic libraries\" )\n "
170170
171+ linkGroup := ""
171172 for _ , lib := range libs {
172173 // Dynamic libraries should be discovered by pkg_config
173174 cmakelist += "pkg_search_module (" + strings .ToUpper (lib ) + " " + lib + ")\n "
174175 relLinkDirectories = append (relLinkDirectories , "${" + strings .ToUpper (lib )+ "_LIBRARY_DIRS}" )
176+ linkGroup += " " + lib
175177 }
176178 cmakelist += "link_directories (" + strings .Join (relLinkDirectories , " " ) + " ${EXTRA_LIBS_DIRS})\n "
177179 for _ , staticLibsFile := range staticLibsFiles {
@@ -180,19 +182,20 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
180182 lib = strings .TrimPrefix (lib , "lib" )
181183 lib = strings .TrimSuffix (lib , ".a" )
182184 if ! utils .SliceContains (libs , lib ) {
183- libs = append ( libs , lib )
185+ linkGroup += " " + lib
184186 cmakelist += "add_library (" + lib + " STATIC IMPORTED)\n "
185187 location := strings .TrimPrefix (staticLibsFile , cmakeFolder )
186188 cmakelist += "set_property(TARGET " + lib + " PROPERTY IMPORTED_LOCATION " + "${PROJECT_SOURCE_DIR}" + location + " )\n "
187189 }
188190 }
191+
189192 // Include source files
190193 // TODO: remove .cpp and .h from libraries example folders
191194 cmakelist += "file (GLOB_RECURSE SOURCES core/*.c* lib/*.c* sketch/*.c*)\n "
192195
193196 // Compile and link project
194197 cmakelist += "add_executable (" + projectName + " ${SOURCES} ${SOURCES_LIBS})\n "
195- cmakelist += "target_link_libraries( " + projectName + " -Wl,--as-needed -Wl,--start-group " + strings . Join ( libs , " " ) + " -Wl,--end-group)\n "
198+ cmakelist += "target_link_libraries( " + projectName + " -Wl,--as-needed -Wl,--start-group " + linkGroup + " -Wl,--end-group)\n "
196199
197200 utils .WriteFile (cmakeFile , cmakelist )
198201
0 commit comments