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);
166 std::size_t fileTypePos = stdfileName.find_last_of(".");
167 std::string fileType = stdfileName.substr(fileTypePos);
169 //if CMakeLists, create CMakeLists
170 if(stdfileName == "CMakeLists.txt")
172 this->CMakeLists = new modelCDMCMakeListsFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
173 this->children.push_back(this->CMakeLists);
175 //if is a code file, create code file
176 else if(fileType == ".c" ||
177 fileType == ".cxx" ||
179 fileType == ".cpp" ||
180 fileType == ".txx" ||
181 fileType == ".cmake" )
183 modelCDMCodeFile* file = new modelCDMCodeFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
184 this->children.push_back(file);
186 //if is an unknown file, create file
189 this->children.push_back(new modelCDMFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
192 cont = dir.GetNext(&fileName);
195 this->SortChildren();
198 modelCDMPackage::~modelCDMPackage()
202 const std::string& modelCDMPackage::GetNamePackage() const
204 return this->namePackage;
207 const std::string& modelCDMPackage::GetAuthors() const
209 return this->authors;
212 const std::string& modelCDMPackage::GetAuthorsEmail() const
214 return this->authorsEmail;
217 const std::string& modelCDMPackage::GetVersion() const
219 return this->version;
222 const std::string& modelCDMPackage::GetDescription() const
224 return this->description;
227 modelCDMPackageSrc* modelCDMPackage::GetSrc() const
232 bool modelCDMPackage::SetAuthors(const std::string& authors, std::string*& result)
234 std::vector<std::string> words;
235 CDMUtilities::splitter::split(words, authors, ",\n", CDMUtilities::splitter::no_empties);
236 std::string authorsReal = words[0];
237 for (int i = 1; i < (int)(words.size()); i++)
239 authorsReal += "/" + words[i];
243 //opening original cmakelists
244 std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
247 result = new std::string("CMakeLists.txt file failed to open.");
250 //opening temporal cmakelists
251 std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
254 result = new std::string("CMakeLists.txt.tmp file failed to open.");
257 //copying contents from original to temporal and making changes
258 while (getline(in, line))
260 if(line.find("SET(${BBTK_PACKAGE_NAME}_AUTHOR") != std::string::npos)
261 line = "SET(${BBTK_PACKAGE_NAME}_AUTHOR \"" + authorsReal + "\")";
262 out << line << std::endl;
266 //delete old file and rename new file
268 std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
270 std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
273 if(system(renameCommand.c_str()))
275 result = new std::string("An error occurred while running '" + renameCommand + "'.");
279 this->authors = authorsReal;
283 bool modelCDMPackage::SetAuthorsEmail(const std::string& email, std::string*& result)
285 //TODO: implement method
289 bool modelCDMPackage::SetVersion(const std::string& version, std::string*& result)
291 std::vector<std::string> vers;
292 CDMUtilities::splitter::split(vers, version, " .", CDMUtilities::splitter::no_empties);
296 //opening original cmakelists
297 std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
300 result = new std::string("CMakeLists.txt file failed to open.");
303 //opening temporal cmakelists
304 std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
307 result = new std::string("CMakeLists.txt.tmp file failed to open.");
310 //copying contents from original to temporal and making changes
311 while (getline(in, line))
313 if(line.find("SET(${BBTK_PACKAGE_NAME}_MAJOR_VERSION") != std::string::npos)
314 line = "SET(${BBTK_PACKAGE_NAME}_MAJOR_VERSION " + vers[0] + ")";
315 else if(line.find("SET(${BBTK_PACKAGE_NAME}_VERSION") != std::string::npos)
316 line = "SET(${BBTK_PACKAGE_NAME}_MINOR_VERSION " + vers[1] + ")";
317 else if(line.find("SET(${BBTK_PACKAGE_NAME}_BUILD_VERSION") != std::string::npos)
318 line = "SET(${BBTK_PACKAGE_NAME}_BUILD_VERSION " + vers[2] + ")";
319 out << line << std::endl;
323 //delete old file and rename new file
325 std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
327 std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
330 if(system(renameCommand.c_str()))
332 result = new std::string("An error occurred while running '" + renameCommand + "'.");
336 this->version = vers[0] + "." + vers[1] + "." + vers[2];
340 bool modelCDMPackage::SetDescription(const std::string& description, std::string*& result)
342 std::vector<std::string> words;
343 CDMUtilities::splitter::split(words, description, " \n", CDMUtilities::splitter::no_empties);
344 std::string descriptionReal = words[0];
345 for (int i = 1; i < (int)(words.size()); i++)
347 descriptionReal += " " + words[i];
351 //opening original cmakelists
352 std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
355 result = new std::string("CMakeLists.txt file failed to open.");
358 //opening temporal cmakelists
359 std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
362 result = new std::string("CMakeLists.txt.tmp file failed to open.");
365 //copying contents from original to temporal and making changes
366 while (getline(in, line))
368 if(line.find("SET(${BBTK_PACKAGE_NAME}_DESCRIPTION") != std::string::npos)
369 line = "SET(${BBTK_PACKAGE_NAME}_DESCRIPTION \"" + descriptionReal + "\")";
370 out << line << std::endl;
374 //delete old file and rename new file
376 std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
378 std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
381 if(system(renameCommand.c_str()))
383 result = new std::string("An error occurred while running '" + renameCommand + "'.");
387 this->description = descriptionReal;
391 modelCDMBlackBox* modelCDMPackage::CreateBlackBox(
392 std::string*& result,
393 const std::string& name,
394 const std::string& type,
395 const std::string& format,
396 const std::string& categories,
397 const std::string& authors,
398 const std::string& authorsEmail,
399 const std::string& description
402 return this->src->CreateBlackBox(result,name, this->namePackage, type,format,categories,authors,authorsEmail,description);
405 const bool modelCDMPackage::Refresh(std::string*& result)
407 std::cout << "refreshing package " << this->namePackage << std::endl;
408 this->type = wxDIR_DIRS;
412 std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
414 std::ifstream confFile;
415 confFile.open((pathMakeLists).c_str());
418 while(confFile.is_open() && !confFile.eof())
421 std::getline(confFile,word,'(');
422 std::vector<std::string> wordBits;
423 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
425 if(wordBits[wordBits.size()-1] == "SET")
428 std::getline(confFile,word,')');
429 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
430 if(wordBits[0] == "BBTK_PACKAGE_NAME")
433 for (int i = 2; i < (int)(wordBits.size()); i++)
435 word += " " + wordBits[i];
438 CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
440 this->namePackage = wordBits[0];
442 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_AUTHOR")
445 for (int i = 2; i < (int)(wordBits.size()); i++)
447 word += " " + wordBits[i];
450 CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
452 this->authors = wordBits[0];
454 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_DESCRIPTION")
457 for (int i = 2; i < (int)(wordBits.size()); i++)
459 word += " " + wordBits[i];
462 CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
464 this->description = wordBits[0];
466 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_MAJOR_VERSION")
468 this->version = wordBits[1];
470 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_MINOR_VERSION")
472 this->version += "." + wordBits[1];
474 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_BUILD_VERSION")
476 this->version += "." + wordBits[1];
483 std::vector<bool> checked(this->children.size(), false);
484 bool checkedSrc = false;
487 wxDir dir(crea::std2wx((this->path).c_str()));
491 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
495 std::string stdfileName = crea::wx2std(fileName);
497 //detect black boxes in src
498 if(stdfileName == "src")
500 //check if box already exist
502 if (this->src != NULL)
505 int pos = std::find(this->children.begin(), this->children.end(), this->src) - this->children.begin();
508 if(!this->src->Refresh(result))
513 this->src = new modelCDMPackageSrc(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level +1);
514 this->children.push_back(this->src);
520 //check if folder already exist
522 for (int i = 0; !found && i < (int)(this->children.size()); i++)
524 if (this->children[i]->GetName() == stdfileName)
528 if(!this->children[i]->Refresh(result))
534 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
535 this->children.push_back(folder);
538 cont = dir.GetNext(&fileName);
542 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
545 std::string stdfileName = crea::wx2std(fileName);
546 std::size_t fileTypePos = stdfileName.find_last_of(".");
547 std::string fileType = stdfileName.substr(fileTypePos);
549 //if CMakeLists, create CMakeLists
550 if(stdfileName == "CMakeLists.txt")
552 if (this->CMakeLists == NULL)
554 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
555 this->children.push_back(this->CMakeLists);
559 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
561 if(!this->CMakeLists->Refresh(result))
565 //if is an unknown file, create file
569 for (int i = 0; !found && i < (int)(this->children.size()); i++)
571 if (this->children[i]->GetName() == stdfileName)
575 if(!this->children[i]->Refresh(result))
582 //if is a code file, create modelCDMCodeFile
585 fileType == ".cxx" ||
587 fileType == ".cpp" ||
588 fileType == ".txx" ||
589 fileType == ".cmake" )
591 this->children.push_back(new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
595 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
596 this->children.push_back(file);
601 cont = dir.GetNext(&fileName);
610 for (int i = 0; i < (int)(checked.size()); i++)
614 delete this->children[i];
615 this->children.erase(this->children.begin()+i);
616 checked.erase(checked.begin()+i);
620 this->SortChildren();
624 void modelCDMPackage::CheckStructure(std::map<std::string, bool>& properties)
627 if(this->CMakeLists != NULL)
630 std::ifstream confFile;
631 confFile.open((this->CMakeLists->GetPath()).c_str());
633 //take everything that is not commented
634 std::string fileContent;
637 std::vector<std::string> words;
638 while(confFile.is_open() && !confFile.eof())
640 std::getline(confFile,word, '\n');
643 CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok);
644 if (words.size() > 0)
647 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
648 for (int i = 0; i < (int)(words.size()); i++)
650 if(words[i].substr(0,2) == "//")
652 fileContent += words[i] + " ";
658 //check every instruction
659 std::stringstream ss(fileContent);
662 std::getline(ss,word, '(');
664 //check instruction name
665 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
668 if (words.size() > 0 && words[words.size()-1] == "SET")
670 std::getline(ss,word, ')');
672 CDMUtilities::splitter::split(words, word, " \t", CDMUtilities::splitter::no_empties);
673 if (words.size() > 1)
675 if (words[0] == "${BBTK_PACKAGE_NAME}_USE_VTK" && words[1] == "ON")
677 properties["package " + this->name + " set USE_VTK"] = true;
679 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_ITK" && words[1] == "ON")
681 properties["package " + this->name + " set USE_ITK"] = true;
683 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_GDCM" && words[1] == "ON")
685 properties["package " + this->name + " set USE_GDCM"] = true;
687 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_GDCM_VTK" && words[1] == "ON")
689 properties["package " + this->name + " set USE_GDCM_VTK"] = true;
691 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_GSMIS" && words[1] == "ON")
693 properties["package " + this->name + " set USE_GSMIS"] = true;
695 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_WXWIDGETS" && words[1] == "ON")
697 properties["package " + this->name + " set USE_WXWIDGETS"] = true;
699 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_KWWIDGETS" && words[1] == "ON")
701 properties["package " + this->name + " set USE_KWWIDGETS"] = true;
703 else if (words[0] == "USE_BOOST" && words[1] == "ON")
705 properties["package " + this->name + " set USE_BOOST"] = true;
707 else if (words[0] == "${BBTK_PACKAGE_NAME}_INCLUDE_DIRS")
709 for (int i = 1; i < (int)(words.size()); i++)
711 if(words[i].substr(0,2) == "${" || words[i].substr(0,2) == "..")
712 properties["package " + this->name + " dir " + words[i]] = true;
715 else if (words[0] == "${BBTK_PACKAGE_NAME}_LIBS")
717 for (int i = 1; i < (int)(words.size()); i++)
719 properties["package " + this->name + " lib " + words[i]] = true;
729 std::map<std::string, bool> modelCDMPackage::Get3rdPartyLibraries()
731 std::map<std::string, std::string> correspondence;
732 correspondence["${BBTK_PACKAGE_NAME}_USE_VTK"] = "VTK";
733 correspondence["${BBTK_PACKAGE_NAME}_USE_ITK"] = "ITK";
734 correspondence["${BBTK_PACKAGE_NAME}_USE_GDCM"] = "GDCM";
735 correspondence["${BBTK_PACKAGE_NAME}_USE_GDCM_VTK"] = "GDCM_VTK";
736 correspondence["${BBTK_PACKAGE_NAME}_USE_GSMIS"] = "GSMIS";
737 correspondence["${BBTK_PACKAGE_NAME}_USE_WXWIDGETS"] = "WxWidgets";
738 correspondence["${BBTK_PACKAGE_NAME}_USE_KWWIDGETS"] = "KWWidgets";
739 std::map<std::string, bool> res;
743 res["GDCM_VTK"] = false;
744 res["GSMIS"] = false;
745 res["WxWidgets"] = false;
746 res["KWWidgets"] = false;
748 if (this->HasCMakeLists())
750 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
752 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_USE_\\w+\\s+ON");
753 std::string::const_iterator start, end;
754 start = CMfile.begin();
756 boost::match_results<std::string::const_iterator> what;
757 boost::match_flag_type flags = boost::match_default;
758 while(boost::regex_search(start, end, what, expression, flags))
760 //std::cout << what[0].str() << std::endl;
761 boost::regex expression1 = boost::regex("\\$\\{BBTK_PACKAGE_NAME\\}_USE_\\w+");
762 std::string::const_iterator start1, end1;
763 start1 = what[0].first;
764 end1 = what[0].second;
765 boost::match_results<std::string::const_iterator> what1;
766 if(boost::regex_search(start1, end1, what1, expression1, flags))
768 std::string dete = what1.str();
769 CDMUtilities::normalizeStr(dete);
770 //std::cout << dete << std::endl;
771 if(correspondence.find(dete) != correspondence.end())
772 res[correspondence[dete]] = true;
774 start = what[0].second;
780 bool modelCDMPackage::Set3rdPartyLibrary(const std::string& library_name,
781 const bool& toInclude)
783 std::map<std::string, std::string> correspondence;
785 correspondence["VTK"] = "_USE_VTK";
786 correspondence["ITK"] = "_USE_ITK";
787 correspondence["GDCM"] = "_USE_GDCM";
788 correspondence["GDCM_VTK"] = "_USE_GDCM_VTK";
789 correspondence["GSMIS"] = "_USE_GSMIS";
790 correspondence["WxWidgets"] = "_USE_WXWIDGETS";
791 correspondence["KWWidgets"] = "_USE_KWWIDGETS";
793 if (correspondence.find(library_name) != correspondence.end())
795 std::string library_command = correspondence[library_name];
796 if (this->HasCMakeLists())
798 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
799 std::string resCMfile = "";
803 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+ON([\\s]|#[^\\n]*\\n)*\\)");
805 std::string::const_iterator start, end;
806 start = CMfile.begin();
808 boost::match_results<std::string::const_iterator> what;
809 boost::match_flag_type flags = boost::match_default;
810 if(boost::regex_search(start, end, what, expression, flags))
813 resCMfile += what.prefix().str();
815 resCMfile += what.str();
817 resCMfile += "#" + what.str();
818 resCMfile += what.suffix().str();
820 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
824 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+OFF([\\s]|#[^\\n]*\\n)*\\)");
826 start = CMfile.begin();
828 if(boost::regex_search(start, end, what, expression, flags))
831 resCMfile += what.prefix().str();
834 std::string dete = what.str();
835 int pos = dete.rfind("OFF");
836 dete.replace(pos, 3, "ON");
840 resCMfile += what.str();
841 resCMfile += what.suffix().str();
843 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
847 boost::regex expression("^\\h*#\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+ON([\\s]|#[^\\n]*\\n)*\\)");
848 if(boost::regex_search(start, end, what, expression, flags))
851 resCMfile += what.prefix().str();
854 std::string dete = what[0].str();
855 for (int i = 0; i < dete.size(); ++i) {
857 resCMfile.push_back(dete[i]);
860 resCMfile += dete.substr(i+1);
866 resCMfile += what.str();
868 resCMfile += what.suffix().str();
869 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
873 boost::regex expression("^\\h*#\\h*UNCOMMENT EACH LIBRARY NEEDED \\(WILL BE FOUND AND USED AUTOMATICALLY\\)[^\\n]*\\n");
874 if(boost::regex_search(start, end, what, expression, flags))
877 resCMfile += what.prefix().str();
878 resCMfile += what.str();
881 resCMfile += "SET(${BBTK_PACKAGE_NAME}"+ library_command +" ON)\n";
883 resCMfile += what.suffix().str();
884 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
889 } catch (boost::bad_expression& e) {
890 std::cout << "bad regex: " << e.what() << std::endl;
898 std::map<std::string, bool> modelCDMPackage::GetCustomLibraries()
900 std::map<std::string, bool> res;
901 std::map<std::string, bool> res1;
903 std::map<std::string, std::string> correspondence;
904 std::vector<modelCDMLibrary*> libraries;
905 modelCDMIProjectTreeNode* p = this;
906 while(p != NULL && dynamic_cast<modelCDMProject*>(p) == NULL)
909 if(p != NULL && dynamic_cast<modelCDMProject*>(p)->GetLib() != NULL)
910 libraries = dynamic_cast<modelCDMProject*>(p)->GetLib()->GetLibraries();
912 for (int i = 0; i < libraries.size(); ++i)
914 correspondence[libraries[i]->GetName()] = libraries[i]->GetNameLibrary();
915 res[libraries[i]->GetNameLibrary()] = false;
916 res1[libraries[i]->GetNameLibrary()] = false;
919 if (this->HasCMakeLists())
921 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
923 //find included libraries
924 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
925 std::string::const_iterator start, end;
926 start = CMfile.begin();
928 boost::match_results<std::string::const_iterator> what;
929 boost::match_flag_type flags = boost::match_default;
930 if(boost::regex_search(start, end, what, expression, flags))
933 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS");
934 std::string::const_iterator start1, end1;
935 start1 = what[0].first;
936 end1 = what[0].second;
937 boost::match_results<std::string::const_iterator> what1;
938 if(boost::regex_search(start1, end1, what1, expression, flags))
940 expression = boost::regex("^\\h*[\\w\\d]+");
941 std::string::const_iterator start2, end2;
942 start2 = what1[0].second;
943 end2 = what[0].second;
944 boost::match_results<std::string::const_iterator> what2;
945 while(boost::regex_search(start2, end2, what2, expression, flags))
947 std::string dete = what2.str();
948 CDMUtilities::normalizeStr(dete);
949 //std::cout << "detectado lib: " << dete << std::endl;
950 if(res1.find(dete) != res1.end())
953 start2 = what2[0].second;
958 //find included folders
959 //std::cout << "searching..." << std::endl;
960 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)*\\)");
961 start = CMfile.begin();
963 if(boost::regex_search(start, end, what, expression, flags))
965 //std::cout << what.str() << std::endl;
966 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_INCLUDE_DIRS");
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 //std::cout << what1.str() << std::endl;
974 expression = boost::regex("^\\h*\\.\\.\\/lib\\/([\\w\\d])+");
975 std::string::const_iterator start2, end2;
976 start2 = what1[0].second;
977 end2 = what[0].second;
978 boost::match_results<std::string::const_iterator> what2;
979 while(boost::regex_search(start2, end2, what2, expression, flags))
981 std::string dete = what2.str();
982 CDMUtilities::normalizeStr(dete);
983 //std::cout << "detectado dir: " << dete.substr(7) << std::endl;
984 if(correspondence.find(dete.substr(7)) != correspondence.end())
985 res[correspondence[dete.substr(7)]] = res1[correspondence[dete.substr(7)]];
987 start2 = what2[0].second;
996 bool modelCDMPackage::SetCustomLibrary(const std::string& library_name,
997 const bool& toInclude)
999 std::map<std::string, std::string> correspondence;
1001 std::vector<modelCDMLibrary*> libraries;
1002 modelCDMIProjectTreeNode* p = this;
1003 while(p != NULL && dynamic_cast<modelCDMProject*>(p) == NULL)
1006 if(p != NULL && dynamic_cast<modelCDMProject*>(p)->GetLib() != NULL)
1007 libraries = dynamic_cast<modelCDMProject*>(p)->GetLib()->GetLibraries();
1009 for (int i = 0; i < libraries.size(); ++i)
1011 correspondence[libraries[i]->GetNameLibrary()] = libraries[i]->GetName();
1014 if (correspondence.find(library_name) != correspondence.end())
1016 if (this->HasCMakeLists())
1018 std::string resCMfile = "";
1019 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
1022 //find included libraries
1023 //std::cout << "searching..." << CMfile << std::endl;
1024 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
1025 std::string::const_iterator start, end;
1026 start = CMfile.begin();
1028 boost::match_results<std::string::const_iterator> what;
1029 boost::match_flag_type flags = boost::match_default;
1030 if(boost::regex_search(start, end, what, expression, flags))
1032 //std::cout << what.str() << std::endl;
1033 resCMfile += what.prefix().str();
1034 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS");
1035 std::string::const_iterator start1, end1;
1036 start1 = what[0].first;
1037 end1 = what[0].second;
1038 boost::match_results<std::string::const_iterator> what1;
1039 if(boost::regex_search(start1, end1, what1, expression, flags))
1041 resCMfile += what1.prefix().str() + what1.str();
1042 //check if already exists
1043 expression = boost::regex("^\\h*"+library_name);
1044 std::string::const_iterator start2, end2;
1045 start2 = what1[0].second;
1046 end2 = what[0].second;
1047 boost::match_results<std::string::const_iterator> what2, temp2;
1048 while(boost::regex_search(start2, end2, what2, expression, flags))
1050 resCMfile += what2.prefix().str();
1056 resCMfile += what2.str();
1058 start2 = what2[0].second;
1061 resCMfile += temp2.suffix().str();
1062 //check if is commented
1065 expression = boost::regex("^\\h*#+\\h*"+library_name);
1066 start2 = what1[0].second;
1067 end2 = what[0].second;
1068 while(boost::regex_search(start2, end2, what2, expression, flags))
1071 resCMfile += what2.prefix().str();
1074 std::string dete = what2[0].str();
1075 for (int i = 0; i < dete.size(); ++i) {
1077 resCMfile.push_back(dete[i]);
1081 start2 = what2[0].second;
1084 resCMfile += temp2.suffix().str();
1085 //add at the beggining of instruction
1089 resCMfile += "\n" + library_name;
1090 resCMfile += what1.suffix().str();
1094 resCMfile += what.suffix().str();
1099 //find included folders
1105 //std::cout << "searching..." << CMfile << std::endl;
1106 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_INCLUDE_DIRS(([\\s]|#[^\\n]*\\n)+([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
1107 start = CMfile.begin();
1109 if(boost::regex_search(start, end, what, expression, flags))
1111 resCMfile += what.prefix().str();
1112 //std::cout << what.str() << std::endl;
1113 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_INCLUDE_DIRS");
1114 std::string::const_iterator start1, end1;
1115 start1 = what[0].first;
1116 end1 = what[0].second;
1117 boost::match_results<std::string::const_iterator> what1;
1118 if(boost::regex_search(start1, end1, what1, expression, flags))
1120 resCMfile += what1.prefix().str() + what1.str();
1121 //std::cout << what1.str() << std::endl;
1122 //search if dir is already included
1123 expression = boost::regex("^\\h*\\.\\.\\/lib\\/"+correspondence[library_name]);
1124 std::string::const_iterator start2, end2;
1125 start2 = what1[0].second;
1126 end2 = what[0].second;
1127 boost::match_results<std::string::const_iterator> what2, temp2;
1128 while(boost::regex_search(start2, end2, what2, expression, flags))
1131 resCMfile += what2.prefix().str();
1134 resCMfile += what2.str();
1136 start2 = what2[0].second;
1139 resCMfile += temp2.suffix().str();
1140 //search if dir is commented
1143 expression = boost::regex("^\\h*#+\\h*\\.\\.\\/lib\\/"+correspondence[library_name]);
1144 start2 = what1[0].second;
1145 end2 = what[0].second;
1146 while(boost::regex_search(start2, end2, what2, expression, flags))
1149 resCMfile += what2.prefix().str();
1152 std::string dete = what2[0].str();
1153 for (int i = 0; i < dete.size(); ++i) {
1155 resCMfile.push_back(dete[i]);
1159 start2 = what2[0].second;
1162 resCMfile += temp2.suffix().str();
1163 //add at the beggining of instruction
1167 resCMfile += "\n../lib/" + correspondence[library_name];
1168 resCMfile += what1.suffix().str();
1172 resCMfile += what.suffix().str();
1177 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);