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 = stdfileName.substr(fileTypePos);
126 //if CMakeLists, create CMakeLists
127 if(stdfileName == "CMakeLists.txt")
129 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
130 this->children.push_back(this->CMakeLists);
132 //if is a code file, create code file
133 else if(fileType == ".c" ||
134 fileType == ".cxx" ||
136 fileType == ".cpp" ||
137 fileType == ".txx" ||
138 fileType == ".cmake" )
140 modelCDMCodeFile* file = new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
141 this->children.push_back(file);
143 //if is an unknown file, create file
146 this->children.push_back(new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
149 cont = dir.GetNext(&fileName);
152 this->SortChildren();
153 std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
156 modelCDMLibrary::~modelCDMLibrary()
160 const std::string& modelCDMLibrary::GetNameLibrary() const
162 return this->nameLibrary;
165 bool modelCDMLibrary::SetNameLibrary(const std::string& fileName, std::string*& result)
167 std::vector<std::string> words;
168 CDMUtilities::splitter::split(words, fileName, ", /\\\"", CDMUtilities::splitter::no_empties);
169 std::string fileNameReal = words[0];
170 for (int i = 1; i < (int)(words.size()); i++)
172 fileNameReal += "-" + words[i];
176 //opening original cmakelists
177 std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
180 result = new std::string("CMakeLists.txt file failed to open.");
183 //opening temporal cmakelists
184 std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
187 result = new std::string("CMakeLists.txt.tmp file failed to open.");
190 //copying contents from original to temporal and making changes
191 while (getline(in, line))
193 if(line.find("SET ( LIBRARY_NAME") != std::string::npos)
194 line = "SET ( LIBRARY_NAME " + fileNameReal + " )";
195 out << line << std::endl;
199 //delete old file and rename new file
201 std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
203 std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
205 if(system(renameCommand.c_str()))
207 result = new std::string("An error occurred while running '" + renameCommand + "'.");
211 this->nameLibrary = fileNameReal;
215 modelCDMFolder* modelCDMLibrary::CreateFolder(const std::string& name, std::string*& result)
217 //TODO:: mkdir depending on OS
218 std::string command = "mkdir \"" + path + CDMUtilities::SLASH + name + "\"";
219 if(system(command.c_str()))
221 result = new std::string("Error executing: " + command + ".");
224 modelCDMFolder* folder = new modelCDMFolder(this, path + CDMUtilities::SLASH + name, name, level + 1);
225 this->folders.push_back(folder);
226 this->children.push_back(folder);
231 const bool modelCDMLibrary::Refresh(std::string*& result)
233 std::cout << "refreshing library: " << this->nameLibrary << std::endl;
235 this->type = wxDIR_DIRS;
238 std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
240 std::ifstream confFile;
241 confFile.open((pathMakeLists).c_str());
244 while(confFile.is_open() && !confFile.eof())
247 std::getline(confFile,word,'(');
248 std::vector<std::string> wordBits;
249 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
251 if(wordBits[wordBits.size()-1] == "SET")
254 std::getline(confFile,word,')');
255 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
256 if(wordBits[0] == "LIBRARY_NAME")
259 for (int i = 2; i < (int)(wordBits.size()); i++)
261 word += " " + wordBits[i];
264 this->nameLibrary = word;
272 std::vector<bool> checked(this->children.size(), false);
273 std::vector<bool> checkedFolders(this->folders.size(), false);
276 wxDir dir(crea::std2wx((this->path).c_str()));
280 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
283 std::string stdfileName = crea::wx2std(fileName);
284 //check if they already exist
286 for (int i = 0; !found && i < (int)(this->folders.size()); i++)
288 if (this->folders[i]->GetName() == stdfileName)
291 int pos = std::find(this->children.begin(), this->children.end(), this->folders[i]) - this->children.begin();
293 checkedFolders[i] = true;
294 if(!this->folders[i]->Refresh(result))
300 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
301 this->folders.push_back(folder);
302 this->children.push_back(folder);
304 cont = dir.GetNext(&fileName);
307 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
310 std::string stdfileName = crea::wx2std(fileName);
311 std::size_t fileTypePos = stdfileName.find_last_of(".");
312 std::string fileType = stdfileName.substr(fileTypePos);
314 //if CMakeLists, create CMakeLists
315 if(stdfileName == "CMakeLists.txt")
317 if (this->CMakeLists == NULL)
319 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
320 this->children.push_back(this->CMakeLists);
324 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
326 if(!this->CMakeLists->Refresh(result))
330 //if is an unknown file, check if exist in children
334 for (int i = 0; !found && i < (int)(this->children.size()); i++)
336 if (this->children[i]->GetName() == stdfileName)
340 if(!this->children[i]->Refresh(result))
347 //if is a code file, create modelCDMCodeFile
350 fileType == ".cxx" ||
352 fileType == ".cpp" ||
353 fileType == ".txx" ||
354 fileType == ".cmake" )
356 this->children.push_back(new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
360 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
361 this->children.push_back(file);
366 cont = dir.GetNext(&fileName);
370 for (int i = 0; i < (int)(checkedFolders.size()); i++)
372 if(!checkedFolders[i])
374 this->folders.erase(this->folders.begin()+i);
375 checkedFolders.erase(checkedFolders.begin()+i);
379 for (int i = 0; i < (int)(checked.size()); i++)
383 delete this->children[i];
384 this->children.erase(this->children.begin()+i);
385 checked.erase(checked.begin()+i);
389 this->SortChildren();
390 std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
394 void modelCDMLibrary::CheckStructure(std::map<std::string, bool>& properties)
397 if(this->CMakeLists != NULL)
400 properties["library " + this->name + " lib ${crea_LIBRARIES}"] = false;
401 properties["library " + this->name + " lib ${WXWIDGETS_LIBRARIES}"] = false;
402 properties["library " + this->name + " lib ${KWWidgets_LIBRARIES}"] = false;
403 properties["library " + this->name + " lib ${VTK_LIBRARIES}"] = false;
404 properties["library " + this->name + " lib ${ITK_LIBRARIES}"] = false;
405 properties["library " + this->name + " lib ${GDCM_LIBRARIES}"] = false;
406 properties["library " + this->name + " lib ${BOOST_LIBRARIES}"] = false;
410 std::ifstream confFile;
411 confFile.open((this->CMakeLists->GetPath()).c_str());
413 //take everything that is not commented
414 std::string fileContent;
417 std::vector<std::string> words;
418 while(confFile.is_open() && !confFile.eof())
420 std::getline(confFile,word, '\n');
423 CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok);
424 if (words.size() > 0)
427 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
428 for (int i = 0; i < (int)(words.size()); i++)
430 if(words[i].substr(0,2) == "//")
432 fileContent += words[i] + " ";
438 //check every instruction
439 std::stringstream ss(fileContent);
442 std::getline(ss,word, '(');
444 //check instruction name
445 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
448 if (words.size() > 0 && words[words.size()-1] == "SET")
450 std::getline(ss,word, ')');
452 CDMUtilities::splitter::split(words, word, " \t", CDMUtilities::splitter::no_empties);
453 if (words.size() > 1)
455 if (words[0] == "${LIBRARY_NAME}_LINK_LIBRARIES")
457 for (int i = 1; i < (int)(words.size()); i++)
459 properties["library " + this->name + " lib " + words[i]] = true;
469 std::map<std::string, bool> modelCDMLibrary::Get3rdPartyLibraries()
471 std::map<std::string, std::string> correspondence;
472 correspondence["${crea_LIBRARIES}"] = "Crea";
473 correspondence["${WXWIDGETS_LIBRARIES}"] = "WxWidgets";
474 correspondence["${KWWidgets_LIBRARIES}"] = "KWWidgets";
475 correspondence["${VTK_LIBRARIES}"] = "VTK";
476 correspondence["${ITK_LIBRARIES}"] = "ITK";
477 correspondence["${GDCM_LIBRARIES}"] = "GDCM";
478 correspondence["${BOOST_LIBRARIES}"] = "Boost";
479 std::map<std::string, bool> res;
481 res["WxWidgets"] = false;
482 res["KWWidgets"] = false;
486 res["Boost"] = false;
488 if (this->HasCMakeLists())
490 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
492 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
493 std::string::const_iterator start, end;
494 start = CMfile.begin();
496 boost::match_results<std::string::const_iterator> what;
497 boost::match_flag_type flags = boost::match_default;
498 if(boost::regex_search(start, end, what, expression, flags))
501 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES");
502 std::string::const_iterator start1, end1;
503 start1 = what[0].first;
504 end1 = what[0].second;
505 boost::match_results<std::string::const_iterator> what1;
506 if(boost::regex_search(start1, end1, what1, expression, flags))
508 expression = boost::regex("(#[^\\n]*\\n|\\s*\\$\\{\\w+\\})");
509 std::string::const_iterator start2, end2;
510 start2 = what1[0].second;
511 end2 = what[0].second;
512 boost::match_results<std::string::const_iterator> what2;
513 while(boost::regex_search(start2, end2, what2, expression, flags))
515 if(what2.str()[0] != '#')
517 std::string dete = what2.str();
518 CDMUtilities::normalizeStr(dete);
519 if(correspondence.find(dete) != correspondence.end())
520 res[correspondence[dete]] = true;
522 start2 = what2[0].second;
530 bool modelCDMLibrary::Set3rdPartyLibrary(const std::string& library_name, const bool& toInclude)
532 std::map<std::string, std::string> correspondence;
534 correspondence["Crea"] = "${crea_LIBRARIES}";
535 correspondence["WxWidgets"] = "${WXWIDGETS_LIBRARIES}";
536 correspondence["KWWidgets"] = "${KWWidgets_LIBRARIES}";
537 correspondence["VTK"] = "${VTK_LIBRARIES}";
538 correspondence["ITK"] = "${ITK_LIBRARIES}";
539 correspondence["GDCM"] = "${GDCM_LIBRARIES}";
540 correspondence["Boost"] = "${BOOST_LIBRARIES}";
542 std::map<std::string, std::string> regexCorrespondence;
544 regexCorrespondence["Crea"] = "\\$\\{crea_LIBRARIES\\}";
545 regexCorrespondence["WxWidgets"] = "\\$\\{WXWIDGETS_LIBRARIES\\}";
546 regexCorrespondence["KWWidgets"] = "\\$\\{KWWidgets_LIBRARIES\\}";
547 regexCorrespondence["VTK"] = "\\$\\{VTK_LIBRARIES\\}";
548 regexCorrespondence["ITK"] = "\\$\\{ITK_LIBRARIES\\}";
549 regexCorrespondence["GDCM"] = "\\$\\{GDCM_LIBRARIES\\}";
550 regexCorrespondence["Boost"] = "\\$\\{BOOST_LIBRARIES\\}";
552 if (correspondence.find(library_name) != correspondence.end())
554 std::string library_command = correspondence[library_name];
555 std::string regex_command = regexCorrespondence[library_name];
556 if (this->HasCMakeLists())
558 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
559 std::string resCMfile = "";
561 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
562 std::string::const_iterator start, end;
563 start = CMfile.begin();
565 boost::match_results<std::string::const_iterator> what;
566 boost::match_flag_type flags = boost::match_default;
567 if(boost::regex_search(start, end, what, expression, flags))
569 resCMfile += what.prefix().str();
572 expression = "^\\h*#+\\h*" + regex_command;
573 std::string::const_iterator start1, end1;
574 start1 = what[0].first;
575 end1 = what[0].second;
576 boost::match_results<std::string::const_iterator> what1, what2;
577 while(boost::regex_search(start1, end1, what1, expression, flags))
580 resCMfile += what1.prefix().str();
581 std::string dete = what1[0].str();
582 for (int i = 0; i < dete.size(); ++i) {
584 resCMfile.push_back(dete[i]);
587 start1 = what1[0].second;
590 resCMfile += what2.suffix().str();
593 expression = "^\\h*" + regex_command;
594 if(boost::regex_search(start1, end1, what1, expression, flags))
597 expression = "^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES";
598 boost::regex_search(start1, end1, what1, expression, flags);
600 resCMfile += what1.prefix().str() + what1.str();
602 resCMfile += "\n" + library_command + "\n";
603 resCMfile += what1.suffix().str();
607 expression = "^\\h*" + regex_command;
608 std::string::const_iterator start1, end1;
609 start1 = what[0].first;
610 end1 = what[0].second;
611 boost::match_results<std::string::const_iterator> what1, what2;
612 while(boost::regex_search(start1, end1, what1, expression, flags))
615 resCMfile += what1.prefix().str();
616 resCMfile += "#" + what1.str();
618 start1 = what1[0].second;
621 resCMfile += what2.suffix().str();
624 expression = "^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES";
625 boost::regex_search(start1, end1, what1, expression, flags);
627 resCMfile += what1.prefix().str() + what1.str() + what1.suffix().str();
630 resCMfile += what.suffix().str();
632 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
639 std::map<std::string, bool> modelCDMLibrary::GetCustomLibraries()
641 std::map<std::string, bool> res;
642 std::map<std::string, bool> res1;
644 std::map<std::string, std::string> correspondence;
645 std::vector<modelCDMLibrary*> libraries = ((modelCDMLib*)this->parent)->GetLibraries();
646 for (int i = 0; i < libraries.size(); ++i)
648 if(libraries[i]->GetNameLibrary() == this->nameLibrary)
650 correspondence[libraries[i]->GetName()] = libraries[i]->GetNameLibrary();
651 res[libraries[i]->GetNameLibrary()] = false;
652 res1[libraries[i]->GetNameLibrary()] = false;
655 if (this->HasCMakeLists())
657 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
659 //find included libraries
660 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
661 std::string::const_iterator start, end;
662 start = CMfile.begin();
664 boost::match_results<std::string::const_iterator> what;
665 boost::match_flag_type flags = boost::match_default;
666 if(boost::regex_search(start, end, what, expression, flags))
669 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES");
670 std::string::const_iterator start1, end1;
671 start1 = what[0].first;
672 end1 = what[0].second;
673 boost::match_results<std::string::const_iterator> what1;
674 if(boost::regex_search(start1, end1, what1, expression, flags))
676 expression = boost::regex("^\\h*[\\w\\d]+");
677 std::string::const_iterator start2, end2;
678 start2 = what1[0].second;
679 end2 = what[0].second;
680 boost::match_results<std::string::const_iterator> what2;
681 while(boost::regex_search(start2, end2, what2, expression, flags))
683 std::string dete = what2.str();
684 CDMUtilities::normalizeStr(dete);
685 //std::cout << "detectado lib: " << dete << std::endl;
686 if(res1.find(dete) != res1.end())
689 start2 = what2[0].second;
694 //find included folders
695 //std::cout << "searching..." << std::endl;
696 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*([\\./\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"){0,1}?(([\\s]|#[^\\n]*\\n)+([\\./\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
697 start = CMfile.begin();
699 if(boost::regex_search(start, end, what, expression, flags))
701 //std::cout << what.str() << std::endl;
702 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(");
703 std::string::const_iterator start1, end1;
704 start1 = what[0].first;
705 end1 = what[0].second;
706 boost::match_results<std::string::const_iterator> what1;
707 if(boost::regex_search(start1, end1, what1, expression, flags))
709 //std::cout << what1.str() << std::endl;
710 expression = boost::regex("^\\h*\\.\\.\\/([\\w\\d])+");
711 std::string::const_iterator start2, end2;
712 start2 = what1[0].second;
713 end2 = what[0].second;
714 boost::match_results<std::string::const_iterator> what2;
715 while(boost::regex_search(start2, end2, what2, expression, flags))
717 std::string dete = what2.str();
718 CDMUtilities::normalizeStr(dete);
719 //std::cout << "detectado dir: " << dete.substr(3) << std::endl;
720 if(correspondence.find(dete.substr(3)) != correspondence.end())
721 res[correspondence[dete.substr(3)]] = res1[correspondence[dete.substr(3)]];
723 start2 = what2[0].second;
732 bool modelCDMLibrary::SetCustomLibrary(const std::string& library_name, const bool& toInclude)
734 std::map<std::string, std::string> correspondence;
735 std::vector<modelCDMLibrary*> libraries = ((modelCDMLib*)this->parent)->GetLibraries();
736 for (int i = 0; i < libraries.size(); ++i)
738 if(libraries[i]->GetNameLibrary() == this->nameLibrary)
740 correspondence[libraries[i]->GetNameLibrary()] = libraries[i]->GetName();
743 if (correspondence.find(library_name) != correspondence.end())
745 if (this->HasCMakeLists())
747 std::string resCMfile = "";
748 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
751 //find included libraries
752 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
753 std::string::const_iterator start, end;
754 start = CMfile.begin();
756 boost::match_results<std::string::const_iterator> what;
757 boost::match_flag_type flags = boost::match_default;
758 if(boost::regex_search(start, end, what, expression, flags))
760 resCMfile += what.prefix().str();
761 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES");
762 std::string::const_iterator start1, end1;
763 start1 = what[0].first;
764 end1 = what[0].second;
765 boost::match_results<std::string::const_iterator> what1;
766 if(boost::regex_search(start1, end1, what1, expression, flags))
768 resCMfile += what1.prefix().str() + what1.str();
769 //check if already exists
770 expression = boost::regex("^\\h*"+library_name);
771 std::string::const_iterator start2, end2;
772 start2 = what1[0].second;
773 end2 = what[0].second;
774 boost::match_results<std::string::const_iterator> what2, temp2;
775 while(boost::regex_search(start2, end2, what2, expression, flags))
777 resCMfile += what2.prefix().str();
783 resCMfile += what2.str();
785 start2 = what2[0].second;
788 resCMfile += temp2.suffix().str();
789 //check if is commented
792 expression = boost::regex("^\\h*#+\\h*"+library_name);
793 start2 = what1[0].second;
794 end2 = what[0].second;
795 while(boost::regex_search(start2, end2, what2, expression, flags))
798 resCMfile += what2.prefix().str();
801 std::string dete = what2[0].str();
802 for (int i = 0; i < dete.size(); ++i) {
804 resCMfile.push_back(dete[i]);
808 start2 = what2[0].second;
811 resCMfile += temp2.suffix().str();
812 //add at the beggining of instruction
816 resCMfile += "\n" + library_name;
817 resCMfile += what1.suffix().str();
821 resCMfile += what.suffix().str();
826 //find included folders
832 std::cout << "searching..." << CMfile << std::endl;
833 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"){0,1}?(([\\s]|#[^\\n]*\\n)+([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
834 start = CMfile.begin();
836 if(boost::regex_search(start, end, what, expression, flags))
838 resCMfile += what.prefix().str();
839 std::cout << what.str() << std::endl;
840 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(");
841 std::string::const_iterator start1, end1;
842 start1 = what[0].first;
843 end1 = what[0].second;
844 boost::match_results<std::string::const_iterator> what1;
845 if(boost::regex_search(start1, end1, what1, expression, flags))
847 resCMfile += what1.prefix().str() + what1.str();
848 std::cout << what1.str() << std::endl;
849 //search if dir is already included
850 expression = boost::regex("^\\h*\\.\\.\\/"+correspondence[library_name]);
851 std::string::const_iterator start2, end2;
852 start2 = what1[0].second;
853 end2 = what[0].second;
854 boost::match_results<std::string::const_iterator> what2, temp2;
855 while(boost::regex_search(start2, end2, what2, expression, flags))
858 resCMfile += what2.prefix().str();
861 resCMfile += what2.str();
863 start2 = what2[0].second;
866 resCMfile += temp2.suffix().str();
867 //search if dir is commented
870 expression = boost::regex("^\\h*#+\\h*\\.\\.\\/"+correspondence[library_name]);
871 start2 = what1[0].second;
872 end2 = what[0].second;
873 while(boost::regex_search(start2, end2, what2, expression, flags))
876 resCMfile += what2.prefix().str();
879 std::string dete = what2[0].str();
880 for (int i = 0; i < dete.size(); ++i) {
882 resCMfile.push_back(dete[i]);
886 start2 = what2[0].second;
889 resCMfile += temp2.suffix().str();
890 //add at the beggining of instruction
894 resCMfile += "\n../" + correspondence[library_name];
895 resCMfile += what1.suffix().str();
899 resCMfile += what.suffix().str();
904 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);