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 std::size_t fileTypePos = stdfileName.find_last_of(".");
126 std::string fileType;
127 if(fileTypePos != std::string::npos)
128 fileType = stdfileName.substr(fileTypePos);
132 //if CMakeLists, create CMakeLists
133 if(stdfileName == "CMakeLists.txt")
135 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
136 this->children.push_back(this->CMakeLists);
140 //if is a code file, create modelCDMCodeFile and check for main file
143 fileType == ".cxx" ||
145 fileType == ".cpp" ||
146 fileType == ".txx" ||
147 fileType == ".cmake" )
149 modelCDMCodeFile* file = new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
151 if (mainFile == NULL && (fileType == ".cxx" || fileType == ".cpp"))
153 std::ifstream fileStream((this->path + CDMUtilities::SLASH + stdfileName).c_str());
155 if (fileStream.is_open())
157 std::string fileContent = "";
158 char ch = fileStream.get();
159 while(!fileStream.eof())
161 fileContent.push_back(ch);
162 ch = fileStream.get();
166 boost::regex expression("^\\h*IMPLEMENT_APP[#\\s\\(]");
167 std::string::const_iterator start, end;
168 start = fileContent.begin();
169 end = fileContent.end();
170 boost::match_results<std::string::const_iterator> what;
171 boost::match_flag_type flags = boost::match_default;
172 if(boost::regex_search(start, end, what, expression, flags))
174 std::cout << "found main wxwidgets file: " << stdfileName << std::endl;
175 this->mainFile = file;
179 expression = boost::regex("^\\h*int\\h+main[#\\s\\(]");
180 start = fileContent.begin();
181 end = fileContent.end();
182 if(boost::regex_search(start, end, what, expression, flags))
184 std::cout << "found main console file: " << stdfileName << std::endl;
185 this->mainFile = file;
190 this->children.push_back(file);
192 //if is an unknown file, create file
195 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
196 this->children.push_back(file);
201 cont = dir.GetNext(&fileName);
204 this->SortChildren();
205 std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
208 modelCDMApplication::~modelCDMApplication()
212 const std::string& modelCDMApplication::GetExecutableName() const
214 return this->executableName;
217 modelCDMFile* modelCDMApplication::GetMainFile() const
219 return this->mainFile;
222 bool modelCDMApplication::SetExecutableName(const std::string& fileName, std::string*& result)
224 std::vector<std::string> words;
225 CDMUtilities::splitter::split(words, fileName, ", /\\\"", CDMUtilities::splitter::no_empties);
226 std::string fileNameReal = words[0];
227 for (int i = 1; i < (int)(words.size()); i++)
229 fileNameReal += "-" + words[i];
233 //opening original cmakelists
234 std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
237 result = new std::string("CMakeLists.txt file failed to open.");
240 //opening temporal cmakelists
241 std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
244 result = new std::string("CMakeLists.txt.tmp file failed to open.");
247 //copying contents from original to temporal and making changes
248 while (getline(in, line))
250 if(line.find("SET ( EXE_NAME") != std::string::npos)
251 line = "SET ( EXE_NAME " + fileNameReal + " )";
252 out << line << std::endl;
256 //delete old file and rename new file
258 std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
260 std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
263 if(system(renameCommand.c_str()))
265 result = new std::string("An error occurred while running '" + renameCommand + "'.");
269 this->executableName = fileNameReal;
273 modelCDMFolder* modelCDMApplication::CreateFolder(const std::string& name, std::string*& result)
275 //TODO:: mkdir depending on OS
276 std::string command = "mkdir " + path + CDMUtilities::SLASH + name;
277 if(system(command.c_str()))
279 result = new std::string("Error executing: " + command + ".");
282 modelCDMFolder* folder = new modelCDMFolder(this, path + CDMUtilities::SLASH + name, name, level + 1);
283 this->folders.push_back(folder);
284 this->children.push_back(folder);
289 const bool modelCDMApplication::Refresh(std::string*& result)
291 this->mainFile = NULL;
292 std::cout << "refreshing application: " << this->executableName << std::endl;
294 this->type = wxDIR_DIRS;
297 std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
299 std::ifstream confFile;
300 confFile.open((pathMakeLists).c_str());
303 while(confFile.is_open() && !confFile.eof())
306 std::getline(confFile,word,'(');
307 std::vector<std::string> wordBits;
308 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
310 if(wordBits[wordBits.size()-1] == "SET")
313 std::getline(confFile,word,')');
314 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
315 if(wordBits[0] == "EXE_NAME")
318 for (int i = 2; i < (int)(wordBits.size()); i++)
320 word += " " + wordBits[i];
323 this->executableName = word;
331 std::vector<bool> checked(this->children.size(), false);
332 std::vector<bool> checkedFolders(this->folders.size(), false);
335 wxDir dir(crea::std2wx((this->path).c_str()));
339 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
342 std::string stdfileName = crea::wx2std(fileName);
343 std::string applicationName = stdfileName;
344 //check if they already exist
346 for (int i = 0; !found && i < (int)(this->folders.size()); i++)
348 if (this->folders[i]->GetName() == applicationName)
351 int pos = std::find(this->children.begin(), this->children.end(), this->folders[i]) - this->children.begin();
353 checkedFolders[i] = true;
354 if(!this->folders[i]->Refresh(result))
360 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
361 this->folders.push_back(folder);
362 this->children.push_back(folder);
364 cont = dir.GetNext(&fileName);
367 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
370 std::string stdfileName = crea::wx2std(fileName);
371 std::size_t fileTypePos = stdfileName.find_last_of(".");
372 std::string fileType;
373 if(fileTypePos != std::string::npos)
374 fileType = stdfileName.substr(fileTypePos);
378 //if CMakeLists, create CMakeLists
379 if(stdfileName == "CMakeLists.txt")
381 if (this->CMakeLists == NULL)
383 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
384 this->children.push_back(this->CMakeLists);
388 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
390 if(!this->CMakeLists->Refresh(result))
394 // if is a code file, create modelCDMCodeFile
395 // if is an unknown file, create file
399 for (int i = 0; !found && i < (int)(this->children.size()); i++)
401 if (this->children[i]->GetName() == stdfileName)
406 if(!this->children[i]->Refresh(result))
409 std::string extension = stdfileName.substr(stdfileName.size()-4);
410 if (mainFile == NULL && (extension == ".cxx" || extension == ".cpp"))
412 std::ifstream fileStream;
414 fileStream.open((this->path + CDMUtilities::SLASH + stdfileName).c_str());
415 while (fileStream.is_open() && !fileStream.eof())
418 std::getline(fileStream,word,'(');
419 std::vector<std::string> wordBits;
420 CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
421 if (wordBits[wordBits.size() - 1] == "main" || wordBits[wordBits.size() - 1] == "IMPLEMENT_APP")
423 this->mainFile = dynamic_cast<modelCDMCodeFile*>(children[i]);
433 if (fileType == ".c" ||
434 fileType == ".cxx" ||
436 fileType == ".cpp" ||
437 fileType == ".txx" ||
438 fileType == ".cmake" )
440 modelCDMCodeFile* file = new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
442 if(mainFile == NULL && (fileType == ".cxx" || fileType == ".cpp"))
444 std::ifstream fileStream;
446 fileStream.open((this->path + CDMUtilities::SLASH + stdfileName).c_str());
447 while (fileStream.is_open() && !fileStream.eof())
450 std::getline(fileStream,word,'(');
451 std::vector<std::string> wordBits;
452 CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
453 if (wordBits[wordBits.size() - 1] == "main" || wordBits[wordBits.size() - 1] == "IMPLEMENT_APP")
455 this->mainFile = file;
460 this->children.push_back(file);
464 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
465 this->children.push_back(file);
470 cont = dir.GetNext(&fileName);
474 for (int i = 0; i < (int)(checkedFolders.size()); i++)
476 if(!checkedFolders[i])
478 this->folders.erase(this->folders.begin()+i);
479 checkedFolders.erase(checkedFolders.begin()+i);
483 for (int i = 0; i < (int)(checked.size()); i++)
487 delete this->children[i];
488 this->children.erase(this->children.begin()+i);
489 checked.erase(checked.begin()+i);
493 this->SortChildren();
497 void modelCDMApplication::CheckStructure(std::map<std::string, bool>& properties)
500 if(this->CMakeLists != NULL)
502 //set default properties
503 properties["application " + this->name + " lib ${crea_LIBRARIES}"] = false;
504 properties["application " + this->name + " lib ${WXWIDGETS_LIBRARIES}"] = false;
505 properties["application " + this->name + " lib ${KWWidgets_LIBRARIES}"] = false;
506 properties["application " + this->name + " lib ${VTK_LIBRARIES}"] = false;
507 properties["application " + this->name + " lib ${ITK_LIBRARIES}"] = false;
508 properties["application " + this->name + " lib ${GDCM_LIBRARIES}"] = false;
509 properties["application " + this->name + " lib ${BOOST_LIBRARIES}"] = false;
512 std::ifstream confFile;
513 confFile.open((this->CMakeLists->GetPath()).c_str());
515 //take everything that is not commented
516 std::string fileContent;
519 std::vector<std::string> words;
520 while(confFile.is_open() && !confFile.eof())
522 std::getline(confFile,word, '\n');
525 CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok);
526 if (words.size() > 0)
529 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
530 for (int i = 0; i < (int)(words.size()); i++)
532 if(words[i].substr(0,2) == "//")
534 fileContent += words[i] + " ";
540 //check every instruction
541 std::stringstream ss(fileContent);
544 std::getline(ss,word, '(');
546 //check instruction name
547 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
550 if (words.size() > 0 && words[words.size()-1] == "SET")
552 std::getline(ss,word, ')');
554 CDMUtilities::splitter::split(words, word, " \t", CDMUtilities::splitter::no_empties);
555 if (words.size() > 1)
557 if (words[0] == "${EXE_NAME}_LINK_LIBRARIES")
559 for (int i = 1; i < (int)(words.size()); i++)
561 properties["application " + this->name + " lib " + words[i]] = true;
566 else if (words.size() > 0 && words[words.size()-1] == "INCLUDE_DIRECTORIES")
568 std::getline(ss,word, ')');
570 CDMUtilities::splitter::split(words, word, " \t", CDMUtilities::splitter::no_empties);
572 for (int i = 0; i < (int)(words.size()); i++)
574 properties["application " + this->name + " dir " + words[i]] = true;
584 std::map<std::string, bool> modelCDMApplication::Get3rdPartyLibraries()
586 std::map<std::string, std::string> correspondence;
587 correspondence["${crea_LIBRARIES}"] = "Crea";
588 correspondence["${WXWIDGETS_LIBRARIES}"] = "WxWidgets";
589 correspondence["${KWWidgets_LIBRARIES}"] = "KWWidgets";
590 correspondence["${VTK_LIBRARIES}"] = "VTK";
591 correspondence["${ITK_LIBRARIES}"] = "ITK";
592 correspondence["${GDCM_LIBRARIES}"] = "GDCM";
593 correspondence["${BOOST_LIBRARIES}"] = "Boost";
594 std::map<std::string, bool> res;
596 res["WxWidgets"] = false;
597 res["KWWidgets"] = false;
601 res["Boost"] = false;
603 if (this->HasCMakeLists())
606 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
608 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
609 std::string::const_iterator start, end;
610 start = CMfile.begin();
612 boost::match_results<std::string::const_iterator> what;
613 boost::match_flag_type flags = boost::match_default;
614 if(boost::regex_search(start, end, what, expression, flags))
617 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES");
618 std::string::const_iterator start1, end1;
619 start1 = what[0].first;
620 end1 = what[0].second;
621 boost::match_results<std::string::const_iterator> what1;
622 if(boost::regex_search(start1, end1, what1, expression, flags))
624 expression = boost::regex("(#[^\\n]*\\n|\\s*\\$\\{\\w+\\})");
625 std::string::const_iterator start2, end2;
626 start2 = what1[0].second;
627 end2 = what[0].second;
628 boost::match_results<std::string::const_iterator> what2;
629 while(boost::regex_search(start2, end2, what2, expression, flags))
631 if(what2.str()[0] != '#')
633 std::string dete = what2.str();
634 CDMUtilities::normalizeStr(dete);
635 if(correspondence.find(dete) != correspondence.end())
636 res[correspondence[dete]] = true;
638 start2 = what2[0].second;
646 bool modelCDMApplication::Set3rdPartyLibrary(const std::string& library_name, const bool& toInclude)
648 std::map<std::string, std::string> correspondence;
650 correspondence["Crea"] = "${crea_LIBRARIES}";
651 correspondence["WxWidgets"] = "${WXWIDGETS_LIBRARIES}";
652 correspondence["KWWidgets"] = "${KWWidgets_LIBRARIES}";
653 correspondence["VTK"] = "${VTK_LIBRARIES}";
654 correspondence["ITK"] = "${ITK_LIBRARIES}";
655 correspondence["GDCM"] = "${GDCM_LIBRARIES}";
656 correspondence["Boost"] = "${BOOST_LIBRARIES}";
658 std::map<std::string, std::string> regexCorrespondence;
660 regexCorrespondence["Crea"] = "\\$\\{crea_LIBRARIES\\}";
661 regexCorrespondence["WxWidgets"] = "\\$\\{WXWIDGETS_LIBRARIES\\}";
662 regexCorrespondence["KWWidgets"] = "\\$\\{KWWidgets_LIBRARIES\\}";
663 regexCorrespondence["VTK"] = "\\$\\{VTK_LIBRARIES\\}";
664 regexCorrespondence["ITK"] = "\\$\\{ITK_LIBRARIES\\}";
665 regexCorrespondence["GDCM"] = "\\$\\{GDCM_LIBRARIES\\}";
666 regexCorrespondence["Boost"] = "\\$\\{BOOST_LIBRARIES\\}";
668 if (correspondence.find(library_name) != correspondence.end())
670 std::string library_command = correspondence[library_name];
671 std::string regex_command = regexCorrespondence[library_name];
672 if (this->HasCMakeLists())
674 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
675 std::string resCMfile = "";
677 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
678 std::string::const_iterator start, end;
679 start = CMfile.begin();
681 boost::match_results<std::string::const_iterator> what;
682 boost::match_flag_type flags = boost::match_default;
683 if(boost::regex_search(start, end, what, expression, flags))
685 resCMfile += what.prefix().str();
688 expression = "^\\h*#+\\h*" + regex_command;
689 std::string::const_iterator start1, end1;
690 start1 = what[0].first;
691 end1 = what[0].second;
692 boost::match_results<std::string::const_iterator> what1, what2;
693 while(boost::regex_search(start1, end1, what1, expression, flags))
696 resCMfile += what1.prefix().str();
697 std::string dete = what1[0].str();
698 for (int i = 0; i < dete.size(); ++i) {
700 resCMfile.push_back(dete[i]);
703 start1 = what1[0].second;
706 resCMfile += what2.suffix().str();
709 expression = "^\\h*" + regex_command;
710 if(boost::regex_search(start1, end1, what1, expression, flags))
713 expression = "^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES";
714 boost::regex_search(start1, end1, what1, expression, flags);
716 resCMfile += what1.prefix().str() + what1.str();
718 resCMfile += "\n" + library_command + "\n";
719 resCMfile += what1.suffix().str();
723 expression = "^\\h*" + regex_command;
724 std::string::const_iterator start1, end1;
725 start1 = what[0].first;
726 end1 = what[0].second;
727 boost::match_results<std::string::const_iterator> what1, what2;
728 while(boost::regex_search(start1, end1, what1, expression, flags))
731 resCMfile += what1.prefix().str();
732 resCMfile += "#" + what1.str();
734 start1 = what1[0].second;
737 resCMfile += what2.suffix().str();
740 expression = "^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES";
741 boost::regex_search(start1, end1, what1, expression, flags);
743 resCMfile += what1.prefix().str() + what1.str() + what1.suffix().str();
746 resCMfile += what.suffix().str();
748 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
756 std::map<std::string, bool> modelCDMApplication::GetCustomLibraries()
758 std::map<std::string, bool> res;
759 std::map<std::string, bool> res1;
761 std::map<std::string, std::string> correspondence;
762 std::vector<modelCDMLibrary*> libraries;
763 if(this->GetParent() != NULL && this->GetParent()->GetParent() != NULL)
764 if(dynamic_cast<modelCDMProject*>(this->GetParent()->GetParent()) != NULL && dynamic_cast<modelCDMProject*>(this->GetParent()->GetParent())->GetLib() != NULL)
765 libraries = (dynamic_cast<modelCDMProject*>(this->GetParent()->GetParent()))->GetLib()->GetLibraries();
766 for (int i = 0; i < libraries.size(); ++i)
768 correspondence[libraries[i]->GetName()] = libraries[i]->GetNameLibrary();
769 res[libraries[i]->GetNameLibrary()] = false;
770 res1[libraries[i]->GetNameLibrary()] = false;
773 if (this->HasCMakeLists())
775 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
777 //find included libraries
778 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
779 std::string::const_iterator start, end;
780 start = CMfile.begin();
782 boost::match_results<std::string::const_iterator> what;
783 boost::match_flag_type flags = boost::match_default;
784 if(boost::regex_search(start, end, what, expression, flags))
787 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES");
788 std::string::const_iterator start1, end1;
789 start1 = what[0].first;
790 end1 = what[0].second;
791 boost::match_results<std::string::const_iterator> what1;
792 if(boost::regex_search(start1, end1, what1, expression, flags))
794 expression = boost::regex("^\\h*[\\w\\d]+");
795 std::string::const_iterator start2, end2;
796 start2 = what1[0].second;
797 end2 = what[0].second;
798 boost::match_results<std::string::const_iterator> what2;
799 while(boost::regex_search(start2, end2, what2, expression, flags))
801 std::string dete = what2.str();
802 CDMUtilities::normalizeStr(dete);
803 //std::cout << "detectado lib: " << dete << std::endl;
804 if(res1.find(dete) != res1.end())
807 start2 = what2[0].second;
812 //find included folders
813 //std::cout << "searching..." << std::endl;
814 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*([\\./\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\")(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
815 start = CMfile.begin();
817 if(boost::regex_search(start, end, what, expression, flags))
819 //std::cout << what.str() << std::endl;
820 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(");
821 std::string::const_iterator start1, end1;
822 start1 = what[0].first;
823 end1 = what[0].second;
824 boost::match_results<std::string::const_iterator> what1;
825 if(boost::regex_search(start1, end1, what1, expression, flags))
827 //std::cout << what1.str() << std::endl;
828 expression = boost::regex("^\\h*\\.\\.\\/\\.\\.\\/lib\\/([\\w\\d])+");
829 std::string::const_iterator start2, end2;
830 start2 = what1[0].second;
831 end2 = what[0].second;
832 boost::match_results<std::string::const_iterator> what2;
833 while(boost::regex_search(start2, end2, what2, expression, flags))
835 std::string dete = what2.str();
836 CDMUtilities::normalizeStr(dete);
837 //std::cout << "detectado dir: " << dete.substr(10) << std::endl;
838 if(correspondence.find(dete.substr(10)) != correspondence.end())
839 res[correspondence[dete.substr(10)]] = res1[correspondence[dete.substr(10)]];
841 start2 = what2[0].second;
850 bool modelCDMApplication::SetCustomLibrary(const std::string& library_name, const bool& toInclude)
852 std::map<std::string, std::string> correspondence;
854 std::vector<modelCDMLibrary*> libraries;
855 modelCDMIProjectTreeNode* p = this;
856 while(p != NULL && dynamic_cast<modelCDMProject*>(p) == NULL)
859 if(p != NULL && dynamic_cast<modelCDMProject*>(p)->GetLib() != NULL)
860 libraries = dynamic_cast<modelCDMProject*>(p)->GetLib()->GetLibraries();
862 for (int i = 0; i < libraries.size(); ++i)
864 correspondence[libraries[i]->GetNameLibrary()] = libraries[i]->GetName();
867 if (correspondence.find(library_name) != correspondence.end())
869 if (this->HasCMakeLists())
871 std::string resCMfile = "";
872 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
875 //find included libraries
876 //std::cout << "searching..." << CMfile << std::endl;
877 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
878 std::string::const_iterator start, end;
879 start = CMfile.begin();
881 boost::match_results<std::string::const_iterator> what;
882 boost::match_flag_type flags = boost::match_default;
883 if(boost::regex_search(start, end, what, expression, flags))
885 //std::cout << what.str() << std::endl;
886 resCMfile += what.prefix().str();
887 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES");
888 std::string::const_iterator start1, end1;
889 start1 = what[0].first;
890 end1 = what[0].second;
891 boost::match_results<std::string::const_iterator> what1;
892 if(boost::regex_search(start1, end1, what1, expression, flags))
894 resCMfile += what1.prefix().str() + what1.str();
895 //check if already exists
896 expression = boost::regex("^\\h*"+library_name);
897 std::string::const_iterator start2, end2;
898 start2 = what1[0].second;
899 end2 = what[0].second;
900 boost::match_results<std::string::const_iterator> what2, temp2;
901 while(boost::regex_search(start2, end2, what2, expression, flags))
903 resCMfile += what2.prefix().str();
909 resCMfile += what2.str();
911 start2 = what2[0].second;
914 resCMfile += temp2.suffix().str();
915 //check if is commented
918 expression = boost::regex("^\\h*#+\\h*"+library_name);
919 start2 = what1[0].second;
920 end2 = what[0].second;
921 while(boost::regex_search(start2, end2, what2, expression, flags))
924 resCMfile += what2.prefix().str();
927 std::string dete = what2[0].str();
928 for (int i = 0; i < dete.size(); ++i) {
930 resCMfile.push_back(dete[i]);
934 start2 = what2[0].second;
937 resCMfile += temp2.suffix().str();
938 //add at the beggining of instruction
942 resCMfile += "\n" + library_name;
943 resCMfile += what1.suffix().str();
947 resCMfile += what.suffix().str();
952 //find included folders
958 //std::cout << "searching..." << CMfile << std::endl;
959 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"){0,1}?(([\\s]|#[^\\n]*\\n)+([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
960 start = CMfile.begin();
962 if(boost::regex_search(start, end, what, expression, flags))
964 resCMfile += what.prefix().str();
965 //std::cout << what.str() << std::endl;
966 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(");
967 std::string::const_iterator start1, end1;
968 start1 = what[0].first;
969 end1 = what[0].second;
970 boost::match_results<std::string::const_iterator> what1;
971 if(boost::regex_search(start1, end1, what1, expression, flags))
973 resCMfile += what1.prefix().str() + what1.str();
974 //std::cout << what1.str() << std::endl;
975 //search if dir is already included
976 expression = boost::regex("^\\h*\\.\\.\\/\\.\\.\\/lib\\/"+correspondence[library_name]);
977 std::string::const_iterator start2, end2;
978 start2 = what1[0].second;
979 end2 = what[0].second;
980 boost::match_results<std::string::const_iterator> what2, temp2;
981 while(boost::regex_search(start2, end2, what2, expression, flags))
984 resCMfile += what2.prefix().str();
987 resCMfile += what2.str();
989 start2 = what2[0].second;
992 resCMfile += temp2.suffix().str();
993 //search if dir is commented
996 expression = boost::regex("^\\h*#+\\h*\\.\\.\\/\\.\\.\\/lib\\/"+correspondence[library_name]);
997 start2 = what1[0].second;
998 end2 = what[0].second;
999 while(boost::regex_search(start2, end2, what2, expression, flags))
1002 resCMfile += what2.prefix().str();
1005 std::string dete = what2[0].str();
1006 for (int i = 0; i < dete.size(); ++i) {
1008 resCMfile.push_back(dete[i]);
1012 start2 = what2[0].second;
1015 resCMfile += temp2.suffix().str();
1016 //add at the beggining of instruction
1020 resCMfile += "\n../../lib/" + correspondence[library_name];
1021 resCMfile += what1.suffix().str();
1025 resCMfile += what.suffix().str();
1030 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);