]> Creatis software - crea.git/blob - lib/creaDevManagerLib/modelCDMApplication.cpp
Feature #1711 CreaDevManager application implementation
[crea.git] / lib / creaDevManagerLib / modelCDMApplication.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la Sant�)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and
11 #  abiding by the rules of distribution of free software. You can  use,
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B
13 #  license as circulated by CEA, CNRS and INRIA at the following URL
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability.
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26  */
27
28 /*
29  * modelCDMApplication.cpp
30  *
31  *  Created on: Nov 23, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "modelCDMApplication.h"
36
37 #include <fstream>
38 #include <sstream>
39 #include <algorithm>
40 #include <boost/regex.hpp>
41
42 #include "CDMUtilities.h"
43 #include "creaWx.h"
44 #include "wx/dir.h"
45
46 modelCDMApplication::modelCDMApplication()
47 {
48   mainFile = NULL;
49 }
50
51 modelCDMApplication::modelCDMApplication(modelCDMIProjectTreeNode* parent, const std::string& path, const std::string& name, const int& level)
52 {
53   std::cout << "creating application: " + path + "\n";
54   this->parent = parent;
55   this->mainFile = NULL;
56   //folder name
57   this->name = name;
58   //path
59   this->path = CDMUtilities::fixPath(path);
60   //type
61   this->type = wxDIR_DIRS;
62   //level
63   this->level = level;
64   //open CMakeList
65   std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
66
67   std::ifstream confFile;
68   confFile.open((pathMakeLists).c_str());
69
70   std::string word;
71   while(confFile.is_open() && !confFile.eof())
72     {
73       //get sets
74       std::getline(confFile,word,'(');
75       std::vector<std::string> wordBits;
76       CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
77
78       if(wordBits[wordBits.size()-1] == "SET")
79         {
80           //get library name
81           std::getline(confFile,word,')');
82           CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
83           if(wordBits[0] == "EXE_NAME")
84             {
85               word = wordBits[1];
86               for (int i = 2; i < (int)(wordBits.size()); i++)
87                 {
88                   word += " " + wordBits[i];
89                 }
90
91               this->executableName = word;
92             }
93         }
94     }
95   confFile.close();
96
97   //add library contents
98
99   this->children.clear();
100   wxDir dir(crea::std2wx((this->path).c_str()));
101   if (dir.IsOpened())
102     {
103       wxString fileName;
104       //folders
105       bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
106       while (cont)
107         {
108           std::string stdfileName = crea::wx2std(fileName);
109
110           modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
111           this->folders.push_back(folder);
112           this->children.push_back(folder);
113
114           cont = dir.GetNext(&fileName);
115         }
116       //files
117       cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
118       while (cont)
119         {
120           std::string stdfileName = crea::wx2std(fileName);
121           //if CMakeLists, create CMakeLists
122           if(stdfileName == "CMakeLists.txt")
123             {
124               this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
125               this->children.push_back(this->CMakeLists);
126             }
127           //if is an unknown file, create file
128           else
129             {
130               modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
131               std::string extension = stdfileName.substr(stdfileName.size()-4);
132               //if is cxx or cpp check if is the main file.
133               if (mainFile == NULL && (extension == ".cxx" || extension == ".cpp"))
134                 {
135                   std::ifstream fileStream((this->path + CDMUtilities::SLASH + stdfileName).c_str());
136
137                   if (fileStream.is_open())
138                     {
139                       std::string fileContent = "";
140                       char ch = fileStream.get();
141                       while(!fileStream.eof())
142                         {
143                           fileContent.push_back(ch);
144                           ch = fileStream.get();
145                         }
146                       fileStream.close();
147
148                       boost::regex expression("^\\h*IMPLEMENT_APP[#\\s\\(]");
149                       std::string::const_iterator start, end;
150                       start = fileContent.begin();
151                       end = fileContent.end();
152                       boost::match_results<std::string::const_iterator> what;
153                       boost::match_flag_type flags = boost::match_default;
154                       if(boost::regex_search(start, end, what, expression, flags))
155                         {
156                           std::cout << "found main wxwidgets file: " << stdfileName << std::endl;
157                           this->mainFile = file;
158                         }
159                       else
160                         {
161                           expression = boost::regex("^\\h*int\\h+main[#\\s\\(]");
162                           start = fileContent.begin();
163                           end = fileContent.end();
164                           if(boost::regex_search(start, end, what, expression, flags))
165                             {
166                               std::cout << "found main console file: " << stdfileName << std::endl;
167                               this->mainFile = file;
168                             }
169                         }
170                     }
171
172                 }
173               this->children.push_back(file);
174             }
175
176           cont = dir.GetNext(&fileName);
177         }
178     }
179   this->SortChildren();
180   std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
181 }
182
183 modelCDMApplication::~modelCDMApplication()
184 {
185 }
186
187 const std::string& modelCDMApplication::GetExecutableName() const
188 {
189   return this->executableName;
190 }
191
192 modelCDMFile* modelCDMApplication::GetMainFile() const
193 {
194   return this->mainFile;
195 }
196
197 bool modelCDMApplication::SetExecutableName(const std::string& fileName, std::string*& result)
198 {
199   std::vector<std::string> words;
200   CDMUtilities::splitter::split(words, fileName, ", /\\\"", CDMUtilities::splitter::no_empties);
201   std::string fileNameReal = words[0];
202   for (int i = 1; i < (int)(words.size()); i++)
203     {
204       fileNameReal += "-" + words[i];
205     }
206
207   std::string line;
208   //opening original cmakelists
209   std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
210   if( !in.is_open())
211     {
212       result = new std::string("CMakeLists.txt file failed to open.");
213       return false;
214     }
215   //opening temporal cmakelists
216   std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
217   if( !out.is_open())
218     {
219       result = new std::string("CMakeLists.txt.tmp file failed to open.");
220       return false;
221     }
222   //copying contents from original to temporal and making changes
223   while (getline(in, line))
224     {
225       if(line.find("SET ( EXE_NAME") != std::string::npos)
226         line = "SET ( EXE_NAME  " + fileNameReal + "  )";
227       out << line << std::endl;
228     }
229   in.close();
230   out.close();
231   //delete old file and rename new file
232 #ifdef _WIN32
233   std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
234 #else
235   std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
236 #endif
237   
238   if(system(renameCommand.c_str()))
239     {
240       result = new std::string("An error occurred while running '" + renameCommand + "'.");
241       return false;
242     }
243
244   this->executableName = fileNameReal;
245   return true;
246 }
247
248 modelCDMFolder* modelCDMApplication::CreateFolder(const std::string& name, std::string*& result)
249 {
250   //TODO:: mkdir depending on OS
251   std::string command = "mkdir " + path + CDMUtilities::SLASH + name;
252   if(system(command.c_str()))
253     {
254       result = new std::string("Error executing: " + command + ".");
255       return NULL;
256     }
257   modelCDMFolder* folder = new modelCDMFolder(this, path + CDMUtilities::SLASH + name, name, level + 1);
258   this->folders.push_back(folder);
259   this->children.push_back(folder);
260
261   return folder;
262 }
263
264 const bool modelCDMApplication::Refresh(std::string*& result)
265 {
266   this->mainFile = NULL;
267   std::cout << "refreshing application: " << this->executableName << std::endl;
268   //set attributes
269   this->type = wxDIR_DIRS;
270
271   //open CMakeList
272   std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
273
274   std::ifstream confFile;
275   confFile.open((pathMakeLists).c_str());
276
277   std::string word;
278   while(confFile.is_open() && !confFile.eof())
279     {
280       //get sets
281       std::getline(confFile,word,'(');
282       std::vector<std::string> wordBits;
283       CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
284
285       if(wordBits[wordBits.size()-1] == "SET")
286         {
287           //get app name
288           std::getline(confFile,word,')');
289           CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
290           if(wordBits[0] == "EXE_NAME")
291             {
292               word = wordBits[1];
293               for (int i = 2; i < (int)(wordBits.size()); i++)
294                 {
295                   word += " " + wordBits[i];
296                 }
297
298               this->executableName = word;
299             }
300         }
301     }
302
303   confFile.close();
304
305   //check children
306   std::vector<bool> checked(this->children.size(), false);
307   std::vector<bool> checkedFolders(this->folders.size(), false);
308
309   //check all folders
310   wxDir dir(crea::std2wx((this->path).c_str()));
311   if (dir.IsOpened())
312     {
313       wxString fileName;
314       bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
315       while (cont)
316         {
317           std::string stdfileName = crea::wx2std(fileName);
318           std::string applicationName = stdfileName;
319           //check if they already exist
320           bool found = false;
321           for (int i = 0; !found && i < (int)(this->folders.size()); i++)
322             {
323               if (this->folders[i]->GetName() == applicationName)
324                 {
325                   found = true;
326                   int pos = std::find(this->children.begin(), this->children.end(), this->folders[i]) - this->children.begin();
327                   checked[pos] = true;
328                   checkedFolders[i] = true;
329                   if(!this->folders[i]->Refresh(result))
330                     return false;
331                 }
332             }
333           if(!found)
334             {
335               modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
336               this->folders.push_back(folder);
337               this->children.push_back(folder);
338             }
339           cont = dir.GetNext(&fileName);
340         }
341
342       cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
343       while (cont)
344         {
345           std::string stdfileName = crea::wx2std(fileName);
346
347           //if CMakeLists, create CMakeLists
348           if(stdfileName == "CMakeLists.txt")
349             {
350               if (this->CMakeLists == NULL)
351                 {
352                   this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
353                   this->children.push_back(this->CMakeLists);
354                 }
355               else
356                 {
357                   int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
358                   checked[pos] = true;
359                   if(!this->CMakeLists->Refresh(result))
360                     return false;
361                 }
362             }
363           //if is an unknown file, create file
364           else
365             {
366               bool found = false;
367               for (int i = 0; !found && i < (int)(this->children.size()); i++)
368                 {
369                   if (this->children[i]->GetName() == stdfileName)
370                     {
371                       found = true;
372                       checked[i] = true;
373
374                       if(!this->children[i]->Refresh(result))
375                         return false;
376
377                       std::string extension = stdfileName.substr(stdfileName.size()-4);
378                       if (mainFile == NULL && (extension == ".cxx" || extension == ".cpp"))
379                         {
380                           std::ifstream fileStream;
381                           std::string word;
382                           fileStream.open((this->path + CDMUtilities::SLASH + stdfileName).c_str());
383                           while (fileStream.is_open() && !fileStream.eof())
384                             {
385                               //get sets
386                               std::getline(fileStream,word,'(');
387                               std::vector<std::string> wordBits;
388                               CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
389                               if (wordBits[wordBits.size() - 1] == "main" || wordBits[wordBits.size() - 1] == "IMPLEMENT_APP")
390                                 {
391                                   this->mainFile = dynamic_cast<modelCDMFile*>(children[i]);
392                                 }
393                             }
394                           fileStream.close();
395                         }
396                     }
397                 }
398
399               if(!found)
400                 {
401                   modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
402
403                   std::string extension = stdfileName.substr(stdfileName.size()-4);
404                   if (mainFile == NULL && (extension == ".cxx" || extension == ".cpp"))
405                     {
406                       std::ifstream fileStream;
407                       std::string word;
408                       fileStream.open((this->path + CDMUtilities::SLASH + stdfileName).c_str());
409                       while (fileStream.is_open() && !fileStream.eof())
410                         {
411                           //get sets
412                           std::getline(fileStream,word,'(');
413                           std::vector<std::string> wordBits;
414                           CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
415                           if (wordBits[wordBits.size() - 1] == "main" || wordBits[wordBits.size() - 1] == "IMPLEMENT_APP")
416                             {
417                               this->mainFile = file;
418                             }
419                         }
420                       fileStream.close();
421                     }
422
423                   this->children.push_back(file);
424                 }
425             }
426
427           cont = dir.GetNext(&fileName);
428         }
429     }
430
431   for (int i = 0; i < (int)(checkedFolders.size()); i++)
432     {
433       if(!checkedFolders[i])
434         {
435           this->folders.erase(this->folders.begin()+i);
436           checkedFolders.erase(checkedFolders.begin()+i);
437           i--;
438         }
439     }
440   for (int i = 0; i < (int)(checked.size()); i++)
441     {
442       if(!checked[i])
443         {
444           delete this->children[i];
445           this->children.erase(this->children.begin()+i);
446           checked.erase(checked.begin()+i);
447           i--;
448         }
449     }
450   this->SortChildren();
451   return true;
452 }
453
454 void modelCDMApplication::CheckStructure(std::map<std::string, bool>& properties)
455 {
456   //check cmake exist
457   if(this->CMakeLists != NULL)
458     {
459       //set default properties
460       properties["application " + this->name + " lib ${crea_LIBRARIES}"] = false;
461       properties["application " + this->name + " lib ${WXWIDGETS_LIBRARIES}"] = false;
462       properties["application " + this->name + " lib ${KWWidgets_LIBRARIES}"] = false;
463       properties["application " + this->name + " lib ${VTK_LIBRARIES}"] = false;
464       properties["application " + this->name + " lib ${ITK_LIBRARIES}"] = false;
465       properties["application " + this->name + " lib ${GDCM_LIBRARIES}"] = false;
466       properties["application " + this->name + " lib ${BOOST_LIBRARIES}"] = false;
467
468       //open cmakelists
469       std::ifstream confFile;
470       confFile.open((this->CMakeLists->GetPath()).c_str());
471
472       //take everything that is not commented
473       std::string fileContent;
474
475       std::string word;
476       std::vector<std::string> words;
477       while(confFile.is_open() && !confFile.eof())
478         {
479           std::getline(confFile,word, '\n');
480           if(word[0] != '#')
481             {
482               CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok);
483               if (words.size() > 0)
484                 {
485                   word = words[0];
486                   CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
487                   for (int i = 0; i < (int)(words.size()); i++)
488                     {
489                       if(words[i].substr(0,2) == "//")
490                         break;
491                       fileContent += words[i] + " ";
492                     }
493                 }
494             }
495         }
496
497       //check every instruction
498       std::stringstream ss(fileContent);
499       while(!ss.eof())
500         {
501           std::getline(ss,word, '(');
502
503           //check instruction name
504           CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
505
506           //set instructions
507           if (words.size() > 0 && words[words.size()-1] == "SET")
508             {
509               std::getline(ss,word, ')');
510
511               CDMUtilities::splitter::split(words, word, " \t", CDMUtilities::splitter::no_empties);
512               if (words.size() > 1)
513                 {
514                   if (words[0] == "${EXE_NAME}_LINK_LIBRARIES")
515                     {
516                       for (int i = 1; i < (int)(words.size()); i++)
517                         {
518                           properties["application " + this->name + " lib " + words[i]] = true;
519                         }
520                     }
521                 }
522             }
523           else if (words.size() > 0 && words[words.size()-1] == "INCLUDE_DIRECTORIES")
524             {
525               std::getline(ss,word, ')');
526
527               CDMUtilities::splitter::split(words, word, " \t", CDMUtilities::splitter::no_empties);
528
529               for (int i = 0; i < (int)(words.size()); i++)
530                 {
531                   properties["application " + this->name + " dir " + words[i]] = true;
532                 }
533
534
535             }
536         }
537
538     }
539 }
540
541 std::map<std::string, bool> modelCDMApplication::Get3rdPartyLibraries()
542 {
543   std::map<std::string, std::string> correspondence;
544   correspondence["${crea_LIBRARIES}"] = "Crea";
545   correspondence["${WXWIDGETS_LIBRARIES}"] = "WxWidgets";
546   correspondence["${KWWidgets_LIBRARIES}"] = "KWWidgets";
547   correspondence["${VTK_LIBRARIES}"] = "VTK";
548   correspondence["${ITK_LIBRARIES}"] = "ITK";
549   correspondence["${GDCM_LIBRARIES}"] = "GDCM";
550   correspondence["${BOOST_LIBRARIES}"] = "Boost";
551   std::map<std::string, bool> res;
552   res["Crea"] = false;
553   res["WxWidgets"] = false;
554   res["KWWidgets"] = false;
555   res["VTK"] = false;
556   res["ITK"] = false;
557   res["GDCM"] = false;
558   res["Boost"] = false;
559
560   if (this->HasCMakeLists())
561     {
562       CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str());
563       // look at every syntax element
564       for (int i = 0; i < cmlFile.size(); ++i)
565         {
566           // if the element is a command and is a SET command
567           if (cmlFile[i].first == "command" && cmlFile[i].second[0] == "SET")
568             {
569               // search first parameter
570               int pos = 1;
571               while (pos < cmlFile[i].second.size())
572                 {
573                   // see if it is ${LIBRARY_NAME}_LINK_LIBRARIES
574                   if (cmlFile[i].second[pos] == "${EXE_NAME}_LINK_LIBRARIES")
575                     {
576                       pos++;
577                       // look for all the third party libraries included
578                       while (pos < cmlFile[i].second.size())
579                         {
580                           if (cmlFile[i].second[pos][0] == '$' && correspondence.find(cmlFile[i].second[pos]) != correspondence.end())
581                             {
582                               res[correspondence[cmlFile[i].second[pos]]] = true;
583                             }
584                           pos++;
585                         }
586                     }
587                   // if it is the first parameter but is not ${LIBRARY_NAME}_LINK_LIBRARIES then finish with this command
588                   else if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '#' && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != ')')
589                     {
590                       break;
591                     }
592                   pos++;
593                 }
594             }
595         }
596     }
597   return res;
598 }
599
600 bool modelCDMApplication::Set3rdPartyLibrary(const std::string& library_name, const bool& toInclude)
601 {
602   std::map<std::string, std::string> correspondence;
603
604   correspondence["Crea"] = "${crea_LIBRARIES}";
605   correspondence["WxWidgets"] = "${WXWIDGETS_LIBRARIES}";
606   correspondence["KWWidgets"] = "${KWWidgets_LIBRARIES}";
607   correspondence["VTK"] = "${VTK_LIBRARIES}";
608   correspondence["ITK"] = "${ITK_LIBRARIES}";
609   correspondence["GDCM"] = "${GDCM_LIBRARIES}";
610   correspondence["Boost"] = "${BOOST_LIBRARIES}";
611
612   if (correspondence.find(library_name) != correspondence.end())
613     {
614       std::string library_command = correspondence[library_name];
615       if (this->HasCMakeLists())
616         {
617           CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath());
618
619           // look at every syntax element
620           for (int i = 0; i < cmlFile.size(); ++i)
621             {
622               // if the element is a command and is a SET command
623               if (cmlFile[i].first == "command" && cmlFile[i].second[0] == "SET")
624                 {
625                   // search first parameter
626                   int pos = 1;
627                   while (pos < cmlFile[i].second.size())
628                     {
629                       // see if it is ${LIBRARY_NAME}_LINK_LIBRARIES
630                       if (cmlFile[i].second[pos] == "${EXE_NAME}_LINK_LIBRARIES")
631                         {
632                           bool found = false;
633                           pos++;
634                           // look for all the third party libraries included
635                           while (pos < cmlFile[i].second.size() && cmlFile[i].second[pos] != ")")
636                             {
637                               // if is library_command then found
638                               if (cmlFile[i].second[pos] == library_command)
639                                 {
640                                   found = true;
641                                   //if toInclude is false the make it a comment
642                                   if (!toInclude)
643                                     {
644                                       cmlFile[i].second[pos] = "#" + cmlFile[i].second[pos];
645                                       std::cout << "library commented: " << library_name << std::endl;
646                                     }
647                                   break;
648                                 }
649                               else if (toInclude && cmlFile[i].second[pos][0] == '#')
650                                 {
651                                   std::vector<std::string> segments;
652                                   CDMUtilities::splitter::split(segments, cmlFile[i].second[pos], "#", CDMUtilities::splitter::no_empties);
653                                   if(segments.size())
654                                     {
655                                       for (int j = 0; j < segments[0].size(); ++j)
656                                         {
657                                           if(isspace(segments[0][j]))
658                                             {
659                                               segments[0].erase(j,1);
660                                               j--;
661                                             }
662                                         }
663
664                                       if(segments[0].size() && segments[0] == library_command)
665                                         {
666                                           found = true;
667                                           while(cmlFile[i].second[pos][0] == '#')
668                                             {
669                                               cmlFile[i].second[pos].erase(0,1);
670                                             }
671                                           std::cout << "library uncommented: " << library_name << std::endl;
672                                           break;
673                                         }
674                                     }
675                                 }
676                               pos++;
677                             }
678
679                           //if the library was not found and is an inclusion then include it
680                           if (!found && toInclude && pos < cmlFile[i].second.size() && cmlFile[i].second[pos] == ")")
681                             {
682                               cmlFile[i].second.insert(cmlFile[i].second.begin()+pos, library_command);
683                               cmlFile[i].second.insert(cmlFile[i].second.begin()+pos+1, "\n");
684                               std::cout << "library included: " << library_name << std::endl;
685                             }
686                         }
687                       // if it is the first parameter but is not ${LIBRARY_NAME}_LINK_LIBRARIES then finish with this command
688                       else if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '#' && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != ')')
689                         {
690                           break;
691                         }
692                       pos++;
693                     }
694                 }
695             }
696
697           return CDMUtilities::writeCMLFile(this->CMakeLists->GetPath(), cmlFile);
698         }
699     }
700   return false;
701 }
702
703 std::map<std::string, bool> modelCDMApplication::GetCustomLibraries()
704 {
705   std::map<std::string, bool> res;
706   res["Test"] = false;
707   return res;
708 }
709
710 bool modelCDMApplication::SetCustomLibrary(const std::string& library_name, const bool& toInclude)
711 {
712   return false;
713 }