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 "modelCDMPackage.h"
37 #include "modelCDMProject.h"
38 #include "modelCDMLib.h"
39 #include "modelCDMLibrary.h"
45 #include <boost/regex.hpp>
49 #include "CDMUtilities.h"
51 modelCDMPackage::modelCDMPackage()
56 modelCDMPackage::modelCDMPackage(modelCDMIProjectTreeNode* parent, const std::string& path, const std::string& name, const int& level)
58 std::cout << "creating package: " + path + "\n";
59 this->parent = parent;
60 this->type = wxDIR_DIRS;
64 std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
66 std::ifstream confFile;
67 confFile.open((pathMakeLists).c_str());
70 while(confFile.is_open() && !confFile.eof())
73 std::getline(confFile,word,'(');
74 std::vector<std::string> wordBits;
75 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
77 if(wordBits[wordBits.size()-1] == "SET")
80 std::getline(confFile,word,')');
81 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
82 if(wordBits[0] == "BBTK_PACKAGE_NAME")
85 for (int i = 2; i < (int)(wordBits.size()); i++)
87 word += " " + wordBits[i];
90 CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
92 this->namePackage = wordBits[0];
94 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_AUTHOR")
97 for (int i = 2; i < (int)(wordBits.size()); i++)
99 word += " " + wordBits[i];
102 CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
104 this->authors = wordBits[0];
106 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_DESCRIPTION")
109 for (int i = 2; i < (int)(wordBits.size()); i++)
111 word += " " + wordBits[i];
114 CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
116 this->description = wordBits[0];
118 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_MAJOR_VERSION")
120 this->version = wordBits[1];
122 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_MINOR_VERSION")
124 this->version += "." + wordBits[1];
126 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_BUILD_VERSION")
128 this->version += "." + wordBits[1];
136 //check all folders and files
137 wxDir dir(crea::std2wx((path).c_str()));
143 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
146 std::string stdfileName = crea::wx2std(fileName);
147 //if src, check for black boxes
148 if(stdfileName == "src")
150 this->src = new modelCDMPackageSrc(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
151 this->children.push_back(this->src);
155 this->children.push_back(new modelCDMFolder(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
158 cont = dir.GetNext(&fileName);
162 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
165 std::string stdfileName = crea::wx2std(fileName);
167 //if CMakeLists, create CMakeLists
168 if(stdfileName == "CMakeLists.txt")
170 this->CMakeLists = new modelCDMCMakeListsFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
171 this->children.push_back(this->CMakeLists);
175 this->children.push_back(new modelCDMFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
177 //if is an unknown file, create file
178 cont = dir.GetNext(&fileName);
181 this->SortChildren();
184 modelCDMPackage::~modelCDMPackage()
188 const std::string& modelCDMPackage::GetNamePackage() const
190 return this->namePackage;
193 const std::string& modelCDMPackage::GetAuthors() const
195 return this->authors;
198 const std::string& modelCDMPackage::GetAuthorsEmail() const
200 return this->authorsEmail;
203 const std::string& modelCDMPackage::GetVersion() const
205 return this->version;
208 const std::string& modelCDMPackage::GetDescription() const
210 return this->description;
213 modelCDMPackageSrc* modelCDMPackage::GetSrc() const
218 bool modelCDMPackage::SetAuthors(const std::string& authors, std::string*& result)
220 std::vector<std::string> words;
221 CDMUtilities::splitter::split(words, authors, ",\n", CDMUtilities::splitter::no_empties);
222 std::string authorsReal = words[0];
223 for (int i = 1; i < (int)(words.size()); i++)
225 authorsReal += "/" + 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(${BBTK_PACKAGE_NAME}_AUTHOR") != std::string::npos)
247 line = "SET(${BBTK_PACKAGE_NAME}_AUTHOR \"" + authorsReal + "\")";
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->authors = authorsReal;
269 bool modelCDMPackage::SetAuthorsEmail(const std::string& email, std::string*& result)
271 //TODO: implement method
275 bool modelCDMPackage::SetVersion(const std::string& version, std::string*& result)
277 std::vector<std::string> vers;
278 CDMUtilities::splitter::split(vers, version, " .", CDMUtilities::splitter::no_empties);
282 //opening original cmakelists
283 std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
286 result = new std::string("CMakeLists.txt file failed to open.");
289 //opening temporal cmakelists
290 std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
293 result = new std::string("CMakeLists.txt.tmp file failed to open.");
296 //copying contents from original to temporal and making changes
297 while (getline(in, line))
299 if(line.find("SET(${BBTK_PACKAGE_NAME}_MAJOR_VERSION") != std::string::npos)
300 line = "SET(${BBTK_PACKAGE_NAME}_MAJOR_VERSION " + vers[0] + ")";
301 else if(line.find("SET(${BBTK_PACKAGE_NAME}_VERSION") != std::string::npos)
302 line = "SET(${BBTK_PACKAGE_NAME}_MINOR_VERSION " + vers[1] + ")";
303 else if(line.find("SET(${BBTK_PACKAGE_NAME}_BUILD_VERSION") != std::string::npos)
304 line = "SET(${BBTK_PACKAGE_NAME}_BUILD_VERSION " + vers[2] + ")";
305 out << line << std::endl;
309 //delete old file and rename new file
311 std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
313 std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
316 if(system(renameCommand.c_str()))
318 result = new std::string("An error occurred while running '" + renameCommand + "'.");
322 this->version = vers[0] + "." + vers[1] + "." + vers[2];
326 bool modelCDMPackage::SetDescription(const std::string& description, std::string*& result)
328 std::vector<std::string> words;
329 CDMUtilities::splitter::split(words, description, " \n", CDMUtilities::splitter::no_empties);
330 std::string descriptionReal = words[0];
331 for (int i = 1; i < (int)(words.size()); i++)
333 descriptionReal += " " + words[i];
337 //opening original cmakelists
338 std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
341 result = new std::string("CMakeLists.txt file failed to open.");
344 //opening temporal cmakelists
345 std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
348 result = new std::string("CMakeLists.txt.tmp file failed to open.");
351 //copying contents from original to temporal and making changes
352 while (getline(in, line))
354 if(line.find("SET(${BBTK_PACKAGE_NAME}_DESCRIPTION") != std::string::npos)
355 line = "SET(${BBTK_PACKAGE_NAME}_DESCRIPTION \"" + descriptionReal + "\")";
356 out << line << std::endl;
360 //delete old file and rename new file
362 std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
364 std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
367 if(system(renameCommand.c_str()))
369 result = new std::string("An error occurred while running '" + renameCommand + "'.");
373 this->description = descriptionReal;
377 modelCDMBlackBox* modelCDMPackage::CreateBlackBox(
378 std::string*& result,
379 const std::string& name,
380 const std::string& type,
381 const std::string& format,
382 const std::string& categories,
383 const std::string& authors,
384 const std::string& authorsEmail,
385 const std::string& description
388 return this->src->CreateBlackBox(result,name, this->namePackage, type,format,categories,authors,authorsEmail,description);
391 const bool modelCDMPackage::Refresh(std::string*& result)
393 std::cout << "refreshing package " << this->namePackage << std::endl;
394 this->type = wxDIR_DIRS;
398 std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
400 std::ifstream confFile;
401 confFile.open((pathMakeLists).c_str());
404 while(confFile.is_open() && !confFile.eof())
407 std::getline(confFile,word,'(');
408 std::vector<std::string> wordBits;
409 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
411 if(wordBits[wordBits.size()-1] == "SET")
414 std::getline(confFile,word,')');
415 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
416 if(wordBits[0] == "BBTK_PACKAGE_NAME")
419 for (int i = 2; i < (int)(wordBits.size()); i++)
421 word += " " + wordBits[i];
424 CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
426 this->namePackage = wordBits[0];
428 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_AUTHOR")
431 for (int i = 2; i < (int)(wordBits.size()); i++)
433 word += " " + wordBits[i];
436 CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
438 this->authors = wordBits[0];
440 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_DESCRIPTION")
443 for (int i = 2; i < (int)(wordBits.size()); i++)
445 word += " " + wordBits[i];
448 CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
450 this->description = wordBits[0];
452 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_MAJOR_VERSION")
454 this->version = wordBits[1];
456 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_MINOR_VERSION")
458 this->version += "." + wordBits[1];
460 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_BUILD_VERSION")
462 this->version += "." + wordBits[1];
469 std::vector<bool> checked(this->children.size(), false);
470 bool checkedSrc = false;
473 wxDir dir(crea::std2wx((this->path).c_str()));
477 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
481 std::string stdfileName = crea::wx2std(fileName);
483 //detect black boxes in src
484 if(stdfileName == "src")
486 //check if box already exist
488 if (this->src != NULL)
491 int pos = std::find(this->children.begin(), this->children.end(), this->src) - this->children.begin();
494 if(!this->src->Refresh(result))
499 this->src = new modelCDMPackageSrc(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level +1);
500 this->children.push_back(this->src);
506 //check if folder already exist
508 for (int i = 0; !found && i < (int)(this->children.size()); i++)
510 if (this->children[i]->GetName() == stdfileName)
514 if(!this->children[i]->Refresh(result))
520 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
521 this->children.push_back(folder);
524 cont = dir.GetNext(&fileName);
528 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
531 std::string stdfileName = crea::wx2std(fileName);
533 //if CMakeLists, create CMakeLists
534 if(stdfileName == "CMakeLists.txt")
536 if (this->CMakeLists == NULL)
538 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
539 this->children.push_back(this->CMakeLists);
543 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
545 if(!this->CMakeLists->Refresh(result))
549 //if is an unknown file, create file
553 for (int i = 0; !found && i < (int)(this->children.size()); i++)
555 if (this->children[i]->GetName() == stdfileName)
559 if(!this->children[i]->Refresh(result))
566 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
567 this->children.push_back(file);
571 cont = dir.GetNext(&fileName);
580 for (int i = 0; i < (int)(checked.size()); i++)
584 delete this->children[i];
585 this->children.erase(this->children.begin()+i);
586 checked.erase(checked.begin()+i);
590 this->SortChildren();
594 void modelCDMPackage::CheckStructure(std::map<std::string, bool>& properties)
597 if(this->CMakeLists != NULL)
600 std::ifstream confFile;
601 confFile.open((this->CMakeLists->GetPath()).c_str());
603 //take everything that is not commented
604 std::string fileContent;
607 std::vector<std::string> words;
608 while(confFile.is_open() && !confFile.eof())
610 std::getline(confFile,word, '\n');
613 CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok);
614 if (words.size() > 0)
617 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
618 for (int i = 0; i < (int)(words.size()); i++)
620 if(words[i].substr(0,2) == "//")
622 fileContent += words[i] + " ";
628 //check every instruction
629 std::stringstream ss(fileContent);
632 std::getline(ss,word, '(');
634 //check instruction name
635 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
638 if (words.size() > 0 && words[words.size()-1] == "SET")
640 std::getline(ss,word, ')');
642 CDMUtilities::splitter::split(words, word, " \t", CDMUtilities::splitter::no_empties);
643 if (words.size() > 1)
645 if (words[0] == "${BBTK_PACKAGE_NAME}_USE_VTK" && words[1] == "ON")
647 properties["package " + this->name + " set USE_VTK"] = true;
649 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_ITK" && words[1] == "ON")
651 properties["package " + this->name + " set USE_ITK"] = true;
653 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_GDCM" && words[1] == "ON")
655 properties["package " + this->name + " set USE_GDCM"] = true;
657 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_GDCM_VTK" && words[1] == "ON")
659 properties["package " + this->name + " set USE_GDCM_VTK"] = true;
661 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_GSMIS" && words[1] == "ON")
663 properties["package " + this->name + " set USE_GSMIS"] = true;
665 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_WXWIDGETS" && words[1] == "ON")
667 properties["package " + this->name + " set USE_WXWIDGETS"] = true;
669 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_KWWIDGETS" && words[1] == "ON")
671 properties["package " + this->name + " set USE_KWWIDGETS"] = true;
673 else if (words[0] == "USE_BOOST" && words[1] == "ON")
675 properties["package " + this->name + " set USE_BOOST"] = true;
677 else if (words[0] == "${BBTK_PACKAGE_NAME}_INCLUDE_DIRS")
679 for (int i = 1; i < (int)(words.size()); i++)
681 if(words[i].substr(0,2) == "${" || words[i].substr(0,2) == "..")
682 properties["package " + this->name + " dir " + words[i]] = true;
685 else if (words[0] == "${BBTK_PACKAGE_NAME}_LIBS")
687 for (int i = 1; i < (int)(words.size()); i++)
689 properties["package " + this->name + " lib " + words[i]] = true;
699 std::map<std::string, bool> modelCDMPackage::Get3rdPartyLibraries()
701 std::map<std::string, std::string> correspondence;
702 correspondence["${BBTK_PACKAGE_NAME}_USE_VTK"] = "VTK";
703 correspondence["${BBTK_PACKAGE_NAME}_USE_ITK"] = "ITK";
704 correspondence["${BBTK_PACKAGE_NAME}_USE_GDCM"] = "GDCM";
705 correspondence["${BBTK_PACKAGE_NAME}_USE_GDCM_VTK"] = "GDCM_VTK";
706 correspondence["${BBTK_PACKAGE_NAME}_USE_GSMIS"] = "GSMIS";
707 correspondence["${BBTK_PACKAGE_NAME}_USE_WXWIDGETS"] = "WxWidgets";
708 correspondence["${BBTK_PACKAGE_NAME}_USE_KWWIDGETS"] = "KWWidgets";
709 std::map<std::string, bool> res;
713 res["GDCM_VTK"] = false;
714 res["GSMIS"] = false;
715 res["WxWidgets"] = false;
716 res["KWWidgets"] = false;
718 if (this->HasCMakeLists())
720 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
722 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_USE_\\w+\\s+ON");
723 std::string::const_iterator start, end;
724 start = CMfile.begin();
726 boost::match_results<std::string::const_iterator> what;
727 boost::match_flag_type flags = boost::match_default;
728 while(boost::regex_search(start, end, what, expression, flags))
730 //std::cout << what[0].str() << std::endl;
731 boost::regex expression1 = boost::regex("\\$\\{BBTK_PACKAGE_NAME\\}_USE_\\w+");
732 std::string::const_iterator start1, end1;
733 start1 = what[0].first;
734 end1 = what[0].second;
735 boost::match_results<std::string::const_iterator> what1;
736 if(boost::regex_search(start1, end1, what1, expression1, flags))
738 std::string dete = what1.str();
739 CDMUtilities::normalizeStr(dete);
740 //std::cout << dete << std::endl;
741 if(correspondence.find(dete) != correspondence.end())
742 res[correspondence[dete]] = true;
744 start = what[0].second;
750 bool modelCDMPackage::Set3rdPartyLibrary(const std::string& library_name,
751 const bool& toInclude)
753 std::map<std::string, std::string> correspondence;
755 correspondence["VTK"] = "_USE_VTK";
756 correspondence["ITK"] = "_USE_ITK";
757 correspondence["GDCM"] = "_USE_GDCM";
758 correspondence["GDCM_VTK"] = "_USE_GDCM_VTK";
759 correspondence["GSMIS"] = "_USE_GSMIS";
760 correspondence["WxWidgets"] = "_USE_WXWIDGETS";
761 correspondence["KWWidgets"] = "_USE_KWWIDGETS";
763 if (correspondence.find(library_name) != correspondence.end())
765 std::string library_command = correspondence[library_name];
766 if (this->HasCMakeLists())
768 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
769 std::string resCMfile = "";
773 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+ON([\\s]|#[^\\n]*\\n)*\\)");
775 std::string::const_iterator start, end;
776 start = CMfile.begin();
778 boost::match_results<std::string::const_iterator> what;
779 boost::match_flag_type flags = boost::match_default;
780 if(boost::regex_search(start, end, what, expression, flags))
783 resCMfile += what.prefix().str();
785 resCMfile += what.str();
787 resCMfile += "#" + what.str();
788 resCMfile += what.suffix().str();
790 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
794 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+OFF([\\s]|#[^\\n]*\\n)*\\)");
796 start = CMfile.begin();
798 if(boost::regex_search(start, end, what, expression, flags))
801 resCMfile += what.prefix().str();
804 std::string dete = what.str();
805 int pos = dete.rfind("OFF");
806 dete.replace(pos, 3, "ON");
810 resCMfile += what.str();
811 resCMfile += what.suffix().str();
813 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
817 boost::regex expression("^\\h*#\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+ON([\\s]|#[^\\n]*\\n)*\\)");
818 if(boost::regex_search(start, end, what, expression, flags))
821 resCMfile += what.prefix().str();
824 std::string dete = what[0].str();
825 for (int i = 0; i < dete.size(); ++i) {
827 resCMfile.push_back(dete[i]);
830 resCMfile += dete.substr(i+1);
836 resCMfile += what.str();
838 resCMfile += what.suffix().str();
839 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
843 boost::regex expression("^\\h*#\\h*UNCOMMENT EACH LIBRARY NEEDED \\(WILL BE FOUND AND USED AUTOMATICALLY\\)[^\\n]*\\n");
844 if(boost::regex_search(start, end, what, expression, flags))
847 resCMfile += what.prefix().str();
848 resCMfile += what.str();
851 resCMfile += "SET(${BBTK_PACKAGE_NAME}"+ library_command +" ON)\n";
853 resCMfile += what.suffix().str();
854 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
859 } catch (boost::bad_expression& e) {
860 std::cout << "bad regex: " << e.what() << std::endl;
868 std::map<std::string, bool> modelCDMPackage::GetCustomLibraries()
870 std::map<std::string, bool> res;
871 std::map<std::string, bool> res1;
873 std::map<std::string, std::string> correspondence;
874 std::vector<modelCDMLibrary*> libraries;
875 modelCDMIProjectTreeNode* p = this;
876 while(p != NULL && dynamic_cast<modelCDMProject*>(p) == NULL)
879 if(p != NULL && dynamic_cast<modelCDMProject*>(p)->GetLib() != NULL)
880 libraries = dynamic_cast<modelCDMProject*>(p)->GetLib()->GetLibraries();
882 for (int i = 0; i < libraries.size(); ++i)
884 correspondence[libraries[i]->GetName()] = libraries[i]->GetNameLibrary();
885 res[libraries[i]->GetNameLibrary()] = false;
886 res1[libraries[i]->GetNameLibrary()] = false;
889 if (this->HasCMakeLists())
891 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
893 //find included libraries
894 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
895 std::string::const_iterator start, end;
896 start = CMfile.begin();
898 boost::match_results<std::string::const_iterator> what;
899 boost::match_flag_type flags = boost::match_default;
900 if(boost::regex_search(start, end, what, expression, flags))
903 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS");
904 std::string::const_iterator start1, end1;
905 start1 = what[0].first;
906 end1 = what[0].second;
907 boost::match_results<std::string::const_iterator> what1;
908 if(boost::regex_search(start1, end1, what1, expression, flags))
910 expression = boost::regex("^\\h*[\\w\\d]+");
911 std::string::const_iterator start2, end2;
912 start2 = what1[0].second;
913 end2 = what[0].second;
914 boost::match_results<std::string::const_iterator> what2;
915 while(boost::regex_search(start2, end2, what2, expression, flags))
917 std::string dete = what2.str();
918 CDMUtilities::normalizeStr(dete);
919 //std::cout << "detectado lib: " << dete << std::endl;
920 if(res1.find(dete) != res1.end())
923 start2 = what2[0].second;
928 //find included folders
929 //std::cout << "searching..." << std::endl;
930 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_INCLUDE_DIRS(([\\s]|#[^\\n]*\\n|////[^\\n]*\\n)+([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
931 start = CMfile.begin();
933 if(boost::regex_search(start, end, what, expression, flags))
935 //std::cout << what.str() << std::endl;
936 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_INCLUDE_DIRS");
937 std::string::const_iterator start1, end1;
938 start1 = what[0].first;
939 end1 = what[0].second;
940 boost::match_results<std::string::const_iterator> what1;
941 if(boost::regex_search(start1, end1, what1, expression, flags))
943 //std::cout << what1.str() << std::endl;
944 expression = boost::regex("^\\h*\\.\\.\\/lib\\/([\\w\\d])+");
945 std::string::const_iterator start2, end2;
946 start2 = what1[0].second;
947 end2 = what[0].second;
948 boost::match_results<std::string::const_iterator> what2;
949 while(boost::regex_search(start2, end2, what2, expression, flags))
951 std::string dete = what2.str();
952 CDMUtilities::normalizeStr(dete);
953 //std::cout << "detectado dir: " << dete.substr(7) << std::endl;
954 if(correspondence.find(dete.substr(7)) != correspondence.end())
955 res[correspondence[dete.substr(7)]] = res1[correspondence[dete.substr(7)]];
957 start2 = what2[0].second;
966 bool modelCDMPackage::SetCustomLibrary(const std::string& library_name,
967 const bool& toInclude)
969 std::map<std::string, std::string> correspondence;
971 std::vector<modelCDMLibrary*> libraries;
972 modelCDMIProjectTreeNode* p = this;
973 while(p != NULL && dynamic_cast<modelCDMProject*>(p) == NULL)
976 if(p != NULL && dynamic_cast<modelCDMProject*>(p)->GetLib() != NULL)
977 libraries = dynamic_cast<modelCDMProject*>(p)->GetLib()->GetLibraries();
979 for (int i = 0; i < libraries.size(); ++i)
981 correspondence[libraries[i]->GetNameLibrary()] = libraries[i]->GetName();
984 if (correspondence.find(library_name) != correspondence.end())
986 if (this->HasCMakeLists())
988 std::string resCMfile = "";
989 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
992 //find included libraries
993 //std::cout << "searching..." << CMfile << std::endl;
994 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
995 std::string::const_iterator start, end;
996 start = CMfile.begin();
998 boost::match_results<std::string::const_iterator> what;
999 boost::match_flag_type flags = boost::match_default;
1000 if(boost::regex_search(start, end, what, expression, flags))
1002 //std::cout << what.str() << std::endl;
1003 resCMfile += what.prefix().str();
1004 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS");
1005 std::string::const_iterator start1, end1;
1006 start1 = what[0].first;
1007 end1 = what[0].second;
1008 boost::match_results<std::string::const_iterator> what1;
1009 if(boost::regex_search(start1, end1, what1, expression, flags))
1011 resCMfile += what1.prefix().str() + what1.str();
1012 //check if already exists
1013 expression = boost::regex("^\\h*"+library_name);
1014 std::string::const_iterator start2, end2;
1015 start2 = what1[0].second;
1016 end2 = what[0].second;
1017 boost::match_results<std::string::const_iterator> what2, temp2;
1018 while(boost::regex_search(start2, end2, what2, expression, flags))
1020 resCMfile += what2.prefix().str();
1026 resCMfile += what2.str();
1028 start2 = what2[0].second;
1031 resCMfile += temp2.suffix().str();
1032 //check if is commented
1035 expression = boost::regex("^\\h*#+\\h*"+library_name);
1036 start2 = what1[0].second;
1037 end2 = what[0].second;
1038 while(boost::regex_search(start2, end2, what2, expression, flags))
1041 resCMfile += what2.prefix().str();
1044 std::string dete = what2[0].str();
1045 for (int i = 0; i < dete.size(); ++i) {
1047 resCMfile.push_back(dete[i]);
1051 start2 = what2[0].second;
1054 resCMfile += temp2.suffix().str();
1055 //add at the beggining of instruction
1059 resCMfile += "\n" + library_name;
1060 resCMfile += what1.suffix().str();
1064 resCMfile += what.suffix().str();
1069 //find included folders
1075 //std::cout << "searching..." << CMfile << std::endl;
1076 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_INCLUDE_DIRS(([\\s]|#[^\\n]*\\n)+([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
1077 start = CMfile.begin();
1079 if(boost::regex_search(start, end, what, expression, flags))
1081 resCMfile += what.prefix().str();
1082 //std::cout << what.str() << std::endl;
1083 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_INCLUDE_DIRS");
1084 std::string::const_iterator start1, end1;
1085 start1 = what[0].first;
1086 end1 = what[0].second;
1087 boost::match_results<std::string::const_iterator> what1;
1088 if(boost::regex_search(start1, end1, what1, expression, flags))
1090 resCMfile += what1.prefix().str() + what1.str();
1091 //std::cout << what1.str() << std::endl;
1092 //search if dir is already included
1093 expression = boost::regex("^\\h*\\.\\.\\/lib\\/"+correspondence[library_name]);
1094 std::string::const_iterator start2, end2;
1095 start2 = what1[0].second;
1096 end2 = what[0].second;
1097 boost::match_results<std::string::const_iterator> what2, temp2;
1098 while(boost::regex_search(start2, end2, what2, expression, flags))
1101 resCMfile += what2.prefix().str();
1104 resCMfile += what2.str();
1106 start2 = what2[0].second;
1109 resCMfile += temp2.suffix().str();
1110 //search if dir is commented
1113 expression = boost::regex("^\\h*#+\\h*\\.\\.\\/lib\\/"+correspondence[library_name]);
1114 start2 = what1[0].second;
1115 end2 = what[0].second;
1116 while(boost::regex_search(start2, end2, what2, expression, flags))
1119 resCMfile += what2.prefix().str();
1122 std::string dete = what2[0].str();
1123 for (int i = 0; i < dete.size(); ++i) {
1125 resCMfile.push_back(dete[i]);
1129 start2 = what2[0].second;
1132 resCMfile += temp2.suffix().str();
1133 //add at the beggining of instruction
1137 resCMfile += "\n../lib/" + correspondence[library_name];
1138 resCMfile += what1.suffix().str();
1142 resCMfile += what.suffix().str();
1147 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);