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 # ------------------------------------------------------------------------
29 * modelCDMApplication.cpp
31 * Created on: Nov 23, 2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "modelCDMApplication.h"
37 #include "modelCDMProject.h"
38 #include "modelCDMLib.h"
39 #include "modelCDMLibrary.h"
44 #include <boost/regex.hpp>
46 #include "CDMUtilities.h"
50 modelCDMApplication::modelCDMApplication()
55 modelCDMApplication::modelCDMApplication(modelCDMIProjectTreeNode* parent, const std::string& path, const std::string& name, const int& level)
57 std::cout << "creating application: " + path + "\n";
58 this->parent = parent;
59 this->mainFile = NULL;
63 this->path = CDMUtilities::fixPath(path);
65 this->type = wxDIR_DIRS;
69 std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
71 std::ifstream confFile;
72 confFile.open((pathMakeLists).c_str());
75 while(confFile.is_open() && !confFile.eof())
78 std::getline(confFile,word,'(');
79 std::vector<std::string> wordBits;
80 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
82 if(wordBits[wordBits.size()-1] == "SET")
85 std::getline(confFile,word,')');
86 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
87 if(wordBits[0] == "EXE_NAME")
90 for (int i = 2; i < (int)(wordBits.size()); i++)
92 word += " " + wordBits[i];
95 this->executableName = word;
101 //add library contents
103 this->children.clear();
104 wxDir dir(crea::std2wx((this->path).c_str()));
109 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
112 std::string stdfileName = crea::wx2std(fileName);
114 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
115 this->folders.push_back(folder);
116 this->children.push_back(folder);
118 cont = dir.GetNext(&fileName);
121 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
124 std::string stdfileName = crea::wx2std(fileName);
125 //if CMakeLists, create CMakeLists
126 if(stdfileName == "CMakeLists.txt")
128 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
129 this->children.push_back(this->CMakeLists);
131 //if is an unknown file, create file
134 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
135 std::string extension = stdfileName.substr(stdfileName.size()-4);
136 //if is cxx or cpp check if is the main file.
137 if (mainFile == NULL && (extension == ".cxx" || extension == ".cpp"))
139 std::ifstream fileStream((this->path + CDMUtilities::SLASH + stdfileName).c_str());
141 if (fileStream.is_open())
143 std::string fileContent = "";
144 char ch = fileStream.get();
145 while(!fileStream.eof())
147 fileContent.push_back(ch);
148 ch = fileStream.get();
152 boost::regex expression("^\\h*IMPLEMENT_APP[#\\s\\(]");
153 std::string::const_iterator start, end;
154 start = fileContent.begin();
155 end = fileContent.end();
156 boost::match_results<std::string::const_iterator> what;
157 boost::match_flag_type flags = boost::match_default;
158 if(boost::regex_search(start, end, what, expression, flags))
160 std::cout << "found main wxwidgets file: " << stdfileName << std::endl;
161 this->mainFile = file;
165 expression = boost::regex("^\\h*int\\h+main[#\\s\\(]");
166 start = fileContent.begin();
167 end = fileContent.end();
168 if(boost::regex_search(start, end, what, expression, flags))
170 std::cout << "found main console file: " << stdfileName << std::endl;
171 this->mainFile = file;
177 this->children.push_back(file);
180 cont = dir.GetNext(&fileName);
183 this->SortChildren();
184 std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
187 modelCDMApplication::~modelCDMApplication()
191 const std::string& modelCDMApplication::GetExecutableName() const
193 return this->executableName;
196 modelCDMFile* modelCDMApplication::GetMainFile() const
198 return this->mainFile;
201 bool modelCDMApplication::SetExecutableName(const std::string& fileName, std::string*& result)
203 std::vector<std::string> words;
204 CDMUtilities::splitter::split(words, fileName, ", /\\\"", CDMUtilities::splitter::no_empties);
205 std::string fileNameReal = words[0];
206 for (int i = 1; i < (int)(words.size()); i++)
208 fileNameReal += "-" + words[i];
212 //opening original cmakelists
213 std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
216 result = new std::string("CMakeLists.txt file failed to open.");
219 //opening temporal cmakelists
220 std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
223 result = new std::string("CMakeLists.txt.tmp file failed to open.");
226 //copying contents from original to temporal and making changes
227 while (getline(in, line))
229 if(line.find("SET ( EXE_NAME") != std::string::npos)
230 line = "SET ( EXE_NAME " + fileNameReal + " )";
231 out << line << std::endl;
235 //delete old file and rename new file
237 std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
239 std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
242 if(system(renameCommand.c_str()))
244 result = new std::string("An error occurred while running '" + renameCommand + "'.");
248 this->executableName = fileNameReal;
252 modelCDMFolder* modelCDMApplication::CreateFolder(const std::string& name, std::string*& result)
254 //TODO:: mkdir depending on OS
255 std::string command = "mkdir " + path + CDMUtilities::SLASH + name;
256 if(system(command.c_str()))
258 result = new std::string("Error executing: " + command + ".");
261 modelCDMFolder* folder = new modelCDMFolder(this, path + CDMUtilities::SLASH + name, name, level + 1);
262 this->folders.push_back(folder);
263 this->children.push_back(folder);
268 const bool modelCDMApplication::Refresh(std::string*& result)
270 this->mainFile = NULL;
271 std::cout << "refreshing application: " << this->executableName << std::endl;
273 this->type = wxDIR_DIRS;
276 std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
278 std::ifstream confFile;
279 confFile.open((pathMakeLists).c_str());
282 while(confFile.is_open() && !confFile.eof())
285 std::getline(confFile,word,'(');
286 std::vector<std::string> wordBits;
287 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
289 if(wordBits[wordBits.size()-1] == "SET")
292 std::getline(confFile,word,')');
293 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
294 if(wordBits[0] == "EXE_NAME")
297 for (int i = 2; i < (int)(wordBits.size()); i++)
299 word += " " + wordBits[i];
302 this->executableName = word;
310 std::vector<bool> checked(this->children.size(), false);
311 std::vector<bool> checkedFolders(this->folders.size(), false);
314 wxDir dir(crea::std2wx((this->path).c_str()));
318 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
321 std::string stdfileName = crea::wx2std(fileName);
322 std::string applicationName = stdfileName;
323 //check if they already exist
325 for (int i = 0; !found && i < (int)(this->folders.size()); i++)
327 if (this->folders[i]->GetName() == applicationName)
330 int pos = std::find(this->children.begin(), this->children.end(), this->folders[i]) - this->children.begin();
332 checkedFolders[i] = true;
333 if(!this->folders[i]->Refresh(result))
339 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
340 this->folders.push_back(folder);
341 this->children.push_back(folder);
343 cont = dir.GetNext(&fileName);
346 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
349 std::string stdfileName = crea::wx2std(fileName);
351 //if CMakeLists, create CMakeLists
352 if(stdfileName == "CMakeLists.txt")
354 if (this->CMakeLists == NULL)
356 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
357 this->children.push_back(this->CMakeLists);
361 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
363 if(!this->CMakeLists->Refresh(result))
367 //if is an unknown file, create file
371 for (int i = 0; !found && i < (int)(this->children.size()); i++)
373 if (this->children[i]->GetName() == stdfileName)
378 if(!this->children[i]->Refresh(result))
381 std::string extension = stdfileName.substr(stdfileName.size()-4);
382 if (mainFile == NULL && (extension == ".cxx" || extension == ".cpp"))
384 std::ifstream fileStream;
386 fileStream.open((this->path + CDMUtilities::SLASH + stdfileName).c_str());
387 while (fileStream.is_open() && !fileStream.eof())
390 std::getline(fileStream,word,'(');
391 std::vector<std::string> wordBits;
392 CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
393 if (wordBits[wordBits.size() - 1] == "main" || wordBits[wordBits.size() - 1] == "IMPLEMENT_APP")
395 this->mainFile = dynamic_cast<modelCDMFile*>(children[i]);
405 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
407 std::string extension = stdfileName.substr(stdfileName.size()-4);
408 if (mainFile == NULL && (extension == ".cxx" || extension == ".cpp"))
410 std::ifstream fileStream;
412 fileStream.open((this->path + CDMUtilities::SLASH + stdfileName).c_str());
413 while (fileStream.is_open() && !fileStream.eof())
416 std::getline(fileStream,word,'(');
417 std::vector<std::string> wordBits;
418 CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
419 if (wordBits[wordBits.size() - 1] == "main" || wordBits[wordBits.size() - 1] == "IMPLEMENT_APP")
421 this->mainFile = file;
427 this->children.push_back(file);
431 cont = dir.GetNext(&fileName);
435 for (int i = 0; i < (int)(checkedFolders.size()); i++)
437 if(!checkedFolders[i])
439 this->folders.erase(this->folders.begin()+i);
440 checkedFolders.erase(checkedFolders.begin()+i);
444 for (int i = 0; i < (int)(checked.size()); i++)
448 delete this->children[i];
449 this->children.erase(this->children.begin()+i);
450 checked.erase(checked.begin()+i);
454 this->SortChildren();
458 void modelCDMApplication::CheckStructure(std::map<std::string, bool>& properties)
461 if(this->CMakeLists != NULL)
463 //set default properties
464 properties["application " + this->name + " lib ${crea_LIBRARIES}"] = false;
465 properties["application " + this->name + " lib ${WXWIDGETS_LIBRARIES}"] = false;
466 properties["application " + this->name + " lib ${KWWidgets_LIBRARIES}"] = false;
467 properties["application " + this->name + " lib ${VTK_LIBRARIES}"] = false;
468 properties["application " + this->name + " lib ${ITK_LIBRARIES}"] = false;
469 properties["application " + this->name + " lib ${GDCM_LIBRARIES}"] = false;
470 properties["application " + this->name + " lib ${BOOST_LIBRARIES}"] = false;
473 std::ifstream confFile;
474 confFile.open((this->CMakeLists->GetPath()).c_str());
476 //take everything that is not commented
477 std::string fileContent;
480 std::vector<std::string> words;
481 while(confFile.is_open() && !confFile.eof())
483 std::getline(confFile,word, '\n');
486 CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok);
487 if (words.size() > 0)
490 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
491 for (int i = 0; i < (int)(words.size()); i++)
493 if(words[i].substr(0,2) == "//")
495 fileContent += words[i] + " ";
501 //check every instruction
502 std::stringstream ss(fileContent);
505 std::getline(ss,word, '(');
507 //check instruction name
508 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
511 if (words.size() > 0 && words[words.size()-1] == "SET")
513 std::getline(ss,word, ')');
515 CDMUtilities::splitter::split(words, word, " \t", CDMUtilities::splitter::no_empties);
516 if (words.size() > 1)
518 if (words[0] == "${EXE_NAME}_LINK_LIBRARIES")
520 for (int i = 1; i < (int)(words.size()); i++)
522 properties["application " + this->name + " lib " + words[i]] = true;
527 else if (words.size() > 0 && words[words.size()-1] == "INCLUDE_DIRECTORIES")
529 std::getline(ss,word, ')');
531 CDMUtilities::splitter::split(words, word, " \t", CDMUtilities::splitter::no_empties);
533 for (int i = 0; i < (int)(words.size()); i++)
535 properties["application " + this->name + " dir " + words[i]] = true;
545 std::map<std::string, bool> modelCDMApplication::Get3rdPartyLibraries()
547 std::map<std::string, std::string> correspondence;
548 correspondence["${crea_LIBRARIES}"] = "Crea";
549 correspondence["${WXWIDGETS_LIBRARIES}"] = "WxWidgets";
550 correspondence["${KWWidgets_LIBRARIES}"] = "KWWidgets";
551 correspondence["${VTK_LIBRARIES}"] = "VTK";
552 correspondence["${ITK_LIBRARIES}"] = "ITK";
553 correspondence["${GDCM_LIBRARIES}"] = "GDCM";
554 correspondence["${BOOST_LIBRARIES}"] = "Boost";
555 std::map<std::string, bool> res;
557 res["WxWidgets"] = false;
558 res["KWWidgets"] = false;
562 res["Boost"] = false;
564 if (this->HasCMakeLists())
567 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
569 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_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))
578 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES");
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;
583 if(boost::regex_search(start1, end1, what1, expression, flags))
585 expression = boost::regex("(#[^\\n]*\\n|\\s*\\$\\{\\w+\\})");
586 std::string::const_iterator start2, end2;
587 start2 = what1[0].second;
588 end2 = what[0].second;
589 boost::match_results<std::string::const_iterator> what2;
590 while(boost::regex_search(start2, end2, what2, expression, flags))
592 if(what2.str()[0] != '#')
594 std::string dete = what2.str();
595 CDMUtilities::normalizeStr(dete);
596 if(correspondence.find(dete) != correspondence.end())
597 res[correspondence[dete]] = true;
599 start2 = what2[0].second;
607 bool modelCDMApplication::Set3rdPartyLibrary(const std::string& library_name, const bool& toInclude)
609 std::map<std::string, std::string> correspondence;
611 correspondence["Crea"] = "${crea_LIBRARIES}";
612 correspondence["WxWidgets"] = "${WXWIDGETS_LIBRARIES}";
613 correspondence["KWWidgets"] = "${KWWidgets_LIBRARIES}";
614 correspondence["VTK"] = "${VTK_LIBRARIES}";
615 correspondence["ITK"] = "${ITK_LIBRARIES}";
616 correspondence["GDCM"] = "${GDCM_LIBRARIES}";
617 correspondence["Boost"] = "${BOOST_LIBRARIES}";
619 std::map<std::string, std::string> regexCorrespondence;
621 regexCorrespondence["Crea"] = "\\$\\{crea_LIBRARIES\\}";
622 regexCorrespondence["WxWidgets"] = "\\$\\{WXWIDGETS_LIBRARIES\\}";
623 regexCorrespondence["KWWidgets"] = "\\$\\{KWWidgets_LIBRARIES\\}";
624 regexCorrespondence["VTK"] = "\\$\\{VTK_LIBRARIES\\}";
625 regexCorrespondence["ITK"] = "\\$\\{ITK_LIBRARIES\\}";
626 regexCorrespondence["GDCM"] = "\\$\\{GDCM_LIBRARIES\\}";
627 regexCorrespondence["Boost"] = "\\$\\{BOOST_LIBRARIES\\}";
629 if (correspondence.find(library_name) != correspondence.end())
631 std::string library_command = correspondence[library_name];
632 std::string regex_command = regexCorrespondence[library_name];
633 if (this->HasCMakeLists())
635 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
636 std::string resCMfile = "";
638 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
639 std::string::const_iterator start, end;
640 start = CMfile.begin();
642 boost::match_results<std::string::const_iterator> what;
643 boost::match_flag_type flags = boost::match_default;
644 if(boost::regex_search(start, end, what, expression, flags))
646 resCMfile += what.prefix().str();
649 expression = "^\\h*#+\\h*" + regex_command;
650 std::string::const_iterator start1, end1;
651 start1 = what[0].first;
652 end1 = what[0].second;
653 boost::match_results<std::string::const_iterator> what1, what2;
654 while(boost::regex_search(start1, end1, what1, expression, flags))
657 resCMfile += what1.prefix().str();
658 std::string dete = what1[0].str();
659 for (int i = 0; i < dete.size(); ++i) {
661 resCMfile.push_back(dete[i]);
664 start1 = what1[0].second;
667 resCMfile += what2.suffix().str();
670 expression = "^\\h*" + regex_command;
671 if(boost::regex_search(start1, end1, what1, expression, flags))
674 expression = "^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES";
675 boost::regex_search(start1, end1, what1, expression, flags);
677 resCMfile += what1.prefix().str() + what1.str();
679 resCMfile += "\n" + library_command + "\n";
680 resCMfile += what1.suffix().str();
684 expression = "^\\h*" + regex_command;
685 std::string::const_iterator start1, end1;
686 start1 = what[0].first;
687 end1 = what[0].second;
688 boost::match_results<std::string::const_iterator> what1, what2;
689 while(boost::regex_search(start1, end1, what1, expression, flags))
692 resCMfile += what1.prefix().str();
693 resCMfile += "#" + what1.str();
695 start1 = what1[0].second;
698 resCMfile += what2.suffix().str();
701 expression = "^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES";
702 boost::regex_search(start1, end1, what1, expression, flags);
704 resCMfile += what1.prefix().str() + what1.str() + what1.suffix().str();
707 resCMfile += what.suffix().str();
709 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
717 std::map<std::string, bool> modelCDMApplication::GetCustomLibraries()
719 std::map<std::string, bool> res;
720 std::map<std::string, bool> res1;
722 std::map<std::string, std::string> correspondence;
723 std::vector<modelCDMLibrary*> libraries;
724 if(this->GetParent() != NULL && this->GetParent()->GetParent() != NULL)
725 if(dynamic_cast<modelCDMProject*>(this->GetParent()->GetParent()) != NULL && dynamic_cast<modelCDMProject*>(this->GetParent()->GetParent())->GetLib() != NULL)
726 libraries = (dynamic_cast<modelCDMProject*>(this->GetParent()->GetParent()))->GetLib()->GetLibraries();
727 for (int i = 0; i < libraries.size(); ++i)
729 correspondence[libraries[i]->GetName()] = libraries[i]->GetNameLibrary();
730 res[libraries[i]->GetNameLibrary()] = false;
731 res1[libraries[i]->GetNameLibrary()] = false;
734 if (this->HasCMakeLists())
736 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
738 //find included libraries
739 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
740 std::string::const_iterator start, end;
741 start = CMfile.begin();
743 boost::match_results<std::string::const_iterator> what;
744 boost::match_flag_type flags = boost::match_default;
745 if(boost::regex_search(start, end, what, expression, flags))
748 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES");
749 std::string::const_iterator start1, end1;
750 start1 = what[0].first;
751 end1 = what[0].second;
752 boost::match_results<std::string::const_iterator> what1;
753 if(boost::regex_search(start1, end1, what1, expression, flags))
755 expression = boost::regex("^\\h*[\\w\\d]+");
756 std::string::const_iterator start2, end2;
757 start2 = what1[0].second;
758 end2 = what[0].second;
759 boost::match_results<std::string::const_iterator> what2;
760 while(boost::regex_search(start2, end2, what2, expression, flags))
762 std::string dete = what2.str();
763 CDMUtilities::normalizeStr(dete);
764 //std::cout << "detectado lib: " << dete << std::endl;
765 if(res1.find(dete) != res1.end())
768 start2 = what2[0].second;
773 //find included folders
774 //std::cout << "searching..." << std::endl;
775 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*([\\./\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\")(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
776 start = CMfile.begin();
778 if(boost::regex_search(start, end, what, expression, flags))
780 //std::cout << what.str() << std::endl;
781 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(");
782 std::string::const_iterator start1, end1;
783 start1 = what[0].first;
784 end1 = what[0].second;
785 boost::match_results<std::string::const_iterator> what1;
786 if(boost::regex_search(start1, end1, what1, expression, flags))
788 //std::cout << what1.str() << std::endl;
789 expression = boost::regex("^\\h*\\.\\.\\/\\.\\.\\/lib\\/([\\w\\d])+");
790 std::string::const_iterator start2, end2;
791 start2 = what1[0].second;
792 end2 = what[0].second;
793 boost::match_results<std::string::const_iterator> what2;
794 while(boost::regex_search(start2, end2, what2, expression, flags))
796 std::string dete = what2.str();
797 CDMUtilities::normalizeStr(dete);
798 //std::cout << "detectado dir: " << dete.substr(10) << std::endl;
799 if(correspondence.find(dete.substr(10)) != correspondence.end())
800 res[correspondence[dete.substr(10)]] = res1[correspondence[dete.substr(10)]];
802 start2 = what2[0].second;
811 bool modelCDMApplication::SetCustomLibrary(const std::string& library_name, const bool& toInclude)
813 std::map<std::string, std::string> correspondence;
815 std::vector<modelCDMLibrary*> libraries;
816 modelCDMIProjectTreeNode* p = this;
817 while(p != NULL && dynamic_cast<modelCDMProject*>(p) == NULL)
820 if(p != NULL && dynamic_cast<modelCDMProject*>(p)->GetLib() != NULL)
821 libraries = dynamic_cast<modelCDMProject*>(p)->GetLib()->GetLibraries();
823 for (int i = 0; i < libraries.size(); ++i)
825 correspondence[libraries[i]->GetNameLibrary()] = libraries[i]->GetName();
828 if (correspondence.find(library_name) != correspondence.end())
830 if (this->HasCMakeLists())
832 std::string resCMfile = "";
833 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
836 //find included libraries
837 std::cout << "searching..." << CMfile << std::endl;
838 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
839 std::string::const_iterator start, end;
840 start = CMfile.begin();
842 boost::match_results<std::string::const_iterator> what;
843 boost::match_flag_type flags = boost::match_default;
844 if(boost::regex_search(start, end, what, expression, flags))
846 std::cout << what.str() << std::endl;
847 resCMfile += what.prefix().str();
848 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES");
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 //check if already exists
857 expression = boost::regex("^\\h*"+library_name);
858 std::string::const_iterator start2, end2;
859 start2 = what1[0].second;
860 end2 = what[0].second;
861 boost::match_results<std::string::const_iterator> what2, temp2;
862 while(boost::regex_search(start2, end2, what2, expression, flags))
864 resCMfile += what2.prefix().str();
870 resCMfile += what2.str();
872 start2 = what2[0].second;
875 resCMfile += temp2.suffix().str();
876 //check if is commented
879 expression = boost::regex("^\\h*#+\\h*"+library_name);
880 start2 = what1[0].second;
881 end2 = what[0].second;
882 while(boost::regex_search(start2, end2, what2, expression, flags))
885 resCMfile += what2.prefix().str();
888 std::string dete = what2[0].str();
889 for (int i = 0; i < dete.size(); ++i) {
891 resCMfile.push_back(dete[i]);
895 start2 = what2[0].second;
898 resCMfile += temp2.suffix().str();
899 //add at the beggining of instruction
903 resCMfile += "\n" + library_name;
904 resCMfile += what1.suffix().str();
908 resCMfile += what.suffix().str();
913 //find included folders
919 std::cout << "searching..." << CMfile << std::endl;
920 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\")??(([\\s]|#[^\\n]*\\n)+([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
921 start = CMfile.begin();
923 if(boost::regex_search(start, end, what, expression, flags))
925 resCMfile += what.prefix().str();
926 std::cout << what.str() << std::endl;
927 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(");
928 std::string::const_iterator start1, end1;
929 start1 = what[0].first;
930 end1 = what[0].second;
931 boost::match_results<std::string::const_iterator> what1;
932 if(boost::regex_search(start1, end1, what1, expression, flags))
934 resCMfile += what1.prefix().str() + what1.str();
935 std::cout << what1.str() << std::endl;
936 //search if dir is already included
937 expression = boost::regex("^\\h*\\.\\.\\/\\.\\.\\/lib\\/"+correspondence[library_name]);
938 std::string::const_iterator start2, end2;
939 start2 = what1[0].second;
940 end2 = what[0].second;
941 boost::match_results<std::string::const_iterator> what2, temp2;
942 while(boost::regex_search(start2, end2, what2, expression, flags))
945 resCMfile += what2.prefix().str();
948 resCMfile += what2.str();
950 start2 = what2[0].second;
953 resCMfile += temp2.suffix().str();
954 //search if dir is commented
957 expression = boost::regex("^\\h*#+\\h*\\.\\.\\/\\.\\.\\/lib\\/"+correspondence[library_name]);
958 start2 = what1[0].second;
959 end2 = what[0].second;
960 while(boost::regex_search(start2, end2, what2, expression, flags))
963 resCMfile += what2.prefix().str();
966 std::string dete = what2[0].str();
967 for (int i = 0; i < dete.size(); ++i) {
969 resCMfile.push_back(dete[i]);
973 start2 = what2[0].second;
976 resCMfile += temp2.suffix().str();
977 //add at the beggining of instruction
981 resCMfile += "\n../../lib/" + correspondence[library_name];
982 resCMfile += what1.suffix().str();
986 resCMfile += what.suffix().str();
991 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);