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 = stdfileName.substr(fileTypePos);
128 //if CMakeLists, create CMakeLists
129 if(stdfileName == "CMakeLists.txt")
131 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
132 this->children.push_back(this->CMakeLists);
136 //if is a code file, create modelCDMCodeFile and check for main file
139 fileType == ".cxx" ||
141 fileType == ".cpp" ||
142 fileType == ".txx" ||
143 fileType == ".cmake" )
145 modelCDMCodeFile* file = new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
147 if (mainFile == NULL && (fileType == ".cxx" || fileType == ".cpp"))
149 std::ifstream fileStream((this->path + CDMUtilities::SLASH + stdfileName).c_str());
151 if (fileStream.is_open())
153 std::string fileContent = "";
154 char ch = fileStream.get();
155 while(!fileStream.eof())
157 fileContent.push_back(ch);
158 ch = fileStream.get();
162 boost::regex expression("^\\h*IMPLEMENT_APP[#\\s\\(]");
163 std::string::const_iterator start, end;
164 start = fileContent.begin();
165 end = fileContent.end();
166 boost::match_results<std::string::const_iterator> what;
167 boost::match_flag_type flags = boost::match_default;
168 if(boost::regex_search(start, end, what, expression, flags))
170 std::cout << "found main wxwidgets file: " << stdfileName << std::endl;
171 this->mainFile = file;
175 expression = boost::regex("^\\h*int\\h+main[#\\s\\(]");
176 start = fileContent.begin();
177 end = fileContent.end();
178 if(boost::regex_search(start, end, what, expression, flags))
180 std::cout << "found main console file: " << stdfileName << std::endl;
181 this->mainFile = file;
186 this->children.push_back(file);
188 //if is an unknown file, create file
191 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
192 this->children.push_back(file);
197 cont = dir.GetNext(&fileName);
200 this->SortChildren();
201 std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
204 modelCDMApplication::~modelCDMApplication()
208 const std::string& modelCDMApplication::GetExecutableName() const
210 return this->executableName;
213 modelCDMFile* modelCDMApplication::GetMainFile() const
215 return this->mainFile;
218 bool modelCDMApplication::SetExecutableName(const std::string& fileName, std::string*& result)
220 std::vector<std::string> words;
221 CDMUtilities::splitter::split(words, fileName, ", /\\\"", CDMUtilities::splitter::no_empties);
222 std::string fileNameReal = words[0];
223 for (int i = 1; i < (int)(words.size()); i++)
225 fileNameReal += "-" + words[i];
229 //opening original cmakelists
230 std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
233 result = new std::string("CMakeLists.txt file failed to open.");
236 //opening temporal cmakelists
237 std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
240 result = new std::string("CMakeLists.txt.tmp file failed to open.");
243 //copying contents from original to temporal and making changes
244 while (getline(in, line))
246 if(line.find("SET ( EXE_NAME") != std::string::npos)
247 line = "SET ( EXE_NAME " + fileNameReal + " )";
248 out << line << std::endl;
252 //delete old file and rename new file
254 std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
256 std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
259 if(system(renameCommand.c_str()))
261 result = new std::string("An error occurred while running '" + renameCommand + "'.");
265 this->executableName = fileNameReal;
269 modelCDMFolder* modelCDMApplication::CreateFolder(const std::string& name, std::string*& result)
271 //TODO:: mkdir depending on OS
272 std::string command = "mkdir " + path + CDMUtilities::SLASH + name;
273 if(system(command.c_str()))
275 result = new std::string("Error executing: " + command + ".");
278 modelCDMFolder* folder = new modelCDMFolder(this, path + CDMUtilities::SLASH + name, name, level + 1);
279 this->folders.push_back(folder);
280 this->children.push_back(folder);
285 const bool modelCDMApplication::Refresh(std::string*& result)
287 this->mainFile = NULL;
288 std::cout << "refreshing application: " << this->executableName << std::endl;
290 this->type = wxDIR_DIRS;
293 std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
295 std::ifstream confFile;
296 confFile.open((pathMakeLists).c_str());
299 while(confFile.is_open() && !confFile.eof())
302 std::getline(confFile,word,'(');
303 std::vector<std::string> wordBits;
304 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
306 if(wordBits[wordBits.size()-1] == "SET")
309 std::getline(confFile,word,')');
310 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
311 if(wordBits[0] == "EXE_NAME")
314 for (int i = 2; i < (int)(wordBits.size()); i++)
316 word += " " + wordBits[i];
319 this->executableName = word;
327 std::vector<bool> checked(this->children.size(), false);
328 std::vector<bool> checkedFolders(this->folders.size(), false);
331 wxDir dir(crea::std2wx((this->path).c_str()));
335 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
338 std::string stdfileName = crea::wx2std(fileName);
339 std::string applicationName = stdfileName;
340 //check if they already exist
342 for (int i = 0; !found && i < (int)(this->folders.size()); i++)
344 if (this->folders[i]->GetName() == applicationName)
347 int pos = std::find(this->children.begin(), this->children.end(), this->folders[i]) - this->children.begin();
349 checkedFolders[i] = true;
350 if(!this->folders[i]->Refresh(result))
356 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
357 this->folders.push_back(folder);
358 this->children.push_back(folder);
360 cont = dir.GetNext(&fileName);
363 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
366 std::string stdfileName = crea::wx2std(fileName);
367 std::size_t fileTypePos = stdfileName.find_last_of(".");
368 std::string fileType = stdfileName.substr(fileTypePos);
370 //if CMakeLists, create CMakeLists
371 if(stdfileName == "CMakeLists.txt")
373 if (this->CMakeLists == NULL)
375 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
376 this->children.push_back(this->CMakeLists);
380 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
382 if(!this->CMakeLists->Refresh(result))
386 // if is a code file, create modelCDMCodeFile
387 // if is an unknown file, create file
391 for (int i = 0; !found && i < (int)(this->children.size()); i++)
393 if (this->children[i]->GetName() == stdfileName)
398 if(!this->children[i]->Refresh(result))
401 std::string extension = stdfileName.substr(stdfileName.size()-4);
402 if (mainFile == NULL && (extension == ".cxx" || extension == ".cpp"))
404 std::ifstream fileStream;
406 fileStream.open((this->path + CDMUtilities::SLASH + stdfileName).c_str());
407 while (fileStream.is_open() && !fileStream.eof())
410 std::getline(fileStream,word,'(');
411 std::vector<std::string> wordBits;
412 CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
413 if (wordBits[wordBits.size() - 1] == "main" || wordBits[wordBits.size() - 1] == "IMPLEMENT_APP")
415 this->mainFile = dynamic_cast<modelCDMCodeFile*>(children[i]);
425 if (fileType == ".c" ||
426 fileType == ".cxx" ||
428 fileType == ".cpp" ||
429 fileType == ".txx" ||
430 fileType == ".cmake" )
432 modelCDMCodeFile* file = new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
434 if(mainFile == NULL && (fileType == ".cxx" || fileType == ".cpp"))
436 std::ifstream fileStream;
438 fileStream.open((this->path + CDMUtilities::SLASH + stdfileName).c_str());
439 while (fileStream.is_open() && !fileStream.eof())
442 std::getline(fileStream,word,'(');
443 std::vector<std::string> wordBits;
444 CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
445 if (wordBits[wordBits.size() - 1] == "main" || wordBits[wordBits.size() - 1] == "IMPLEMENT_APP")
447 this->mainFile = file;
452 this->children.push_back(file);
456 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
457 this->children.push_back(file);
462 cont = dir.GetNext(&fileName);
466 for (int i = 0; i < (int)(checkedFolders.size()); i++)
468 if(!checkedFolders[i])
470 this->folders.erase(this->folders.begin()+i);
471 checkedFolders.erase(checkedFolders.begin()+i);
475 for (int i = 0; i < (int)(checked.size()); i++)
479 delete this->children[i];
480 this->children.erase(this->children.begin()+i);
481 checked.erase(checked.begin()+i);
485 this->SortChildren();
489 void modelCDMApplication::CheckStructure(std::map<std::string, bool>& properties)
492 if(this->CMakeLists != NULL)
494 //set default properties
495 properties["application " + this->name + " lib ${crea_LIBRARIES}"] = false;
496 properties["application " + this->name + " lib ${WXWIDGETS_LIBRARIES}"] = false;
497 properties["application " + this->name + " lib ${KWWidgets_LIBRARIES}"] = false;
498 properties["application " + this->name + " lib ${VTK_LIBRARIES}"] = false;
499 properties["application " + this->name + " lib ${ITK_LIBRARIES}"] = false;
500 properties["application " + this->name + " lib ${GDCM_LIBRARIES}"] = false;
501 properties["application " + this->name + " lib ${BOOST_LIBRARIES}"] = false;
504 std::ifstream confFile;
505 confFile.open((this->CMakeLists->GetPath()).c_str());
507 //take everything that is not commented
508 std::string fileContent;
511 std::vector<std::string> words;
512 while(confFile.is_open() && !confFile.eof())
514 std::getline(confFile,word, '\n');
517 CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok);
518 if (words.size() > 0)
521 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
522 for (int i = 0; i < (int)(words.size()); i++)
524 if(words[i].substr(0,2) == "//")
526 fileContent += words[i] + " ";
532 //check every instruction
533 std::stringstream ss(fileContent);
536 std::getline(ss,word, '(');
538 //check instruction name
539 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
542 if (words.size() > 0 && words[words.size()-1] == "SET")
544 std::getline(ss,word, ')');
546 CDMUtilities::splitter::split(words, word, " \t", CDMUtilities::splitter::no_empties);
547 if (words.size() > 1)
549 if (words[0] == "${EXE_NAME}_LINK_LIBRARIES")
551 for (int i = 1; i < (int)(words.size()); i++)
553 properties["application " + this->name + " lib " + words[i]] = true;
558 else if (words.size() > 0 && words[words.size()-1] == "INCLUDE_DIRECTORIES")
560 std::getline(ss,word, ')');
562 CDMUtilities::splitter::split(words, word, " \t", CDMUtilities::splitter::no_empties);
564 for (int i = 0; i < (int)(words.size()); i++)
566 properties["application " + this->name + " dir " + words[i]] = true;
576 std::map<std::string, bool> modelCDMApplication::Get3rdPartyLibraries()
578 std::map<std::string, std::string> correspondence;
579 correspondence["${crea_LIBRARIES}"] = "Crea";
580 correspondence["${WXWIDGETS_LIBRARIES}"] = "WxWidgets";
581 correspondence["${KWWidgets_LIBRARIES}"] = "KWWidgets";
582 correspondence["${VTK_LIBRARIES}"] = "VTK";
583 correspondence["${ITK_LIBRARIES}"] = "ITK";
584 correspondence["${GDCM_LIBRARIES}"] = "GDCM";
585 correspondence["${BOOST_LIBRARIES}"] = "Boost";
586 std::map<std::string, bool> res;
588 res["WxWidgets"] = false;
589 res["KWWidgets"] = false;
593 res["Boost"] = false;
595 if (this->HasCMakeLists())
598 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
600 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
601 std::string::const_iterator start, end;
602 start = CMfile.begin();
604 boost::match_results<std::string::const_iterator> what;
605 boost::match_flag_type flags = boost::match_default;
606 if(boost::regex_search(start, end, what, expression, flags))
609 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES");
610 std::string::const_iterator start1, end1;
611 start1 = what[0].first;
612 end1 = what[0].second;
613 boost::match_results<std::string::const_iterator> what1;
614 if(boost::regex_search(start1, end1, what1, expression, flags))
616 expression = boost::regex("(#[^\\n]*\\n|\\s*\\$\\{\\w+\\})");
617 std::string::const_iterator start2, end2;
618 start2 = what1[0].second;
619 end2 = what[0].second;
620 boost::match_results<std::string::const_iterator> what2;
621 while(boost::regex_search(start2, end2, what2, expression, flags))
623 if(what2.str()[0] != '#')
625 std::string dete = what2.str();
626 CDMUtilities::normalizeStr(dete);
627 if(correspondence.find(dete) != correspondence.end())
628 res[correspondence[dete]] = true;
630 start2 = what2[0].second;
638 bool modelCDMApplication::Set3rdPartyLibrary(const std::string& library_name, const bool& toInclude)
640 std::map<std::string, std::string> correspondence;
642 correspondence["Crea"] = "${crea_LIBRARIES}";
643 correspondence["WxWidgets"] = "${WXWIDGETS_LIBRARIES}";
644 correspondence["KWWidgets"] = "${KWWidgets_LIBRARIES}";
645 correspondence["VTK"] = "${VTK_LIBRARIES}";
646 correspondence["ITK"] = "${ITK_LIBRARIES}";
647 correspondence["GDCM"] = "${GDCM_LIBRARIES}";
648 correspondence["Boost"] = "${BOOST_LIBRARIES}";
650 std::map<std::string, std::string> regexCorrespondence;
652 regexCorrespondence["Crea"] = "\\$\\{crea_LIBRARIES\\}";
653 regexCorrespondence["WxWidgets"] = "\\$\\{WXWIDGETS_LIBRARIES\\}";
654 regexCorrespondence["KWWidgets"] = "\\$\\{KWWidgets_LIBRARIES\\}";
655 regexCorrespondence["VTK"] = "\\$\\{VTK_LIBRARIES\\}";
656 regexCorrespondence["ITK"] = "\\$\\{ITK_LIBRARIES\\}";
657 regexCorrespondence["GDCM"] = "\\$\\{GDCM_LIBRARIES\\}";
658 regexCorrespondence["Boost"] = "\\$\\{BOOST_LIBRARIES\\}";
660 if (correspondence.find(library_name) != correspondence.end())
662 std::string library_command = correspondence[library_name];
663 std::string regex_command = regexCorrespondence[library_name];
664 if (this->HasCMakeLists())
666 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
667 std::string resCMfile = "";
669 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
670 std::string::const_iterator start, end;
671 start = CMfile.begin();
673 boost::match_results<std::string::const_iterator> what;
674 boost::match_flag_type flags = boost::match_default;
675 if(boost::regex_search(start, end, what, expression, flags))
677 resCMfile += what.prefix().str();
680 expression = "^\\h*#+\\h*" + regex_command;
681 std::string::const_iterator start1, end1;
682 start1 = what[0].first;
683 end1 = what[0].second;
684 boost::match_results<std::string::const_iterator> what1, what2;
685 while(boost::regex_search(start1, end1, what1, expression, flags))
688 resCMfile += what1.prefix().str();
689 std::string dete = what1[0].str();
690 for (int i = 0; i < dete.size(); ++i) {
692 resCMfile.push_back(dete[i]);
695 start1 = what1[0].second;
698 resCMfile += what2.suffix().str();
701 expression = "^\\h*" + regex_command;
702 if(boost::regex_search(start1, end1, what1, expression, flags))
705 expression = "^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES";
706 boost::regex_search(start1, end1, what1, expression, flags);
708 resCMfile += what1.prefix().str() + what1.str();
710 resCMfile += "\n" + library_command + "\n";
711 resCMfile += what1.suffix().str();
715 expression = "^\\h*" + regex_command;
716 std::string::const_iterator start1, end1;
717 start1 = what[0].first;
718 end1 = what[0].second;
719 boost::match_results<std::string::const_iterator> what1, what2;
720 while(boost::regex_search(start1, end1, what1, expression, flags))
723 resCMfile += what1.prefix().str();
724 resCMfile += "#" + what1.str();
726 start1 = what1[0].second;
729 resCMfile += what2.suffix().str();
732 expression = "^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES";
733 boost::regex_search(start1, end1, what1, expression, flags);
735 resCMfile += what1.prefix().str() + what1.str() + what1.suffix().str();
738 resCMfile += what.suffix().str();
740 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
748 std::map<std::string, bool> modelCDMApplication::GetCustomLibraries()
750 std::map<std::string, bool> res;
751 std::map<std::string, bool> res1;
753 std::map<std::string, std::string> correspondence;
754 std::vector<modelCDMLibrary*> libraries;
755 if(this->GetParent() != NULL && this->GetParent()->GetParent() != NULL)
756 if(dynamic_cast<modelCDMProject*>(this->GetParent()->GetParent()) != NULL && dynamic_cast<modelCDMProject*>(this->GetParent()->GetParent())->GetLib() != NULL)
757 libraries = (dynamic_cast<modelCDMProject*>(this->GetParent()->GetParent()))->GetLib()->GetLibraries();
758 for (int i = 0; i < libraries.size(); ++i)
760 correspondence[libraries[i]->GetName()] = libraries[i]->GetNameLibrary();
761 res[libraries[i]->GetNameLibrary()] = false;
762 res1[libraries[i]->GetNameLibrary()] = false;
765 if (this->HasCMakeLists())
767 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
769 //find included libraries
770 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
771 std::string::const_iterator start, end;
772 start = CMfile.begin();
774 boost::match_results<std::string::const_iterator> what;
775 boost::match_flag_type flags = boost::match_default;
776 if(boost::regex_search(start, end, what, expression, flags))
779 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES");
780 std::string::const_iterator start1, end1;
781 start1 = what[0].first;
782 end1 = what[0].second;
783 boost::match_results<std::string::const_iterator> what1;
784 if(boost::regex_search(start1, end1, what1, expression, flags))
786 expression = boost::regex("^\\h*[\\w\\d]+");
787 std::string::const_iterator start2, end2;
788 start2 = what1[0].second;
789 end2 = what[0].second;
790 boost::match_results<std::string::const_iterator> what2;
791 while(boost::regex_search(start2, end2, what2, expression, flags))
793 std::string dete = what2.str();
794 CDMUtilities::normalizeStr(dete);
795 //std::cout << "detectado lib: " << dete << std::endl;
796 if(res1.find(dete) != res1.end())
799 start2 = what2[0].second;
804 //find included folders
805 //std::cout << "searching..." << std::endl;
806 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*([\\./\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\")(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
807 start = CMfile.begin();
809 if(boost::regex_search(start, end, what, expression, flags))
811 //std::cout << what.str() << std::endl;
812 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(");
813 std::string::const_iterator start1, end1;
814 start1 = what[0].first;
815 end1 = what[0].second;
816 boost::match_results<std::string::const_iterator> what1;
817 if(boost::regex_search(start1, end1, what1, expression, flags))
819 //std::cout << what1.str() << std::endl;
820 expression = boost::regex("^\\h*\\.\\.\\/\\.\\.\\/lib\\/([\\w\\d])+");
821 std::string::const_iterator start2, end2;
822 start2 = what1[0].second;
823 end2 = what[0].second;
824 boost::match_results<std::string::const_iterator> what2;
825 while(boost::regex_search(start2, end2, what2, expression, flags))
827 std::string dete = what2.str();
828 CDMUtilities::normalizeStr(dete);
829 //std::cout << "detectado dir: " << dete.substr(10) << std::endl;
830 if(correspondence.find(dete.substr(10)) != correspondence.end())
831 res[correspondence[dete.substr(10)]] = res1[correspondence[dete.substr(10)]];
833 start2 = what2[0].second;
842 bool modelCDMApplication::SetCustomLibrary(const std::string& library_name, const bool& toInclude)
844 std::map<std::string, std::string> correspondence;
846 std::vector<modelCDMLibrary*> libraries;
847 modelCDMIProjectTreeNode* p = this;
848 while(p != NULL && dynamic_cast<modelCDMProject*>(p) == NULL)
851 if(p != NULL && dynamic_cast<modelCDMProject*>(p)->GetLib() != NULL)
852 libraries = dynamic_cast<modelCDMProject*>(p)->GetLib()->GetLibraries();
854 for (int i = 0; i < libraries.size(); ++i)
856 correspondence[libraries[i]->GetNameLibrary()] = libraries[i]->GetName();
859 if (correspondence.find(library_name) != correspondence.end())
861 if (this->HasCMakeLists())
863 std::string resCMfile = "";
864 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
867 //find included libraries
868 //std::cout << "searching..." << CMfile << std::endl;
869 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
870 std::string::const_iterator start, end;
871 start = CMfile.begin();
873 boost::match_results<std::string::const_iterator> what;
874 boost::match_flag_type flags = boost::match_default;
875 if(boost::regex_search(start, end, what, expression, flags))
877 //std::cout << what.str() << std::endl;
878 resCMfile += what.prefix().str();
879 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{EXE_NAME\\}_LINK_LIBRARIES");
880 std::string::const_iterator start1, end1;
881 start1 = what[0].first;
882 end1 = what[0].second;
883 boost::match_results<std::string::const_iterator> what1;
884 if(boost::regex_search(start1, end1, what1, expression, flags))
886 resCMfile += what1.prefix().str() + what1.str();
887 //check if already exists
888 expression = boost::regex("^\\h*"+library_name);
889 std::string::const_iterator start2, end2;
890 start2 = what1[0].second;
891 end2 = what[0].second;
892 boost::match_results<std::string::const_iterator> what2, temp2;
893 while(boost::regex_search(start2, end2, what2, expression, flags))
895 resCMfile += what2.prefix().str();
901 resCMfile += what2.str();
903 start2 = what2[0].second;
906 resCMfile += temp2.suffix().str();
907 //check if is commented
910 expression = boost::regex("^\\h*#+\\h*"+library_name);
911 start2 = what1[0].second;
912 end2 = what[0].second;
913 while(boost::regex_search(start2, end2, what2, expression, flags))
916 resCMfile += what2.prefix().str();
919 std::string dete = what2[0].str();
920 for (int i = 0; i < dete.size(); ++i) {
922 resCMfile.push_back(dete[i]);
926 start2 = what2[0].second;
929 resCMfile += temp2.suffix().str();
930 //add at the beggining of instruction
934 resCMfile += "\n" + library_name;
935 resCMfile += what1.suffix().str();
939 resCMfile += what.suffix().str();
944 //find included folders
950 //std::cout << "searching..." << CMfile << std::endl;
951 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"){0,1}?(([\\s]|#[^\\n]*\\n)+([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
952 start = CMfile.begin();
954 if(boost::regex_search(start, end, what, expression, flags))
956 resCMfile += what.prefix().str();
957 //std::cout << what.str() << std::endl;
958 expression = boost::regex("^\\h*INCLUDE_DIRECTORIES([\\s]|#[^\\n]*\\n)*\\(");
959 std::string::const_iterator start1, end1;
960 start1 = what[0].first;
961 end1 = what[0].second;
962 boost::match_results<std::string::const_iterator> what1;
963 if(boost::regex_search(start1, end1, what1, expression, flags))
965 resCMfile += what1.prefix().str() + what1.str();
966 //std::cout << what1.str() << std::endl;
967 //search if dir is already included
968 expression = boost::regex("^\\h*\\.\\.\\/\\.\\.\\/lib\\/"+correspondence[library_name]);
969 std::string::const_iterator start2, end2;
970 start2 = what1[0].second;
971 end2 = what[0].second;
972 boost::match_results<std::string::const_iterator> what2, temp2;
973 while(boost::regex_search(start2, end2, what2, expression, flags))
976 resCMfile += what2.prefix().str();
979 resCMfile += what2.str();
981 start2 = what2[0].second;
984 resCMfile += temp2.suffix().str();
985 //search if dir is commented
988 expression = boost::regex("^\\h*#+\\h*\\.\\.\\/\\.\\.\\/lib\\/"+correspondence[library_name]);
989 start2 = what1[0].second;
990 end2 = what[0].second;
991 while(boost::regex_search(start2, end2, what2, expression, flags))
994 resCMfile += what2.prefix().str();
997 std::string dete = what2[0].str();
998 for (int i = 0; i < dete.size(); ++i) {
1000 resCMfile.push_back(dete[i]);
1004 start2 = what2[0].second;
1007 resCMfile += temp2.suffix().str();
1008 //add at the beggining of instruction
1012 resCMfile += "\n../../lib/" + correspondence[library_name];
1013 resCMfile += what1.suffix().str();
1017 resCMfile += what.suffix().str();
1022 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);