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);
124 //if CMakeLists, create CMakeLists
125 if(stdfileName == "CMakeLists.txt")
127 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
128 this->children.push_back(this->CMakeLists);
130 //if is an unknown file, create file
133 this->children.push_back(new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
136 cont = dir.GetNext(&fileName);
139 this->SortChildren();
140 std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
143 modelCDMLibrary::~modelCDMLibrary()
147 const std::string& modelCDMLibrary::GetNameLibrary() const
149 return this->nameLibrary;
152 bool modelCDMLibrary::SetNameLibrary(const std::string& fileName, std::string*& result)
154 std::vector<std::string> words;
155 CDMUtilities::splitter::split(words, fileName, ", /\\\"", CDMUtilities::splitter::no_empties);
156 std::string fileNameReal = words[0];
157 for (int i = 1; i < (int)(words.size()); i++)
159 fileNameReal += "-" + words[i];
163 //opening original cmakelists
164 std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
167 result = new std::string("CMakeLists.txt file failed to open.");
170 //opening temporal cmakelists
171 std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
174 result = new std::string("CMakeLists.txt.tmp file failed to open.");
177 //copying contents from original to temporal and making changes
178 while (getline(in, line))
180 if(line.find("SET ( LIBRARY_NAME") != std::string::npos)
181 line = "SET ( LIBRARY_NAME " + fileNameReal + " )";
182 out << line << std::endl;
186 //delete old file and rename new file
188 std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
190 std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
192 if(system(renameCommand.c_str()))
194 result = new std::string("An error occurred while running '" + renameCommand + "'.");
198 this->nameLibrary = fileNameReal;
202 modelCDMFolder* modelCDMLibrary::CreateFolder(const std::string& name, std::string*& result)
204 //TODO:: mkdir depending on OS
205 std::string command = "mkdir \"" + path + CDMUtilities::SLASH + name + "\"";
206 if(system(command.c_str()))
208 result = new std::string("Error executing: " + command + ".");
211 modelCDMFolder* folder = new modelCDMFolder(this, path + CDMUtilities::SLASH + name, name, level + 1);
212 this->folders.push_back(folder);
213 this->children.push_back(folder);
218 const bool modelCDMLibrary::Refresh(std::string*& result)
220 std::cout << "refreshing library: " << this->nameLibrary << std::endl;
222 this->type = wxDIR_DIRS;
225 std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
227 std::ifstream confFile;
228 confFile.open((pathMakeLists).c_str());
231 while(confFile.is_open() && !confFile.eof())
234 std::getline(confFile,word,'(');
235 std::vector<std::string> wordBits;
236 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
238 if(wordBits[wordBits.size()-1] == "SET")
241 std::getline(confFile,word,')');
242 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
243 if(wordBits[0] == "LIBRARY_NAME")
246 for (int i = 2; i < (int)(wordBits.size()); i++)
248 word += " " + wordBits[i];
251 this->nameLibrary = word;
259 std::vector<bool> checked(this->children.size(), false);
260 std::vector<bool> checkedFolders(this->folders.size(), false);
263 wxDir dir(crea::std2wx((this->path).c_str()));
267 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
270 std::string stdfileName = crea::wx2std(fileName);
271 //check if they already exist
273 for (int i = 0; !found && i < (int)(this->folders.size()); i++)
275 if (this->folders[i]->GetName() == stdfileName)
278 int pos = std::find(this->children.begin(), this->children.end(), this->folders[i]) - this->children.begin();
280 checkedFolders[i] = true;
281 if(!this->folders[i]->Refresh(result))
287 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
288 this->folders.push_back(folder);
289 this->children.push_back(folder);
291 cont = dir.GetNext(&fileName);
294 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
297 std::string stdfileName = crea::wx2std(fileName);
299 //if CMakeLists, create CMakeLists
300 if(stdfileName == "CMakeLists.txt")
302 if (this->CMakeLists == NULL)
304 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
305 this->children.push_back(this->CMakeLists);
309 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
311 if(!this->CMakeLists->Refresh(result))
315 //if is an unknown file, check if exist in children
319 for (int i = 0; !found && i < (int)(this->children.size()); i++)
321 if (this->children[i]->GetName() == stdfileName)
325 if(!this->children[i]->Refresh(result))
332 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
333 this->children.push_back(file);
337 cont = dir.GetNext(&fileName);
341 for (int i = 0; i < (int)(checkedFolders.size()); i++)
343 if(!checkedFolders[i])
345 this->folders.erase(this->folders.begin()+i);
346 checkedFolders.erase(checkedFolders.begin()+i);
350 for (int i = 0; i < (int)(checked.size()); i++)
354 delete this->children[i];
355 this->children.erase(this->children.begin()+i);
356 checked.erase(checked.begin()+i);
360 this->SortChildren();
361 std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
365 void modelCDMLibrary::CheckStructure(std::map<std::string, bool>& properties)
368 if(this->CMakeLists != NULL)
371 properties["library " + this->name + " lib ${crea_LIBRARIES}"] = false;
372 properties["library " + this->name + " lib ${WXWIDGETS_LIBRARIES}"] = false;
373 properties["library " + this->name + " lib ${KWWidgets_LIBRARIES}"] = false;
374 properties["library " + this->name + " lib ${VTK_LIBRARIES}"] = false;
375 properties["library " + this->name + " lib ${ITK_LIBRARIES}"] = false;
376 properties["library " + this->name + " lib ${GDCM_LIBRARIES}"] = false;
377 properties["library " + this->name + " lib ${BOOST_LIBRARIES}"] = false;
381 std::ifstream confFile;
382 confFile.open((this->CMakeLists->GetPath()).c_str());
384 //take everything that is not commented
385 std::string fileContent;
388 std::vector<std::string> words;
389 while(confFile.is_open() && !confFile.eof())
391 std::getline(confFile,word, '\n');
394 CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok);
395 if (words.size() > 0)
398 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
399 for (int i = 0; i < (int)(words.size()); i++)
401 if(words[i].substr(0,2) == "//")
403 fileContent += words[i] + " ";
409 //check every instruction
410 std::stringstream ss(fileContent);
413 std::getline(ss,word, '(');
415 //check instruction name
416 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
419 if (words.size() > 0 && words[words.size()-1] == "SET")
421 std::getline(ss,word, ')');
423 CDMUtilities::splitter::split(words, word, " \t", CDMUtilities::splitter::no_empties);
424 if (words.size() > 1)
426 if (words[0] == "${LIBRARY_NAME}_LINK_LIBRARIES")
428 for (int i = 1; i < (int)(words.size()); i++)
430 properties["library " + this->name + " lib " + words[i]] = true;
440 std::map<std::string, bool> modelCDMLibrary::Get3rdPartyLibraries()
442 std::map<std::string, std::string> correspondence;
443 correspondence["${crea_LIBRARIES}"] = "Crea";
444 correspondence["${WXWIDGETS_LIBRARIES}"] = "WxWidgets";
445 correspondence["${KWWidgets_LIBRARIES}"] = "KWWidgets";
446 correspondence["${VTK_LIBRARIES}"] = "VTK";
447 correspondence["${ITK_LIBRARIES}"] = "ITK";
448 correspondence["${GDCM_LIBRARIES}"] = "GDCM";
449 correspondence["${BOOST_LIBRARIES}"] = "Boost";
450 std::map<std::string, bool> res;
452 res["WxWidgets"] = false;
453 res["KWWidgets"] = false;
457 res["Boost"] = false;
459 if (this->HasCMakeLists())
461 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
463 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
464 std::string::const_iterator start, end;
465 start = CMfile.begin();
467 boost::match_results<std::string::const_iterator> what;
468 boost::match_flag_type flags = boost::match_default;
469 if(boost::regex_search(start, end, what, expression, flags))
472 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES");
473 std::string::const_iterator start1, end1;
474 start1 = what[0].first;
475 end1 = what[0].second;
476 boost::match_results<std::string::const_iterator> what1;
477 if(boost::regex_search(start1, end1, what1, expression, flags))
479 expression = boost::regex("(#[^\\n]*\\n|\\s*\\$\\{\\w+\\})");
480 std::string::const_iterator start2, end2;
481 start2 = what1[0].second;
482 end2 = what[0].second;
483 boost::match_results<std::string::const_iterator> what2;
484 while(boost::regex_search(start2, end2, what2, expression, flags))
486 if(what2.str()[0] != '#')
488 std::string dete = what2.str();
489 CDMUtilities::normalizeStr(dete);
490 if(correspondence.find(dete) != correspondence.end())
491 res[correspondence[dete]] = true;
493 start2 = what2[0].second;
501 bool modelCDMLibrary::Set3rdPartyLibrary(const std::string& library_name, const bool& toInclude)
503 std::map<std::string, std::string> correspondence;
505 correspondence["Crea"] = "${crea_LIBRARIES}";
506 correspondence["WxWidgets"] = "${WXWIDGETS_LIBRARIES}";
507 correspondence["KWWidgets"] = "${KWWidgets_LIBRARIES}";
508 correspondence["VTK"] = "${VTK_LIBRARIES}";
509 correspondence["ITK"] = "${ITK_LIBRARIES}";
510 correspondence["GDCM"] = "${GDCM_LIBRARIES}";
511 correspondence["Boost"] = "${BOOST_LIBRARIES}";
513 std::map<std::string, std::string> regexCorrespondence;
515 regexCorrespondence["Crea"] = "\\$\\{crea_LIBRARIES\\}";
516 regexCorrespondence["WxWidgets"] = "\\$\\{WXWIDGETS_LIBRARIES\\}";
517 regexCorrespondence["KWWidgets"] = "\\$\\{KWWidgets_LIBRARIES\\}";
518 regexCorrespondence["VTK"] = "\\$\\{VTK_LIBRARIES\\}";
519 regexCorrespondence["ITK"] = "\\$\\{ITK_LIBRARIES\\}";
520 regexCorrespondence["GDCM"] = "\\$\\{GDCM_LIBRARIES\\}";
521 regexCorrespondence["Boost"] = "\\$\\{BOOST_LIBRARIES\\}";
523 if (correspondence.find(library_name) != correspondence.end())
525 std::string library_command = correspondence[library_name];
526 std::string regex_command = regexCorrespondence[library_name];
527 if (this->HasCMakeLists())
529 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
530 std::string resCMfile = "";
532 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
533 std::string::const_iterator start, end;
534 start = CMfile.begin();
536 boost::match_results<std::string::const_iterator> what;
537 boost::match_flag_type flags = boost::match_default;
538 if(boost::regex_search(start, end, what, expression, flags))
540 resCMfile += what.prefix().str();
543 expression = "^\\h*#+\\h*" + regex_command;
544 std::string::const_iterator start1, end1;
545 start1 = what[0].first;
546 end1 = what[0].second;
547 boost::match_results<std::string::const_iterator> what1, what2;
548 while(boost::regex_search(start1, end1, what1, expression, flags))
551 resCMfile += what1.prefix().str();
552 std::string dete = what1[0].str();
553 for (int i = 0; i < dete.size(); ++i) {
555 resCMfile.push_back(dete[i]);
558 start1 = what1[0].second;
561 resCMfile += what2.suffix().str();
564 expression = "^\\h*" + regex_command;
565 if(boost::regex_search(start1, end1, what1, expression, flags))
568 expression = "^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES";
569 boost::regex_search(start1, end1, what1, expression, flags);
571 resCMfile += what1.prefix().str() + what1.str();
573 resCMfile += "\n" + library_command + "\n";
574 resCMfile += what1.suffix().str();
578 expression = "^\\h*" + regex_command;
579 std::string::const_iterator start1, end1;
580 start1 = what[0].first;
581 end1 = what[0].second;
582 boost::match_results<std::string::const_iterator> what1, what2;
583 while(boost::regex_search(start1, end1, what1, expression, flags))
586 resCMfile += what1.prefix().str();
587 resCMfile += "#" + what1.str();
589 start1 = what1[0].second;
592 resCMfile += what2.suffix().str();
595 expression = "^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES";
596 boost::regex_search(start1, end1, what1, expression, flags);
598 resCMfile += what1.prefix().str() + what1.str() + what1.suffix().str();
601 resCMfile += what.suffix().str();
603 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
610 std::map<std::string, bool> modelCDMLibrary::GetCustomLibraries()
612 std::map<std::string, bool> res;
613 std::map<std::string, bool> res1;
615 std::map<std::string, std::string> correspondence;
616 std::vector<modelCDMLibrary*> libraries = ((modelCDMLib*)this->parent)->GetLibraries();
617 for (int i = 0; i < libraries.size(); ++i)
619 if(libraries[i]->GetNameLibrary() == this->nameLibrary)
621 correspondence[libraries[i]->GetName()] = libraries[i]->GetNameLibrary();
622 res[libraries[i]->GetNameLibrary()] = false;
623 res1[libraries[i]->GetNameLibrary()] = false;
626 if (this->HasCMakeLists())
628 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
630 //find included libraries
631 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
632 std::string::const_iterator start, end;
633 start = CMfile.begin();
635 boost::match_results<std::string::const_iterator> what;
636 boost::match_flag_type flags = boost::match_default;
637 if(boost::regex_search(start, end, what, expression, flags))
640 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES");
641 std::string::const_iterator start1, end1;
642 start1 = what[0].first;
643 end1 = what[0].second;
644 boost::match_results<std::string::const_iterator> what1;
645 if(boost::regex_search(start1, end1, what1, expression, flags))
647 expression = boost::regex("^\\h*[\\w\\d]+");
648 std::string::const_iterator start2, end2;
649 start2 = what1[0].second;
650 end2 = what[0].second;
651 boost::match_results<std::string::const_iterator> what2;
652 while(boost::regex_search(start2, end2, what2, expression, flags))
654 std::string dete = what2.str();
655 CDMUtilities::normalizeStr(dete);
656 //std::cout << "detectado lib: " << dete << std::endl;
657 if(res1.find(dete) != res1.end())
660 start2 = what2[0].second;
665 //find included folders
666 //std::cout << "searching..." << std::endl;
667 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*([\\./\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"){0,1}?(([\\s]|#[^\\n]*\\n)+([\\./\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
668 start = CMfile.begin();
670 if(boost::regex_search(start, end, what, expression, flags))
672 //std::cout << what.str() << std::endl;
673 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(");
674 std::string::const_iterator start1, end1;
675 start1 = what[0].first;
676 end1 = what[0].second;
677 boost::match_results<std::string::const_iterator> what1;
678 if(boost::regex_search(start1, end1, what1, expression, flags))
680 //std::cout << what1.str() << std::endl;
681 expression = boost::regex("^\\h*\\.\\.\\/([\\w\\d])+");
682 std::string::const_iterator start2, end2;
683 start2 = what1[0].second;
684 end2 = what[0].second;
685 boost::match_results<std::string::const_iterator> what2;
686 while(boost::regex_search(start2, end2, what2, expression, flags))
688 std::string dete = what2.str();
689 CDMUtilities::normalizeStr(dete);
690 //std::cout << "detectado dir: " << dete.substr(3) << std::endl;
691 if(correspondence.find(dete.substr(3)) != correspondence.end())
692 res[correspondence[dete.substr(3)]] = res1[correspondence[dete.substr(3)]];
694 start2 = what2[0].second;
703 bool modelCDMLibrary::SetCustomLibrary(const std::string& library_name, const bool& toInclude)
705 std::map<std::string, std::string> correspondence;
706 std::vector<modelCDMLibrary*> libraries = ((modelCDMLib*)this->parent)->GetLibraries();
707 for (int i = 0; i < libraries.size(); ++i)
709 if(libraries[i]->GetNameLibrary() == this->nameLibrary)
711 correspondence[libraries[i]->GetNameLibrary()] = libraries[i]->GetName();
714 if (correspondence.find(library_name) != correspondence.end())
716 if (this->HasCMakeLists())
718 std::string resCMfile = "";
719 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
722 //find included libraries
723 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
724 std::string::const_iterator start, end;
725 start = CMfile.begin();
727 boost::match_results<std::string::const_iterator> what;
728 boost::match_flag_type flags = boost::match_default;
729 if(boost::regex_search(start, end, what, expression, flags))
731 resCMfile += what.prefix().str();
732 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{LIBRARY_NAME\\}_LINK_LIBRARIES");
733 std::string::const_iterator start1, end1;
734 start1 = what[0].first;
735 end1 = what[0].second;
736 boost::match_results<std::string::const_iterator> what1;
737 if(boost::regex_search(start1, end1, what1, expression, flags))
739 resCMfile += what1.prefix().str() + what1.str();
740 //check if already exists
741 expression = boost::regex("^\\h*"+library_name);
742 std::string::const_iterator start2, end2;
743 start2 = what1[0].second;
744 end2 = what[0].second;
745 boost::match_results<std::string::const_iterator> what2, temp2;
746 while(boost::regex_search(start2, end2, what2, expression, flags))
748 resCMfile += what2.prefix().str();
754 resCMfile += what2.str();
756 start2 = what2[0].second;
759 resCMfile += temp2.suffix().str();
760 //check if is commented
763 expression = boost::regex("^\\h*#+\\h*"+library_name);
764 start2 = what1[0].second;
765 end2 = what[0].second;
766 while(boost::regex_search(start2, end2, what2, expression, flags))
769 resCMfile += what2.prefix().str();
772 std::string dete = what2[0].str();
773 for (int i = 0; i < dete.size(); ++i) {
775 resCMfile.push_back(dete[i]);
779 start2 = what2[0].second;
782 resCMfile += temp2.suffix().str();
783 //add at the beggining of instruction
787 resCMfile += "\n" + library_name;
788 resCMfile += what1.suffix().str();
792 resCMfile += what.suffix().str();
797 //find included folders
803 std::cout << "searching..." << CMfile << std::endl;
804 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"){0,1}?(([\\s]|#[^\\n]*\\n)+([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
805 start = CMfile.begin();
807 if(boost::regex_search(start, end, what, expression, flags))
809 resCMfile += what.prefix().str();
810 std::cout << what.str() << std::endl;
811 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(");
812 std::string::const_iterator start1, end1;
813 start1 = what[0].first;
814 end1 = what[0].second;
815 boost::match_results<std::string::const_iterator> what1;
816 if(boost::regex_search(start1, end1, what1, expression, flags))
818 resCMfile += what1.prefix().str() + what1.str();
819 std::cout << what1.str() << std::endl;
820 //search if dir is already included
821 expression = boost::regex("^\\h*\\.\\.\\/"+correspondence[library_name]);
822 std::string::const_iterator start2, end2;
823 start2 = what1[0].second;
824 end2 = what[0].second;
825 boost::match_results<std::string::const_iterator> what2, temp2;
826 while(boost::regex_search(start2, end2, what2, expression, flags))
829 resCMfile += what2.prefix().str();
832 resCMfile += what2.str();
834 start2 = what2[0].second;
837 resCMfile += temp2.suffix().str();
838 //search if dir is commented
841 expression = boost::regex("^\\h*#+\\h*\\.\\.\\/"+correspondence[library_name]);
842 start2 = what1[0].second;
843 end2 = what[0].second;
844 while(boost::regex_search(start2, end2, what2, expression, flags))
847 resCMfile += what2.prefix().str();
850 std::string dete = what2[0].str();
851 for (int i = 0; i < dete.size(); ++i) {
853 resCMfile.push_back(dete[i]);
857 start2 = what2[0].second;
860 resCMfile += temp2.suffix().str();
861 //add at the beggining of instruction
865 resCMfile += "\n../" + correspondence[library_name];
866 resCMfile += what1.suffix().str();
870 resCMfile += what.suffix().str();
875 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);