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;
168 if(fileTypePos != std::string::npos)
169 fileType = stdfileName.substr(fileTypePos);
173 //if CMakeLists, create CMakeLists
174 if(stdfileName == "CMakeLists.txt")
176 this->CMakeLists = new modelCDMCMakeListsFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
177 this->children.push_back(this->CMakeLists);
179 //if is a code file, create code file
180 else if(fileType == ".c" ||
181 fileType == ".cxx" ||
183 fileType == ".cpp" ||
184 fileType == ".txx" ||
185 fileType == ".cmake" )
187 modelCDMCodeFile* file = new modelCDMCodeFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
188 this->children.push_back(file);
190 //if is an unknown file, create file
193 this->children.push_back(new modelCDMFile(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
196 cont = dir.GetNext(&fileName);
199 this->SortChildren();
202 modelCDMPackage::~modelCDMPackage()
206 const std::string& modelCDMPackage::GetNamePackage() const
208 return this->namePackage;
211 const std::string& modelCDMPackage::GetAuthors() const
213 return this->authors;
216 const std::string& modelCDMPackage::GetAuthorsEmail() const
218 return this->authorsEmail;
221 const std::string& modelCDMPackage::GetVersion() const
223 return this->version;
226 const std::string& modelCDMPackage::GetDescription() const
228 return this->description;
231 modelCDMPackageSrc* modelCDMPackage::GetSrc() const
236 bool modelCDMPackage::SetAuthors(const std::string& authors, std::string*& result)
238 std::vector<std::string> words;
239 CDMUtilities::splitter::split(words, authors, ",\n", CDMUtilities::splitter::no_empties);
240 std::string authorsReal = words[0];
241 for (int i = 1; i < (int)(words.size()); i++)
243 authorsReal += "/" + words[i];
247 //opening original cmakelists
248 std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
251 result = new std::string("CMakeLists.txt file failed to open.");
254 //opening temporal cmakelists
255 std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
258 result = new std::string("CMakeLists.txt.tmp file failed to open.");
261 //copying contents from original to temporal and making changes
262 while (getline(in, line))
264 if(line.find("SET(${BBTK_PACKAGE_NAME}_AUTHOR") != std::string::npos)
265 line = "SET(${BBTK_PACKAGE_NAME}_AUTHOR \"" + authorsReal + "\")";
266 out << line << std::endl;
270 //delete old file and rename new file
272 std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
274 std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
277 if(system(renameCommand.c_str()))
279 result = new std::string("An error occurred while running '" + renameCommand + "'.");
283 this->authors = authorsReal;
287 bool modelCDMPackage::SetAuthorsEmail(const std::string& email, std::string*& result)
289 //TODO: implement method
293 bool modelCDMPackage::SetVersion(const std::string& version, std::string*& result)
295 std::vector<std::string> vers;
296 CDMUtilities::splitter::split(vers, version, " .", CDMUtilities::splitter::no_empties);
300 //opening original cmakelists
301 std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
304 result = new std::string("CMakeLists.txt file failed to open.");
307 //opening temporal cmakelists
308 std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
311 result = new std::string("CMakeLists.txt.tmp file failed to open.");
314 //copying contents from original to temporal and making changes
315 while (getline(in, line))
317 if(line.find("SET(${BBTK_PACKAGE_NAME}_MAJOR_VERSION") != std::string::npos)
318 line = "SET(${BBTK_PACKAGE_NAME}_MAJOR_VERSION " + vers[0] + ")";
319 else if(line.find("SET(${BBTK_PACKAGE_NAME}_VERSION") != std::string::npos)
320 line = "SET(${BBTK_PACKAGE_NAME}_MINOR_VERSION " + vers[1] + ")";
321 else if(line.find("SET(${BBTK_PACKAGE_NAME}_BUILD_VERSION") != std::string::npos)
322 line = "SET(${BBTK_PACKAGE_NAME}_BUILD_VERSION " + vers[2] + ")";
323 out << line << std::endl;
327 //delete old file and rename new file
329 std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
331 std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
334 if(system(renameCommand.c_str()))
336 result = new std::string("An error occurred while running '" + renameCommand + "'.");
340 this->version = vers[0] + "." + vers[1] + "." + vers[2];
344 bool modelCDMPackage::SetDescription(const std::string& description, std::string*& result)
346 std::vector<std::string> words;
347 CDMUtilities::splitter::split(words, description, " \n", CDMUtilities::splitter::no_empties);
348 std::string descriptionReal = words[0];
349 for (int i = 1; i < (int)(words.size()); i++)
351 descriptionReal += " " + words[i];
355 //opening original cmakelists
356 std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
359 result = new std::string("CMakeLists.txt file failed to open.");
362 //opening temporal cmakelists
363 std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
366 result = new std::string("CMakeLists.txt.tmp file failed to open.");
369 //copying contents from original to temporal and making changes
370 while (getline(in, line))
372 if(line.find("SET(${BBTK_PACKAGE_NAME}_DESCRIPTION") != std::string::npos)
373 line = "SET(${BBTK_PACKAGE_NAME}_DESCRIPTION \"" + descriptionReal + "\")";
374 out << line << std::endl;
378 //delete old file and rename new file
380 std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
382 std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
385 if(system(renameCommand.c_str()))
387 result = new std::string("An error occurred while running '" + renameCommand + "'.");
391 this->description = descriptionReal;
395 modelCDMBlackBox* modelCDMPackage::CreateBlackBox(
396 std::string*& result,
397 const std::string& name,
398 const std::string& type,
399 const std::string& format,
400 const std::string& categories,
401 const std::string& authors,
402 const std::string& authorsEmail,
403 const std::string& description
406 return this->src->CreateBlackBox(result,name, this->namePackage, type,format,categories,authors,authorsEmail,description);
409 const bool modelCDMPackage::Refresh(std::string*& result)
411 std::cout << "refreshing package " << this->namePackage << std::endl;
412 this->type = wxDIR_DIRS;
416 std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
418 std::ifstream confFile;
419 confFile.open((pathMakeLists).c_str());
422 while(confFile.is_open() && !confFile.eof())
425 std::getline(confFile,word,'(');
426 std::vector<std::string> wordBits;
427 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
429 if(wordBits[wordBits.size()-1] == "SET")
432 std::getline(confFile,word,')');
433 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
434 if(wordBits[0] == "BBTK_PACKAGE_NAME")
437 for (int i = 2; i < (int)(wordBits.size()); i++)
439 word += " " + wordBits[i];
442 CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
444 this->namePackage = wordBits[0];
446 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_AUTHOR")
449 for (int i = 2; i < (int)(wordBits.size()); i++)
451 word += " " + wordBits[i];
454 CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
456 this->authors = wordBits[0];
458 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_DESCRIPTION")
461 for (int i = 2; i < (int)(wordBits.size()); i++)
463 word += " " + wordBits[i];
466 CDMUtilities::splitter::split(wordBits, word, "\"", CDMUtilities::splitter::no_empties);
468 this->description = wordBits[0];
470 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_MAJOR_VERSION")
472 this->version = wordBits[1];
474 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_MINOR_VERSION")
476 this->version += "." + wordBits[1];
478 else if(wordBits[0] == "${BBTK_PACKAGE_NAME}_BUILD_VERSION")
480 this->version += "." + wordBits[1];
487 std::vector<bool> checked(this->children.size(), false);
488 bool checkedSrc = false;
491 wxDir dir(crea::std2wx((this->path).c_str()));
495 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
499 std::string stdfileName = crea::wx2std(fileName);
501 //detect black boxes in src
502 if(stdfileName == "src")
504 //check if box already exist
506 if (this->src != NULL)
509 int pos = std::find(this->children.begin(), this->children.end(), this->src) - this->children.begin();
512 if(!this->src->Refresh(result))
517 this->src = new modelCDMPackageSrc(this, path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level +1);
518 this->children.push_back(this->src);
524 //check if folder already exist
526 for (int i = 0; !found && i < (int)(this->children.size()); i++)
528 if (this->children[i]->GetName() == stdfileName)
532 if(!this->children[i]->Refresh(result))
538 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
539 this->children.push_back(folder);
542 cont = dir.GetNext(&fileName);
546 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
549 std::string stdfileName = crea::wx2std(fileName);
550 std::size_t fileTypePos = stdfileName.find_last_of(".");
551 std::string fileType;
552 if(fileTypePos != std::string::npos)
553 fileType = stdfileName.substr(fileTypePos);
557 //if CMakeLists, create CMakeLists
558 if(stdfileName == "CMakeLists.txt")
560 if (this->CMakeLists == NULL)
562 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
563 this->children.push_back(this->CMakeLists);
567 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
569 if(!this->CMakeLists->Refresh(result))
573 //if is an unknown file, create file
577 for (int i = 0; !found && i < (int)(this->children.size()); i++)
579 if (this->children[i]->GetName() == stdfileName)
583 if(!this->children[i]->Refresh(result))
590 //if is a code file, create modelCDMCodeFile
593 fileType == ".cxx" ||
595 fileType == ".cpp" ||
596 fileType == ".txx" ||
597 fileType == ".cmake" )
599 this->children.push_back(new modelCDMCodeFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
603 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
604 this->children.push_back(file);
609 cont = dir.GetNext(&fileName);
618 for (int i = 0; i < (int)(checked.size()); i++)
622 delete this->children[i];
623 this->children.erase(this->children.begin()+i);
624 checked.erase(checked.begin()+i);
628 this->SortChildren();
632 void modelCDMPackage::CheckStructure(std::map<std::string, bool>& properties)
635 if(this->CMakeLists != NULL)
638 std::ifstream confFile;
639 confFile.open((this->CMakeLists->GetPath()).c_str());
641 //take everything that is not commented
642 std::string fileContent;
645 std::vector<std::string> words;
646 while(confFile.is_open() && !confFile.eof())
648 std::getline(confFile,word, '\n');
651 CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok);
652 if (words.size() > 0)
655 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
656 for (int i = 0; i < (int)(words.size()); i++)
658 if(words[i].substr(0,2) == "//")
660 fileContent += words[i] + " ";
666 //check every instruction
667 std::stringstream ss(fileContent);
670 std::getline(ss,word, '(');
672 //check instruction name
673 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
676 if (words.size() > 0 && words[words.size()-1] == "SET")
678 std::getline(ss,word, ')');
680 CDMUtilities::splitter::split(words, word, " \t", CDMUtilities::splitter::no_empties);
681 if (words.size() > 1)
683 if (words[0] == "${BBTK_PACKAGE_NAME}_USE_VTK" && words[1] == "ON")
685 properties["package " + this->name + " set USE_VTK"] = true;
687 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_ITK" && words[1] == "ON")
689 properties["package " + this->name + " set USE_ITK"] = true;
691 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_GDCM" && words[1] == "ON")
693 properties["package " + this->name + " set USE_GDCM"] = true;
695 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_GDCM_VTK" && words[1] == "ON")
697 properties["package " + this->name + " set USE_GDCM_VTK"] = true;
699 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_GSMIS" && words[1] == "ON")
701 properties["package " + this->name + " set USE_GSMIS"] = true;
703 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_WXWIDGETS" && words[1] == "ON")
705 properties["package " + this->name + " set USE_WXWIDGETS"] = true;
707 else if (words[0] == "${BBTK_PACKAGE_NAME}_USE_KWWIDGETS" && words[1] == "ON")
709 properties["package " + this->name + " set USE_KWWIDGETS"] = true;
711 else if (words[0] == "USE_BOOST" && words[1] == "ON")
713 properties["package " + this->name + " set USE_BOOST"] = true;
715 else if (words[0] == "${BBTK_PACKAGE_NAME}_INCLUDE_DIRS")
717 for (int i = 1; i < (int)(words.size()); i++)
719 if(words[i].substr(0,2) == "${" || words[i].substr(0,2) == "..")
720 properties["package " + this->name + " dir " + words[i]] = true;
723 else if (words[0] == "${BBTK_PACKAGE_NAME}_LIBS")
725 for (int i = 1; i < (int)(words.size()); i++)
727 properties["package " + this->name + " lib " + words[i]] = true;
737 std::map<std::string, bool> modelCDMPackage::Get3rdPartyLibraries()
739 std::map<std::string, std::string> correspondence;
740 correspondence["${BBTK_PACKAGE_NAME}_USE_VTK"] = "VTK";
741 correspondence["${BBTK_PACKAGE_NAME}_USE_ITK"] = "ITK";
742 correspondence["${BBTK_PACKAGE_NAME}_USE_GDCM"] = "GDCM";
743 correspondence["${BBTK_PACKAGE_NAME}_USE_GDCM_VTK"] = "GDCM_VTK";
744 correspondence["${BBTK_PACKAGE_NAME}_USE_GSMIS"] = "GSMIS";
745 correspondence["${BBTK_PACKAGE_NAME}_USE_WXWIDGETS"] = "WxWidgets";
746 correspondence["${BBTK_PACKAGE_NAME}_USE_KWWIDGETS"] = "KWWidgets";
747 std::map<std::string, bool> res;
751 res["GDCM_VTK"] = false;
752 res["GSMIS"] = false;
753 res["WxWidgets"] = false;
754 res["KWWidgets"] = false;
756 if (this->HasCMakeLists())
758 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
760 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_USE_\\w+\\s+ON");
761 std::string::const_iterator start, end;
762 start = CMfile.begin();
764 boost::match_results<std::string::const_iterator> what;
765 boost::match_flag_type flags = boost::match_default;
766 while(boost::regex_search(start, end, what, expression, flags))
768 //std::cout << what[0].str() << std::endl;
769 boost::regex expression1 = boost::regex("\\$\\{BBTK_PACKAGE_NAME\\}_USE_\\w+");
770 std::string::const_iterator start1, end1;
771 start1 = what[0].first;
772 end1 = what[0].second;
773 boost::match_results<std::string::const_iterator> what1;
774 if(boost::regex_search(start1, end1, what1, expression1, flags))
776 std::string dete = what1.str();
777 CDMUtilities::normalizeStr(dete);
778 //std::cout << dete << std::endl;
779 if(correspondence.find(dete) != correspondence.end())
780 res[correspondence[dete]] = true;
782 start = what[0].second;
788 bool modelCDMPackage::Set3rdPartyLibrary(const std::string& library_name,
789 const bool& toInclude)
791 std::map<std::string, std::string> correspondence;
793 correspondence["VTK"] = "_USE_VTK";
794 correspondence["ITK"] = "_USE_ITK";
795 correspondence["GDCM"] = "_USE_GDCM";
796 correspondence["GDCM_VTK"] = "_USE_GDCM_VTK";
797 correspondence["GSMIS"] = "_USE_GSMIS";
798 correspondence["WxWidgets"] = "_USE_WXWIDGETS";
799 correspondence["KWWidgets"] = "_USE_KWWIDGETS";
801 if (correspondence.find(library_name) != correspondence.end())
803 std::string library_command = correspondence[library_name];
804 if (this->HasCMakeLists())
806 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
807 std::string resCMfile = "";
811 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+ON([\\s]|#[^\\n]*\\n)*\\)");
813 std::string::const_iterator start, end;
814 start = CMfile.begin();
816 boost::match_results<std::string::const_iterator> what;
817 boost::match_flag_type flags = boost::match_default;
818 if(boost::regex_search(start, end, what, expression, flags))
821 resCMfile += what.prefix().str();
823 resCMfile += what.str();
825 resCMfile += "#" + what.str();
826 resCMfile += what.suffix().str();
828 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
832 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+OFF([\\s]|#[^\\n]*\\n)*\\)");
834 start = CMfile.begin();
836 if(boost::regex_search(start, end, what, expression, flags))
839 resCMfile += what.prefix().str();
842 std::string dete = what.str();
843 int pos = dete.rfind("OFF");
844 dete.replace(pos, 3, "ON");
848 resCMfile += what.str();
849 resCMfile += what.suffix().str();
851 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
855 boost::regex expression("^\\h*#\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+ON([\\s]|#[^\\n]*\\n)*\\)");
856 if(boost::regex_search(start, end, what, expression, flags))
859 resCMfile += what.prefix().str();
862 std::string dete = what[0].str();
863 for (int i = 0; i < dete.size(); ++i) {
865 resCMfile.push_back(dete[i]);
868 resCMfile += dete.substr(i+1);
874 resCMfile += what.str();
876 resCMfile += what.suffix().str();
877 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
881 boost::regex expression("^\\h*#\\h*UNCOMMENT EACH LIBRARY NEEDED \\(WILL BE FOUND AND USED AUTOMATICALLY\\)[^\\n]*\\n");
882 if(boost::regex_search(start, end, what, expression, flags))
885 resCMfile += what.prefix().str();
886 resCMfile += what.str();
889 resCMfile += "SET(${BBTK_PACKAGE_NAME}"+ library_command +" ON)\n";
891 resCMfile += what.suffix().str();
892 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
897 } catch (boost::bad_expression& e) {
898 std::cout << "bad regex: " << e.what() << std::endl;
906 std::map<std::string, bool> modelCDMPackage::GetCustomLibraries()
908 std::map<std::string, bool> res;
909 std::map<std::string, bool> res1;
911 std::map<std::string, std::string> correspondence;
912 std::vector<modelCDMLibrary*> libraries;
913 modelCDMIProjectTreeNode* p = this;
914 while(p != NULL && dynamic_cast<modelCDMProject*>(p) == NULL)
917 if(p != NULL && dynamic_cast<modelCDMProject*>(p)->GetLib() != NULL)
918 libraries = dynamic_cast<modelCDMProject*>(p)->GetLib()->GetLibraries();
920 for (int i = 0; i < libraries.size(); ++i)
922 correspondence[libraries[i]->GetName()] = libraries[i]->GetNameLibrary();
923 res[libraries[i]->GetNameLibrary()] = false;
924 res1[libraries[i]->GetNameLibrary()] = false;
927 if (this->HasCMakeLists())
929 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
931 //find included libraries
932 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
933 std::string::const_iterator start, end;
934 start = CMfile.begin();
936 boost::match_results<std::string::const_iterator> what;
937 boost::match_flag_type flags = boost::match_default;
938 if(boost::regex_search(start, end, what, expression, flags))
941 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS");
942 std::string::const_iterator start1, end1;
943 start1 = what[0].first;
944 end1 = what[0].second;
945 boost::match_results<std::string::const_iterator> what1;
946 if(boost::regex_search(start1, end1, what1, expression, flags))
948 expression = boost::regex("^\\h*[\\w\\d]+");
949 std::string::const_iterator start2, end2;
950 start2 = what1[0].second;
951 end2 = what[0].second;
952 boost::match_results<std::string::const_iterator> what2;
953 while(boost::regex_search(start2, end2, what2, expression, flags))
955 std::string dete = what2.str();
956 CDMUtilities::normalizeStr(dete);
957 //std::cout << "detectado lib: " << dete << std::endl;
958 if(res1.find(dete) != res1.end())
961 start2 = what2[0].second;
966 //find included folders
967 //std::cout << "searching..." << std::endl;
968 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)*\\)");
969 start = CMfile.begin();
971 if(boost::regex_search(start, end, what, expression, flags))
973 //std::cout << what.str() << std::endl;
974 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_INCLUDE_DIRS");
975 std::string::const_iterator start1, end1;
976 start1 = what[0].first;
977 end1 = what[0].second;
978 boost::match_results<std::string::const_iterator> what1;
979 if(boost::regex_search(start1, end1, what1, expression, flags))
981 //std::cout << what1.str() << std::endl;
982 expression = boost::regex("^\\h*\\.\\.\\/lib\\/([\\w\\d])+");
983 std::string::const_iterator start2, end2;
984 start2 = what1[0].second;
985 end2 = what[0].second;
986 boost::match_results<std::string::const_iterator> what2;
987 while(boost::regex_search(start2, end2, what2, expression, flags))
989 std::string dete = what2.str();
990 CDMUtilities::normalizeStr(dete);
991 //std::cout << "detectado dir: " << dete.substr(7) << std::endl;
992 if(correspondence.find(dete.substr(7)) != correspondence.end())
993 res[correspondence[dete.substr(7)]] = res1[correspondence[dete.substr(7)]];
995 start2 = what2[0].second;
1004 bool modelCDMPackage::SetCustomLibrary(const std::string& library_name,
1005 const bool& toInclude)
1007 std::map<std::string, std::string> correspondence;
1009 std::vector<modelCDMLibrary*> libraries;
1010 modelCDMIProjectTreeNode* p = this;
1011 while(p != NULL && dynamic_cast<modelCDMProject*>(p) == NULL)
1014 if(p != NULL && dynamic_cast<modelCDMProject*>(p)->GetLib() != NULL)
1015 libraries = dynamic_cast<modelCDMProject*>(p)->GetLib()->GetLibraries();
1017 for (int i = 0; i < libraries.size(); ++i)
1019 correspondence[libraries[i]->GetNameLibrary()] = libraries[i]->GetName();
1022 if (correspondence.find(library_name) != correspondence.end())
1024 if (this->HasCMakeLists())
1026 std::string resCMfile = "";
1027 std::string CMfile = CDMUtilities::readFile(this->CMakeLists->GetPath().c_str());
1030 //find included libraries
1031 //std::cout << "searching..." << CMfile << std::endl;
1032 boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS(([\\s]|#[^\\n]*\\n)+([\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
1033 std::string::const_iterator start, end;
1034 start = CMfile.begin();
1036 boost::match_results<std::string::const_iterator> what;
1037 boost::match_flag_type flags = boost::match_default;
1038 if(boost::regex_search(start, end, what, expression, flags))
1040 //std::cout << what.str() << std::endl;
1041 resCMfile += what.prefix().str();
1042 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_LIBS");
1043 std::string::const_iterator start1, end1;
1044 start1 = what[0].first;
1045 end1 = what[0].second;
1046 boost::match_results<std::string::const_iterator> what1;
1047 if(boost::regex_search(start1, end1, what1, expression, flags))
1049 resCMfile += what1.prefix().str() + what1.str();
1050 //check if already exists
1051 expression = boost::regex("^\\h*"+library_name);
1052 std::string::const_iterator start2, end2;
1053 start2 = what1[0].second;
1054 end2 = what[0].second;
1055 boost::match_results<std::string::const_iterator> what2, temp2;
1056 while(boost::regex_search(start2, end2, what2, expression, flags))
1058 resCMfile += what2.prefix().str();
1064 resCMfile += what2.str();
1066 start2 = what2[0].second;
1069 resCMfile += temp2.suffix().str();
1070 //check if is commented
1073 expression = boost::regex("^\\h*#+\\h*"+library_name);
1074 start2 = what1[0].second;
1075 end2 = what[0].second;
1076 while(boost::regex_search(start2, end2, what2, expression, flags))
1079 resCMfile += what2.prefix().str();
1082 std::string dete = what2[0].str();
1083 for (int i = 0; i < dete.size(); ++i) {
1085 resCMfile.push_back(dete[i]);
1089 start2 = what2[0].second;
1092 resCMfile += temp2.suffix().str();
1093 //add at the beggining of instruction
1097 resCMfile += "\n" + library_name;
1098 resCMfile += what1.suffix().str();
1102 resCMfile += what.suffix().str();
1107 //find included folders
1113 //std::cout << "searching..." << CMfile << std::endl;
1114 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_INCLUDE_DIRS(([\\s]|#[^\\n]*\\n)+([\\.\\/\\$\\{\\}\\w\\d]+|\"(?:[^\"\\\\]|\\\\.)*\"))*([\\s]|#[^\\n]*\\n)*\\)");
1115 start = CMfile.begin();
1117 if(boost::regex_search(start, end, what, expression, flags))
1119 resCMfile += what.prefix().str();
1120 //std::cout << what.str() << std::endl;
1121 expression = boost::regex("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}_INCLUDE_DIRS");
1122 std::string::const_iterator start1, end1;
1123 start1 = what[0].first;
1124 end1 = what[0].second;
1125 boost::match_results<std::string::const_iterator> what1;
1126 if(boost::regex_search(start1, end1, what1, expression, flags))
1128 resCMfile += what1.prefix().str() + what1.str();
1129 //std::cout << what1.str() << std::endl;
1130 //search if dir is already included
1131 expression = boost::regex("^\\h*\\.\\.\\/lib\\/"+correspondence[library_name]);
1132 std::string::const_iterator start2, end2;
1133 start2 = what1[0].second;
1134 end2 = what[0].second;
1135 boost::match_results<std::string::const_iterator> what2, temp2;
1136 while(boost::regex_search(start2, end2, what2, expression, flags))
1139 resCMfile += what2.prefix().str();
1142 resCMfile += what2.str();
1144 start2 = what2[0].second;
1147 resCMfile += temp2.suffix().str();
1148 //search if dir is commented
1151 expression = boost::regex("^\\h*#+\\h*\\.\\.\\/lib\\/"+correspondence[library_name]);
1152 start2 = what1[0].second;
1153 end2 = what[0].second;
1154 while(boost::regex_search(start2, end2, what2, expression, flags))
1157 resCMfile += what2.prefix().str();
1160 std::string dete = what2[0].str();
1161 for (int i = 0; i < dete.size(); ++i) {
1163 resCMfile.push_back(dete[i]);
1167 start2 = what2[0].second;
1170 resCMfile += temp2.suffix().str();
1171 //add at the beggining of instruction
1175 resCMfile += "\n../lib/" + correspondence[library_name];
1176 resCMfile += what1.suffix().str();
1180 resCMfile += what.suffix().str();
1185 return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);