2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------
31 * Created on: Nov 23, 2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "modelCDMLibrary.h"
37 #include "modelCDMLib.h"
42 #include <boost/regex.hpp>
44 #include "CDMUtilities.h"
48 modelCDMLibrary::modelCDMLibrary()
52 modelCDMLibrary::modelCDMLibrary(modelCDMIProjectTreeNode* parent, const std::string& path, const std::string& name, const int& level)
54 std::cout << "creating library: " + path + "\n";
55 this->parent = parent;
59 this->path = CDMUtilities::fixPath(path);
61 this->type = wxDIR_DIRS;
66 std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
68 std::ifstream confFile;
69 confFile.open((pathMakeLists).c_str());
72 while(confFile.is_open() && !confFile.eof())
75 std::getline(confFile,word,'(');
76 std::vector<std::string> wordBits;
77 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
79 if(wordBits[wordBits.size()-1] == "SET")
82 std::getline(confFile,word,')');
83 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
84 if(wordBits[0] == "LIBRARY_NAME")
87 for (int i = 2; i < (int)(wordBits.size()); i++)
89 word += " " + wordBits[i];
92 this->nameLibrary = word;
99 //add library contents
101 this->children.clear();
102 wxDir dir(crea::std2wx((this->path).c_str()));
107 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
110 std::string stdfileName = crea::wx2std(fileName);
112 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
113 this->folders.push_back(folder);
114 this->children.push_back(folder);
116 cont = dir.GetNext(&fileName);
119 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
122 std::string stdfileName = crea::wx2std(fileName);
123 std::size_t fileTypePos = stdfileName.find_last_of(".");
124 std::string fileType;
125 if(fileTypePos != std::string::npos)
126 fileType = stdfileName.substr(fileTypePos);
130 //if CMakeLists, create CMakeLists
131 if(stdfileName == "CMakeLists.txt")
133 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
134 this->children.push_back(this->CMakeLists);
136 //if is a code file, create code file
137 else if(fileType == ".c" ||
138 fileType == ".cxx" ||
140 fileType == ".cpp" ||
141 fileType == ".txx" ||
142 fileType == ".cmake" )
144 modelCDMCodeFile* file = new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
145 this->children.push_back(file);
147 //if is an unknown file, create file
150 this->children.push_back(new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
153 cont = dir.GetNext(&fileName);
156 this->SortChildren();
157 std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
160 modelCDMLibrary::~modelCDMLibrary()
164 const std::string& modelCDMLibrary::GetNameLibrary() const
166 return this->nameLibrary;
169 bool modelCDMLibrary::SetNameLibrary(const std::string& fileName, std::string*& result)
171 std::vector<std::string> words;
172 CDMUtilities::splitter::split(words, fileName, ", /\\\"", CDMUtilities::splitter::no_empties);
173 std::string fileNameReal = words[0];
174 for (int i = 1; i < (int)(words.size()); i++)
176 fileNameReal += "-" + words[i];
180 //opening original cmakelists
181 std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
184 result = new std::string("CMakeLists.txt file failed to open.");
187 //opening temporal cmakelists
188 std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
191 result = new std::string("CMakeLists.txt.tmp file failed to open.");
194 //copying contents from original to temporal and making changes
195 while (getline(in, line))
197 if(line.find("SET ( LIBRARY_NAME") != std::string::npos)
198 line = "SET ( LIBRARY_NAME " + fileNameReal + " )";
199 out << line << std::endl;
203 //delete old file and rename new file
205 std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
207 std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
209 if(system(renameCommand.c_str()))
211 result = new std::string("An error occurred while running '" + renameCommand + "'.");
215 this->nameLibrary = fileNameReal;
219 modelCDMFolder* modelCDMLibrary::CreateFolder(const std::string& name, std::string*& result)
221 //TODO:: mkdir depending on OS
222 std::string command = "mkdir \"" + path + CDMUtilities::SLASH + name + "\"";
223 if(system(command.c_str()))
225 result = new std::string("Error executing: " + command + ".");
228 modelCDMFolder* folder = new modelCDMFolder(this, path + CDMUtilities::SLASH + name, name, level + 1);
229 this->folders.push_back(folder);
230 this->children.push_back(folder);
235 const bool modelCDMLibrary::Refresh(std::string*& result)
237 std::cout << "refreshing library: " << this->nameLibrary << std::endl;
239 this->type = wxDIR_DIRS;
242 std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
244 std::ifstream confFile;
245 confFile.open((pathMakeLists).c_str());
248 while(confFile.is_open() && !confFile.eof())
251 std::getline(confFile,word,'(');
252 std::vector<std::string> wordBits;
253 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
255 if(wordBits[wordBits.size()-1] == "SET")
258 std::getline(confFile,word,')');
259 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
260 if(wordBits[0] == "LIBRARY_NAME")
263 for (int i = 2; i < (int)(wordBits.size()); i++)
265 word += " " + wordBits[i];
268 this->nameLibrary = word;
276 std::vector<bool> checked(this->children.size(), false);
277 std::vector<bool> checkedFolders(this->folders.size(), false);
280 wxDir dir(crea::std2wx((this->path).c_str()));
284 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
287 std::string stdfileName = crea::wx2std(fileName);
288 //check if they already exist
290 for (int i = 0; !found && i < (int)(this->folders.size()); i++)
292 if (this->folders[i]->GetName() == stdfileName)
295 int pos = std::find(this->children.begin(), this->children.end(), this->folders[i]) - this->children.begin();
297 checkedFolders[i] = true;
298 if(!this->folders[i]->Refresh(result))
304 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
305 this->folders.push_back(folder);
306 this->children.push_back(folder);
308 cont = dir.GetNext(&fileName);
311 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
314 std::string stdfileName = crea::wx2std(fileName);
315 std::size_t fileTypePos = stdfileName.find_last_of(".");
316 std::string fileType;
317 if(fileTypePos != std::string::npos)
318 fileType = stdfileName.substr(fileTypePos);
322 //if CMakeLists, create CMakeLists
323 if(stdfileName == "CMakeLists.txt")
325 if (this->CMakeLists == NULL)
327 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
328 this->children.push_back(this->CMakeLists);
332 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
334 if(!this->CMakeLists->Refresh(result))
338 //if is an unknown file, check if exist in children
342 for (int i = 0; !found && i < (int)(this->children.size()); i++)
344 if (this->children[i]->GetName() == stdfileName)
348 if(!this->children[i]->Refresh(result))
355 //if is a code file, create modelCDMCodeFile
358 fileType == ".cxx" ||
360 fileType == ".cpp" ||
361 fileType == ".txx" ||
362 fileType == ".cmake" )
364 this->children.push_back(new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
368 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
369 this->children.push_back(file);
374 cont = dir.GetNext(&fileName);
378 for (int i = 0; i < (int)(checkedFolders.size()); i++)
380 if(!checkedFolders[i])
382 this->folders.erase(this->folders.begin()+i);
383 checkedFolders.erase(checkedFolders.begin()+i);
387 for (int i = 0; i < (int)(checked.size()); i++)
391 delete this->children[i];
392 this->children.erase(this->children.begin()+i);
393 checked.erase(checked.begin()+i);
397 this->SortChildren();
398 std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
402 void modelCDMLibrary::CheckStructure(std::map<std::string, bool>& properties)
405 if(this->CMakeLists != NULL)
408 properties["library " + this->name + " lib ${crea_LIBRARIES}"] = false;
409 properties["library " + this->name + " lib ${WXWIDGETS_LIBRARIES}"] = false;
410 properties["library " + this->name + " lib ${KWWidgets_LIBRARIES}"] = false;
411 properties["library " + this->name + " lib ${VTK_LIBRARIES}"] = false;
412 properties["library " + this->name + " lib ${ITK_LIBRARIES}"] = false;
413 properties["library " + this->name + " lib ${GDCM_LIBRARIES}"] = false;
414 properties["library " + this->name + " lib ${BOOST_LIBRARIES}"] = false;
418 std::ifstream confFile;
419 confFile.open((this->CMakeLists->GetPath()).c_str());
421 //take everything that is not commented
422 std::string fileContent;
425 std::vector<std::string> words;
426 while(confFile.is_open() && !confFile.eof())
428 std::getline(confFile,word, '\n');
431 CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok);
432 if (words.size() > 0)
435 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
436 for (int i = 0; i < (int)(words.size()); i++)
438 if(words[i].substr(0,2) == "//")
440 fileContent += words[i] + " ";
446 //check every instruction
447 std::stringstream ss(fileContent);
450 std::getline(ss,word, '(');
452 //check instruction name
453 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
456 if (words.size() > 0 && words[words.size()-1] == "SET")
458 std::getline(ss,word, ')');
460 CDMUtilities::splitter::split(words, word, " \t", CDMUtilities::splitter::no_empties);
461 if (words.size() > 1)
463 if (words[0] == "${LIBRARY_NAME}_LINK_LIBRARIES")
465 for (int i = 1; i < (int)(words.size()); i++)
467 properties["library " + this->name + " lib " + words[i]] = true;
477 std::map<std::string, bool> modelCDMLibrary::Get3rdPartyLibraries()
479 std::map<std::string, std::string> correspondence;
480 correspondence["${crea_LIBRARIES}"] = "Crea";
481 correspondence["${WXWIDGETS_LIBRARIES}"] = "WxWidgets";
482 correspondence["${KWWidgets_LIBRARIES}"] = "KWWidgets";
483 correspondence["${VTK_LIBRARIES}"] = "VTK";
484 correspondence["${ITK_LIBRARIES}"] = "ITK";
485 correspondence["${GDCM_LIBRARIES}"] = "GDCM";
486 correspondence["${BOOST_LIBRARIES}"] = "Boost";
487 std::map<std::string, bool> res;
489 res["WxWidgets"] = false;
490 res["KWWidgets"] = false;
494 res["Boost"] = false;
496 if (this->HasCMakeLists())
498 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
500 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
501 std::string::const_iterator start, end;
502 start = CMfile.begin();
504 boost::match_results<std::string::const_iterator> what;
505 boost::match_flag_type flags = boost::match_default;
506 if(boost::regex_search(start, end, what, expression, flags))
509 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES");
510 std::string::const_iterator start1, end1;
511 start1 = what[0].first;
512 end1 = what[0].second;
513 boost::match_results<std::string::const_iterator> what1;
514 if(boost::regex_search(start1, end1, what1, expression, flags))
516 expression = boost::regex("(#[^\\n]*\\n|\\s*\\$\\{\\w+\\})");
517 std::string::const_iterator start2, end2;
518 start2 = what1[0].second;
519 end2 = what[0].second;
520 boost::match_results<std::string::const_iterator> what2;
521 while(boost::regex_search(start2, end2, what2, expression, flags))
523 if(what2.str()[0] != '#')
525 std::string dete = what2.str();
526 CDMUtilities::normalizeStr(dete);
527 if(correspondence.find(dete) != correspondence.end())
528 res[correspondence[dete]] = true;
530 start2 = what2[0].second;
538 bool modelCDMLibrary::Set3rdPartyLibrary(const std::string& library_name, const bool& toInclude)
540 std::map<std::string, std::string> correspondence;
542 correspondence["Crea"] = "${crea_LIBRARIES}";
543 correspondence["WxWidgets"] = "${WXWIDGETS_LIBRARIES}";
544 correspondence["KWWidgets"] = "${KWWidgets_LIBRARIES}";
545 correspondence["VTK"] = "${VTK_LIBRARIES}";
546 correspondence["ITK"] = "${ITK_LIBRARIES}";
547 correspondence["GDCM"] = "${GDCM_LIBRARIES}";
548 correspondence["Boost"] = "${BOOST_LIBRARIES}";
550 std::map<std::string, std::string> regexCorrespondence;
552 regexCorrespondence["Crea"] = "\\$\\{crea_LIBRARIES\\}";
553 regexCorrespondence["WxWidgets"] = "\\$\\{WXWIDGETS_LIBRARIES\\}";
554 regexCorrespondence["KWWidgets"] = "\\$\\{KWWidgets_LIBRARIES\\}";
555 regexCorrespondence["VTK"] = "\\$\\{VTK_LIBRARIES\\}";
556 regexCorrespondence["ITK"] = "\\$\\{ITK_LIBRARIES\\}";
557 regexCorrespondence["GDCM"] = "\\$\\{GDCM_LIBRARIES\\}";
558 regexCorrespondence["Boost"] = "\\$\\{BOOST_LIBRARIES\\}";
560 if (correspondence.find(library_name) != correspondence.end())
562 std::string library_command = correspondence[library_name];
563 std::string regex_command = regexCorrespondence[library_name];
564 if (this->HasCMakeLists())
566 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
567 std::string resCMfile = "";
569 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
570 std::string::const_iterator start, end;
571 start = CMfile.begin();
573 boost::match_results<std::string::const_iterator> what;
574 boost::match_flag_type flags = boost::match_default;
575 if(boost::regex_search(start, end, what, expression, flags))
577 resCMfile += what.prefix().str();
580 expression = "^\\h*#+\\h*" + regex_command;
581 std::string::const_iterator start1, end1;
582 start1 = what[0].first;
583 end1 = what[0].second;
584 boost::match_results<std::string::const_iterator> what1, what2;
585 while(boost::regex_search(start1, end1, what1, expression, flags))
588 resCMfile += what1.prefix().str();
589 std::string dete = what1[0].str();
590 for (int i = 0; i < dete.size(); ++i) {
592 resCMfile.push_back(dete[i]);
595 start1 = what1[0].second;
598 resCMfile += what2.suffix().str();
601 expression = "^\\h*" + regex_command;
602 if(boost::regex_search(start1, end1, what1, expression, flags))
605 expression = "^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES";
606 boost::regex_search(start1, end1, what1, expression, flags);
608 resCMfile += what1.prefix().str() + what1.str();
610 resCMfile += "\n" + library_command + "\n";
611 resCMfile += what1.suffix().str();
615 expression = "^\\h*" + regex_command;
616 std::string::const_iterator start1, end1;
617 start1 = what[0].first;
618 end1 = what[0].second;
619 boost::match_results<std::string::const_iterator> what1, what2;
620 while(boost::regex_search(start1, end1, what1, expression, flags))
623 resCMfile += what1.prefix().str();
624 resCMfile += "#" + what1.str();
626 start1 = what1[0].second;
629 resCMfile += what2.suffix().str();
632 expression = "^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES";
633 boost::regex_search(start1, end1, what1, expression, flags);
635 resCMfile += what1.prefix().str() + what1.str() + what1.suffix().str();
638 resCMfile += what.suffix().str();
640 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
647 std::map<std::string, bool> modelCDMLibrary::GetCustomLibraries()
649 std::map<std::string, bool> res;
650 std::map<std::string, bool> res1;
652 std::map<std::string, std::string> correspondence;
653 std::vector<modelCDMLibrary*> libraries = ((modelCDMLib*)this->parent)->GetLibraries();
654 for (int i = 0; i < libraries.size(); ++i)
656 if(libraries[i]->GetNameLibrary() == this->nameLibrary)
658 correspondence[libraries[i]->GetName()] = libraries[i]->GetNameLibrary();
659 res[libraries[i]->GetNameLibrary()] = false;
660 res1[libraries[i]->GetNameLibrary()] = false;
663 if (this->HasCMakeLists())
665 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
667 //find included libraries
668 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
669 std::string::const_iterator start, end;
670 start = CMfile.begin();
672 boost::match_results<std::string::const_iterator> what;
673 boost::match_flag_type flags = boost::match_default;
674 if(boost::regex_search(start, end, what, expression, flags))
677 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES");
678 std::string::const_iterator start1, end1;
679 start1 = what[0].first;
680 end1 = what[0].second;
681 boost::match_results<std::string::const_iterator> what1;
682 if(boost::regex_search(start1, end1, what1, expression, flags))
684 expression = boost::regex("^\\h*[\\w\\d]+");
685 std::string::const_iterator start2, end2;
686 start2 = what1[0].second;
687 end2 = what[0].second;
688 boost::match_results<std::string::const_iterator> what2;
689 while(boost::regex_search(start2, end2, what2, expression, flags))
691 std::string dete = what2.str();
692 CDMUtilities::normalizeStr(dete);
693 //std::cout << "detectado lib: " << dete << std::endl;
694 if(res1.find(dete) != res1.end())
697 start2 = what2[0].second;
702 //find included folders
703 //std::cout << "searching..." << std::endl;
704 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*([\\./\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"){0,1}?(([\\s]|#[^\\n]*\\n)+([\\./\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
705 start = CMfile.begin();
707 if(boost::regex_search(start, end, what, expression, flags))
709 //std::cout << what.str() << std::endl;
710 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(");
711 std::string::const_iterator start1, end1;
712 start1 = what[0].first;
713 end1 = what[0].second;
714 boost::match_results<std::string::const_iterator> what1;
715 if(boost::regex_search(start1, end1, what1, expression, flags))
717 //std::cout << what1.str() << std::endl;
718 expression = boost::regex("^\\h*\\.\\.\\/([\\w\\d])+");
719 std::string::const_iterator start2, end2;
720 start2 = what1[0].second;
721 end2 = what[0].second;
722 boost::match_results<std::string::const_iterator> what2;
723 while(boost::regex_search(start2, end2, what2, expression, flags))
725 std::string dete = what2.str();
726 CDMUtilities::normalizeStr(dete);
727 //std::cout << "detectado dir: " << dete.substr(3) << std::endl;
728 if(correspondence.find(dete.substr(3)) != correspondence.end())
729 res[correspondence[dete.substr(3)]] = res1[correspondence[dete.substr(3)]];
731 start2 = what2[0].second;
740 bool modelCDMLibrary::SetCustomLibrary(const std::string& library_name, const bool& toInclude)
742 std::map<std::string, std::string> correspondence;
743 std::vector<modelCDMLibrary*> libraries = ((modelCDMLib*)this->parent)->GetLibraries();
744 for (int i = 0; i < libraries.size(); ++i)
746 if(libraries[i]->GetNameLibrary() == this->nameLibrary)
748 correspondence[libraries[i]->GetNameLibrary()] = libraries[i]->GetName();
751 if (correspondence.find(library_name) != correspondence.end())
753 if (this->HasCMakeLists())
755 std::string resCMfile = "";
756 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
759 //find included libraries
760 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
761 std::string::const_iterator start, end;
762 start = CMfile.begin();
764 boost::match_results<std::string::const_iterator> what;
765 boost::match_flag_type flags = boost::match_default;
766 if(boost::regex_search(start, end, what, expression, flags))
768 resCMfile += what.prefix().str();
769 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES");
770 std::string::const_iterator start1, end1;
771 start1 = what[0].first;
772 end1 = what[0].second;
773 boost::match_results<std::string::const_iterator> what1;
774 if(boost::regex_search(start1, end1, what1, expression, flags))
776 resCMfile += what1.prefix().str() + what1.str();
777 //check if already exists
778 expression = boost::regex("^\\h*"+library_name);
779 std::string::const_iterator start2, end2;
780 start2 = what1[0].second;
781 end2 = what[0].second;
782 boost::match_results<std::string::const_iterator> what2, temp2;
783 while(boost::regex_search(start2, end2, what2, expression, flags))
785 resCMfile += what2.prefix().str();
791 resCMfile += what2.str();
793 start2 = what2[0].second;
796 resCMfile += temp2.suffix().str();
797 //check if is commented
800 expression = boost::regex("^\\h*#+\\h*"+library_name);
801 start2 = what1[0].second;
802 end2 = what[0].second;
803 while(boost::regex_search(start2, end2, what2, expression, flags))
806 resCMfile += what2.prefix().str();
809 std::string dete = what2[0].str();
810 for (int i = 0; i < dete.size(); ++i) {
812 resCMfile.push_back(dete[i]);
816 start2 = what2[0].second;
819 resCMfile += temp2.suffix().str();
820 //add at the beggining of instruction
824 resCMfile += "\n" + library_name;
825 resCMfile += what1.suffix().str();
829 resCMfile += what.suffix().str();
834 //find included folders
840 std::cout << "searching..." << CMfile << std::endl;
841 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"){0,1}?(([\\s]|#[^\\n]*\\n)+([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
842 start = CMfile.begin();
844 if(boost::regex_search(start, end, what, expression, flags))
846 resCMfile += what.prefix().str();
847 std::cout << what.str() << std::endl;
848 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(");
849 std::string::const_iterator start1, end1;
850 start1 = what[0].first;
851 end1 = what[0].second;
852 boost::match_results<std::string::const_iterator> what1;
853 if(boost::regex_search(start1, end1, what1, expression, flags))
855 resCMfile += what1.prefix().str() + what1.str();
856 std::cout << what1.str() << std::endl;
857 //search if dir is already included
858 expression = boost::regex("^\\h*\\.\\.\\/"+correspondence[library_name]);
859 std::string::const_iterator start2, end2;
860 start2 = what1[0].second;
861 end2 = what[0].second;
862 boost::match_results<std::string::const_iterator> what2, temp2;
863 while(boost::regex_search(start2, end2, what2, expression, flags))
866 resCMfile += what2.prefix().str();
869 resCMfile += what2.str();
871 start2 = what2[0].second;
874 resCMfile += temp2.suffix().str();
875 //search if dir is commented
878 expression = boost::regex("^\\h*#+\\h*\\.\\.\\/"+correspondence[library_name]);
879 start2 = what1[0].second;
880 end2 = what[0].second;
881 while(boost::regex_search(start2, end2, what2, expression, flags))
884 resCMfile += what2.prefix().str();
887 std::string dete = what2[0].str();
888 for (int i = 0; i < dete.size(); ++i) {
890 resCMfile.push_back(dete[i]);
894 start2 = what2[0].second;
897 resCMfile += temp2.suffix().str();
898 //add at the beggining of instruction
902 resCMfile += "\n../" + correspondence[library_name];
903 resCMfile += what1.suffix().str();
907 resCMfile += what.suffix().str();
912 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);