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 // std::cout << "found correspondence " << library_command << std::endl;
767 // std::cout.flush();
768 if (this->HasCMakeLists())
770 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
771 std::string resCMfile = "";
774 // std::cout << "found cmakefile: " << CMfile << std::endl;
775 // std::cout.flush();
778 // std::cout << "first regex" << std::endl;
779 // std::cout.flush();
780 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+ON([\\s]|#[^\\n]*\\n)*\\)");
782 std::string::const_iterator start, end;
783 start = CMfile.begin();
785 boost::match_results<std::string::const_iterator> what;
786 boost::match_flag_type flags = boost::match_default;
787 if(boost::regex_search(start, end, what, expression, flags))
789 // std::cout << "found " << what.str() << std::endl;
790 // std::cout.flush();
792 resCMfile += what.prefix().str();
794 resCMfile += what.str();
796 resCMfile += "#" + what.str();
797 resCMfile += what.suffix().str();
799 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
803 // std::cout << "second regex" << std::endl;
804 // std::cout.flush();
805 boost::regex expression("^\\h*#\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+ON([\\s]|#[^\\n]*\\n)*\\)");
806 if(boost::regex_search(start, end, what, expression, flags))
809 resCMfile += what.prefix().str();
812 std::string dete = what[0].str();
813 for (int i = 0; i < dete.size(); ++i) {
815 resCMfile.push_back(dete[i]);
818 resCMfile += dete.substr(i+1);
824 resCMfile += what.str();
826 resCMfile += what.suffix().str();
827 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
831 // std::cout << "third regex" << std::endl;
832 // std::cout.flush();
833 boost::regex expression("^\\h*#\\h*UNCOMMENT EACH LIBRARY NEEDED \\(WILL BE FOUND AND USED AUTOMATICALLY\\)[^\\n]*\\n");
834 if(boost::regex_search(start, end, what, expression, flags))
837 resCMfile += what.prefix().str();
838 resCMfile += what.str();
841 resCMfile += "SET(${BBTK_PACKAGE_NAME}"+ library_command +" ON)\n";
843 resCMfile += what.suffix().str();
844 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
848 } catch (boost::bad_expression& e) {
849 std::cout << "bad regex: " << e.what() << std::endl;
857 std::map<std::string, bool> modelCDMPackage::GetCustomLibraries()
859 std::map<std::string, bool> res;
860 std::map<std::string, bool> res1;
862 std::map<std::string, std::string> correspondence;
863 std::vector<modelCDMLibrary*> libraries;
864 modelCDMIProjectTreeNode* p = this;
865 while(p != NULL && dynamic_cast<modelCDMProject*>(p) == NULL)
868 if(p != NULL && dynamic_cast<modelCDMProject*>(p)->GetLib() != NULL)
869 libraries = dynamic_cast<modelCDMProject*>(p)->GetLib()->GetLibraries();
871 for (int i = 0; i < libraries.size(); ++i)
873 correspondence[libraries[i]->GetName()] = libraries[i]->GetNameLibrary();
874 res[libraries[i]->GetNameLibrary()] = false;
875 res1[libraries[i]->GetNameLibrary()] = false;
878 if (this->HasCMakeLists())
880 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
882 //find included libraries
883 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
884 std::string::const_iterator start, end;
885 start = CMfile.begin();
887 boost::match_results<std::string::const_iterator> what;
888 boost::match_flag_type flags = boost::match_default;
889 if(boost::regex_search(start, end, what, expression, flags))
892 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS");
893 std::string::const_iterator start1, end1;
894 start1 = what[0].first;
895 end1 = what[0].second;
896 boost::match_results<std::string::const_iterator> what1;
897 if(boost::regex_search(start1, end1, what1, expression, flags))
899 expression = boost::regex("^\\h*[\\w\\d]+");
900 std::string::const_iterator start2, end2;
901 start2 = what1[0].second;
902 end2 = what[0].second;
903 boost::match_results<std::string::const_iterator> what2;
904 while(boost::regex_search(start2, end2, what2, expression, flags))
906 std::string dete = what2.str();
907 CDMUtilities::normalizeStr(dete);
908 //std::cout << "detectado lib: " << dete << std::endl;
909 if(res1.find(dete) != res1.end())
912 start2 = what2[0].second;
917 //find included folders
918 //std::cout << "searching..." << std::endl;
919 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)*\\)");
920 start = CMfile.begin();
922 if(boost::regex_search(start, end, what, expression, flags))
924 //std::cout << what.str() << std::endl;
925 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_INCLUDE_DIRS");
926 std::string::const_iterator start1, end1;
927 start1 = what[0].first;
928 end1 = what[0].second;
929 boost::match_results<std::string::const_iterator> what1;
930 if(boost::regex_search(start1, end1, what1, expression, flags))
932 //std::cout << what1.str() << std::endl;
933 expression = boost::regex("^\\h*\\.\\.\\/lib\\/([\\w\\d])+");
934 std::string::const_iterator start2, end2;
935 start2 = what1[0].second;
936 end2 = what[0].second;
937 boost::match_results<std::string::const_iterator> what2;
938 while(boost::regex_search(start2, end2, what2, expression, flags))
940 std::string dete = what2.str();
941 CDMUtilities::normalizeStr(dete);
942 //std::cout << "detectado dir: " << dete.substr(7) << std::endl;
943 if(correspondence.find(dete.substr(7)) != correspondence.end())
944 res[correspondence[dete.substr(7)]] = res1[correspondence[dete.substr(7)]];
946 start2 = what2[0].second;
955 bool modelCDMPackage::SetCustomLibrary(const std::string& library_name,
956 const bool& toInclude)