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: 13/11/2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "modelCDMProject.h"
44 #include "CDMUtilities.h"
48 modelCDMProject::modelCDMProject()
50 std::cout << "in constructor1" << std::endl;
53 this->CMakeLists = NULL;
56 modelCDMProject::modelCDMProject(
57 modelCDMIProjectTreeNode* parent,
58 const std::string& path,
59 const std::string& name,
60 const std::string& buildPath
63 std::cout << "creating project: " + name + " in " + path + "\n";
64 this->parent = parent;
65 this->path = CDMUtilities::fixPath(path);
67 std::string pathFixed(CDMUtilities::fixPath(path));
69 std::string pathMakeLists = pathFixed + CDMUtilities::SLASH + "CMakeLists.txt";
71 std::ifstream confFile;
72 confFile.open((pathMakeLists).c_str());
75 while(confFile.is_open() && !confFile.eof())
77 //std::cout << "leyendo " << word << std::endl;
79 std::getline(confFile,word,'(');
80 std::vector<std::string> wordBits;
81 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
83 if(wordBits[wordBits.size()-1] == "PROJECT")
85 std::getline(confFile,word,')');
86 std::vector<std::string> nameBits;
87 CDMUtilities::splitter::split(nameBits, word, " ", CDMUtilities::splitter::no_empties);
89 this->name = this->nameProject = "";
90 for (int i = 0; i < (int)(nameBits.size()); i++)
94 this->name += nameBits[i];
96 this->nameProject = this->name;
101 if(wordBits[wordBits.size()-1] == "SET")
103 //get project version
104 std::getline(confFile,word,')');
105 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
106 if(wordBits[0] == "PROJECT_MAJOR_VERSION")
108 version = wordBits[1];
110 if(wordBits[0] == "PROJECT_MINOR_VERSION")
112 version += "." + wordBits[1];
114 if(wordBits[0] == "PROJECT_BUILD_VERSION")
116 version += "." + wordBits[1];
119 //get project versionDate
120 if(wordBits[0] == "PROJECT_VERSION_DATE")
122 std::vector<std::string> versionBits;
123 CDMUtilities::splitter::split(versionBits, wordBits[1], "\"", CDMUtilities::splitter::no_empties);
124 versionDate = versionBits[0];
126 //get project buildPath
130 this->buildPath = buildPath;
134 this->buildPath = this->path + "Bin";
140 this->type = wxDIR_DIRS;
143 this->children.clear();
146 this->packages.clear();
150 wxDir dir(crea::std2wx((pathFixed).c_str()));
154 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
157 std::string stdfileName = crea::wx2std(fileName);
159 //if appli, create appli
160 if(stdfileName == "appli")
162 this->appli = new modelCDMAppli(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
163 this->children.push_back(this->appli);
166 else if(stdfileName == "lib")
168 this->lib = new modelCDMLib(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
169 this->children.push_back(this->lib);
171 //if package , create package
172 else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
174 modelCDMPackage* package = new modelCDMPackage(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
175 this->packages.push_back(package);
176 this->children.push_back(package);
178 //if is an unknown folder, create folder
181 this->children.push_back(new modelCDMFolder(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
184 cont = dir.GetNext(&fileName);
187 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
190 std::string stdfileName = crea::wx2std(fileName);
192 //if CMakeLists, create CMakeLists
193 if(stdfileName == "CMakeLists.txt")
195 this->CMakeLists = new modelCDMCMakeListsFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
196 this->children.push_back(this->CMakeLists);
200 this->children.push_back(new modelCDMFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
202 //if is an unknown file, create file
203 cont = dir.GetNext(&fileName);
207 this->SortChildren();
208 std::sort(this->packages.begin(), this->packages.end(), CompareNodeItem);
212 modelCDMProject::~modelCDMProject()
216 const std::string& modelCDMProject::GetNameProject() const
218 return this->nameProject;
221 const std::string& modelCDMProject::GetVersion() const
223 return this->version;
226 const std::string& modelCDMProject::GetVersionDate() const
228 return this->versionDate;
231 const std::string& modelCDMProject::GetBuildPath() const
233 return this->buildPath;
236 const std::vector<modelCDMPackage*>& modelCDMProject::GetPackages() const
238 return this->packages;
241 modelCDMAppli* modelCDMProject::GetAppli() const
246 modelCDMLib* modelCDMProject::GetLib() const
251 std::string modelCDMProject::GetBuildInstruction() const
253 std::string makeComm = "make -C \"" + this->buildPath + "\""; /*> \"" + this->buildPath + CDMUtilities::SLASH + "building.log\" 2>&1";*/
257 bool modelCDMProject::SetVersion(const std::string& version, std::string*& result)
260 std::vector<std::string> vers;
261 CDMUtilities::splitter::split(vers, version, " .", CDMUtilities::splitter::no_empties);
263 time_t now = time(0);
267 localtime_s(<m, &now);
269 ltm = *(localtime(&now));
272 std::stringstream date;
273 date << ltm.tm_mday << "/" << 1 + ltm.tm_mon << "/" << 1900 + ltm.tm_year;
275 //set name of library in CMakeLists inside copied folder
277 std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
280 result = new std::string("CMakeLists.txt file failed to open.");
283 std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
286 result = new std::string("CMakeLists.txt.tmp file failed to open.");
289 while (getline(in, line))
291 if(line.find("SET(PROJECT_MAJOR_VERSION") != std::string::npos)
292 line = "SET(PROJECT_MAJOR_VERSION " + vers[0] + ")";
293 else if(line.find("SET(PROJECT_MINOR_VERSION") != std::string::npos)
294 line = "SET(PROJECT_MINOR_VERSION " + vers[1] + ")";
295 else if(line.find("SET(PROJECT_BUILD_VERSION") != std::string::npos)
296 line = "SET(PROJECT_BUILD_VERSION " + vers[2] + ")";
297 else if(line.find("SET(PROJECT_VERSION_DATE") != std::string::npos)
298 line = "SET(PROJECT_VERSION_DATE \"" + date.str() + "\")";
299 out << line << std::endl;
303 //delete old file and rename new file
305 std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
307 std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
309 if(system(renameCommand.c_str()))
311 result = new std::string("An error occurred while running '" + renameCommand + "'.");
315 this->version = vers[0] + "." + vers[1] + "." + vers[2];
316 this->versionDate = date.str();
320 bool modelCDMProject::SetBuildPath(const std::string& path, std::string*& result)
324 result = new std::string("The path cannot be empty");
327 if(path == this->path)
329 result = new std::string("The path cannot be same as the project sources");
332 this->buildPath = path;
336 modelCDMIProjectTreeNode* modelCDMProject::CreatePackage(
337 const std::string& name,
338 std::string*& result,
339 const std::string& authors,
340 const std::string& authorsEmail,
341 const std::string& description,
342 const std::string& version
345 //fixing input parameters
346 std::vector<std::string> words;
348 CDMUtilities::splitter::split(words,name," '/\"\\,.",CDMUtilities::splitter::no_empties);
349 std::string nameFixed = "";
350 for (int i = 0; i < (int)(words.size()); i++)
352 nameFixed += words[i];
356 CDMUtilities::splitter::split(words,authors," '/\"\\,.",CDMUtilities::splitter::no_empties);
357 std::string authorFixed;
358 for (int i = 0; i < (int)(words.size()); i++)
360 authorFixed += words[i];
364 std::string descriptionFixed;
365 CDMUtilities::splitter::split(words,authorsEmail," '/\"\\,",CDMUtilities::splitter::no_empties);
366 for (int i = 0; i < (int)(words.size()); i++)
368 descriptionFixed += words[i] + "/";
371 CDMUtilities::splitter::split(words,description," '\"",CDMUtilities::splitter::no_empties);
372 for (int i = 0; i < (int)(words.size()); i++)
374 descriptionFixed += "_" + words[i];
377 //call project to create package : use bbCreatePackage <path> <name> [author] [description]
378 std::string creationCommand = "bbCreatePackage \"" + this->path + "\" \"" + nameFixed + "\" \"" + authorFixed + "\" \"" + descriptionFixed + "\"";
379 //TODO: bbCreatePackage script always returning 0. It should return 1 or greater if any error
380 bool resultCommand = 0 != system(creationCommand.c_str());
382 resultCommand = false;
386 result = new std::string("An error occurred while running '" + creationCommand + "'.");
390 //add library to project CMakeLists
391 std::fstream out1((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str(), std::fstream::in | std::fstream::out | std::fstream::app);
394 out1 << "ADD_SUBDIRECTORY(bbtk_" << nameFixed << "_PKG)" << std::endl;
398 //add library to model
399 modelCDMPackage* package = new modelCDMPackage(this, this->path + CDMUtilities::SLASH + "bbtk_" + nameFixed + "_PKG", "bbtk_" + nameFixed + "_PKG", this->level + 1);
400 this->packages.push_back(package);
401 this->children.push_back(package);
403 //TODO: set package version
405 this->SortChildren();
407 result = new std::string(this->path + CDMUtilities::SLASH + name);
411 modelCDMIProjectTreeNode* modelCDMProject::CreateLibrary(
412 const std::string& name,
413 std::string*& result,
414 const std::string& path
417 if(this->lib != NULL)
419 return this->lib->CreateLibrary(name, result);
421 result = new std::string("there is no lib folder in this project.");
425 modelCDMIProjectTreeNode* modelCDMProject::CreateApplication(
426 const std::string& name,
428 std::string*& result,
429 const std::string& path
432 if(this->appli != NULL)
434 return this->appli->CreateApplication(name, type, result);
436 result = new std::string("there is no appli folder in this project.");
440 modelCDMIProjectTreeNode* modelCDMProject::CreateBlackBox(
441 const std::string& name,
442 const std::string& package,
443 const std::string& authors,
444 const std::string& authorsEmail,
445 const std::string& categories,
446 const std::string& description
449 //TODO: implement method
453 bool modelCDMProject::OpenCMakeListsFile(std::string*& result)
455 if (!CDMUtilities::openTextEditor(this->CMakeLists->GetPath()))
459 result = new std::string("Couldn't open CMakeLists file.");
464 const bool modelCDMProject::Refresh(std::string*& result)
466 std::cout << "refreshing project" << std::endl;
467 //open makelists file
468 std::string pathMakeLists = this->path + CDMUtilities::SLASH + "CMakeLists.txt";
470 std::ifstream confFile;
471 confFile.open((pathMakeLists).c_str());
474 while(confFile.is_open() && !confFile.eof())
476 //std::cout << "leyendo " << word << std::endl;
478 std::getline(confFile,word,'(');
479 std::vector<std::string> wordBits;
480 CDMUtilities::splitter::split(wordBits,word," (\n",CDMUtilities::splitter::no_empties);
482 if(wordBits[wordBits.size()-1] == "PROJECT")
484 std::getline(confFile,word,')');
485 std::vector<std::string> nameBits;
486 CDMUtilities::splitter::split(nameBits, word, " ", CDMUtilities::splitter::no_empties);
488 this->name = this->nameProject = "";
489 for (int i = 0; i < (int)(nameBits.size()); i++)
493 this->name += nameBits[i];
495 this->nameProject = this->name;
500 if(wordBits[wordBits.size()-1] == "SET")
502 //get project version
503 std::getline(confFile,word,')');
504 CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
505 if(wordBits[0] == "PROJECT_MAJOR_VERSION")
507 version = wordBits[1];
509 if(wordBits[0] == "PROJECT_MINOR_VERSION")
511 version += "." + wordBits[1];
513 if(wordBits[0] == "PROJECT_BUILD_VERSION")
515 version += "." + wordBits[1];
518 //get project versionDate
519 if(wordBits[0] == "PROJECT_VERSION_DATE")
521 std::vector<std::string> versionBits;
522 CDMUtilities::splitter::split(versionBits, wordBits[1], "\"", CDMUtilities::splitter::no_empties);
523 versionDate = versionBits[0];
529 this->type = wxDIR_DIRS;
532 std::vector<bool> checked(this->children.size(), false);
533 std::vector<bool> checkedPackages(this->packages.size(), false);
536 wxDir dir(crea::std2wx((this->path).c_str()));
540 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
543 std::string stdfileName = crea::wx2std(fileName);
545 //if appli, create appli
546 if(stdfileName == "appli")
548 if (this->appli == NULL)
550 this->appli = new modelCDMAppli(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
551 this->children.push_back(this->appli);
555 int pos = std::find(this->children.begin(), this->children.end(), this->appli) - this->children.begin();
557 if(!this->appli->Refresh(result))
562 else if(stdfileName == "lib")
564 if (this->lib == NULL)
566 this->lib = new modelCDMLib(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
567 this->children.push_back(this->lib);
571 int pos = std::find(this->children.begin(), this->children.end(), this->lib) - this->children.begin();
573 if(!this->lib->Refresh(result))
578 //if package , create package
579 else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG")
582 for (int i = 0; !found && i < (int)(this->packages.size()); i++)
584 if (this->packages[i]->GetName() == stdfileName)
587 int pos = std::find(this->children.begin(), this->children.end(), this->packages[i]) - this->children.begin();
589 checkedPackages[i] = true;
590 if(!this->packages[i]->Refresh(result))
596 modelCDMPackage* package = new modelCDMPackage(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
597 this->packages.push_back(package);
598 this->children.push_back(package);
602 //if is an unknown folder, create folder
606 for (int i = 0; !found && i < (int)(this->children.size()); i++)
608 if (this->children[i]->GetName() == stdfileName)
612 if(!this->children[i]->Refresh(result))
619 modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
620 this->children.push_back(folder);
624 cont = dir.GetNext(&fileName);
627 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
630 std::string stdfileName = crea::wx2std(fileName);
632 //if CMakeLists, create CMakeLists
633 if(stdfileName == "CMakeLists.txt")
635 if (this->CMakeLists == NULL)
637 this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
638 this->children.push_back(this->CMakeLists);
642 int pos = std::find(this->children.begin(), this->children.end(), this->CMakeLists) - this->children.begin();
644 if(!this->CMakeLists->Refresh(result))
648 //if is an unknown file, create file
652 for (int i = 0; !found && i < (int)(this->children.size()); i++)
654 if (this->children[i]->GetName() == stdfileName)
658 if(!this->children[i]->Refresh(result))
665 modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
666 this->children.push_back(file);
670 cont = dir.GetNext(&fileName);
674 for (int i = 0; i < (int)(checkedPackages.size()); i++)
676 if(!checkedPackages[i])
678 this->packages.erase(this->packages.begin()+i);
679 checkedPackages.erase(checkedPackages.begin()+i);
683 for (int i = 0; i < (int)(checked.size()); i++)
687 delete this->children[i];
688 this->children.erase(this->children.begin()+i);
689 checked.erase(checked.begin()+i);
694 this->SortChildren();
695 std::sort(this->packages.begin(), this->packages.end(), CompareNodeItem);
699 bool modelCDMProject::ConfigureBuild(std::string*& result)
701 //TODO: adjust for windows and mac
704 if(0 == system("cmake-gui"))
708 result = new std::string("There was an error opening cmake-gui. Please make sure it's installed and that cmake's bin folder is in the system path.");
716 wxDir dir(crea::std2wx((this->buildPath).c_str()));
718 //if folder doesn't exist then create it
721 //create command line to create folder
722 std::string createComm = "mkdir \"" + this->buildPath + "\"";
723 //execute creation command
724 if (system(createComm.c_str()))
726 //if there was an error then report it
727 result = new std::string("There was an error creating the build path: \"" + this->buildPath + "\"");
731 //create command line to execute ccmake
732 //TODO:: adjust for different Linux distributions
733 std::string confComm = "gnome-terminal --tab --working-directory=\"" + this->buildPath + "\" -e \"ccmake '" + this->path + "'\"";
735 if(CDMUtilities::openTerminal(confComm))
737 //if there was an error then report it
738 result = new std::string("There was an error opening the configuration tool in the desired place.");
745 bool modelCDMProject::Build(std::string*& result, const std::string& line)
747 //TODO: adjust for windows and mac
750 //\\..\\IDE\\VCExpress.exe \"" + this->buildPath + CDMUtilities::SLASH + this->nameProject + ".sln\"
751 // std::string command = "\"" + std::string(getenv("VS90COMNTOOLS")) + "..\\IDE\\VCExpress.exe\" \"" + this->buildPath + CDMUtilities::SLASH + this->nameProject + ".sln\" &";
752 std::string command = "\"\"%VS90COMNTOOLS%..\\IDE\\VCExpress.exe\" \"" + this->buildPath + CDMUtilities::SLASH + this->nameProject + ".sln\" &\"";
753 command = "start cmd.exe /k " + command + " &";
754 if(0 == system(command.c_str()))
758 result = new std::string("An error has happened running: \"" + command + "\". Please make sure to have visual c++ express installed and to have the VS90COMNTOOLS environment variable set.");
766 wxDir dir(crea::std2wx((this->buildPath).c_str()));
768 //if binary folder can't be opened then return false
771 result = new std::string("The build path could not be opened. Make sure to configure the project before compiling it");
774 //create make command
775 std::string makeComm = "gnome-terminal -e \"bash -c \\\"";
776 for (int i = 0; i < line.size(); i++)
780 makeComm+="\\\\\\\"";
782 else if(line[i] == '\\')
784 makeComm+="\\\\\\\\";
788 makeComm.push_back(line[i]);
791 makeComm += "; echo -e '\\a'; bash";
792 makeComm += "\\\"\"";
794 std::cout << "executing '" << makeComm << "'" << std::endl;
795 //execute make command
796 if(system(makeComm.c_str()))
798 //if there was an error then report it
799 result = new std::string("There was an error compiling the project, please check the \"building.log\" file located in the build folder to read more about the problem.");
806 bool modelCDMProject::Connect(std::string*& result, const std::string& folder)
808 //TODO: adjust for mac
812 wxDir dir(crea::std2wx(folder));
814 //if binary folder can't be opened then return false
817 result = new std::string("The path could not be opened. Make sure the folder exists and contains a bbtkPackage file.");
820 //create plug command
821 std::string plugComm = "bbPlugPackage \"" + folder + "\"";
822 std::cout << "executing '" << plugComm << "'" << std::endl;
823 //execute plug command
824 if(system(std::string("start cmd.exe /k \"" + plugComm + "\"").c_str()))
826 //if there was an error then report it
827 result = new std::string("There was an error plugging the packages of the project, please check the console to read more about the problem.");
835 wxDir dir(crea::std2wx(folder));
837 //if binary folder can't be opened then return false
840 result = new std::string("The path could not be opened. Make sure the folder exists and contains a bbtkPackage file.");
843 //create plug command
844 std::string plugComm = "bbPlugPackage \"" + this->buildPath + "\"";
846 std::string Comm = "gnome-terminal -e \"bash -c \\\"";
847 for (int i = 0; i < plugComm.size(); i++)
849 if(plugComm[i] == '"')
853 else if(plugComm[i] == '\\')
859 Comm.push_back(plugComm[i]);
862 Comm += "; echo -e '\\a'; bash";
866 std::cout << "executing '" << Comm << "'" << std::endl;
867 //execute plug command
868 if(system(Comm.c_str()))
870 //if there was an error then report it
871 result = new std::string("There was an error plugging the packages of the project, please check the console to read more about the problem.");
878 void modelCDMProject::CheckStructure(std::map<std::string, bool>& properties)
881 if(this->CMakeLists != NULL)
883 //set properties parameters based on model
884 properties["project add appli"] = this->appli != NULL;
885 properties["project add lib"] = this->lib != NULL;
886 for (int i = 0; i < (int)(this->packages.size()); i++)
887 properties["project add " + packages[i]->GetName()] = false;
890 std::ifstream confFile;
891 confFile.open((this->CMakeLists->GetPath()).c_str());
893 //take everything that is not commented
894 std::string fileContent;
897 std::vector<std::string> words;
898 while(confFile.is_open() && !confFile.eof())
900 std::getline(confFile,word, '\n');
903 CDMUtilities::splitter::split(words, word, "#", CDMUtilities::splitter::empties_ok);
904 if (words.size() > 0)
907 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
908 for (int i = 0; i < (int)(words.size()); i++)
910 if(words[i].substr(0,2) == "//")
912 fileContent += words[i] + " ";
919 //check every instruction
920 std::stringstream ss(fileContent);
923 std::getline(ss,word, '(');
925 //check instruction name
926 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
929 if (words.size() > 0 && words[words.size()-1] == "SET")
931 std::getline(ss,word, ')');
933 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
934 if (words.size() > 1)
936 if (words[0] == "USE_CREA" && words[1] == "ON")
938 properties["project set USE_CREA"] = true;
940 else if (words[0] == "USE_GDCM" && words[1] == "ON")
942 properties["project set USE_GDCM"] = true;
944 else if (words[0] == "USE_GDCM_VTK" && words[1] == "ON")
946 properties["project set USE_GDCM_VTK"] = true;
948 else if (words[0] == "USE_GDCM2" && words[1] == "ON")
950 properties["project set USE_GDCM2"] = true;
952 else if (words[0] == "USE_WXWIDGETS" && words[1] == "ON")
954 properties["project set USE_WXWIDGETS"] = true;
956 else if (words[0] == "USE_KWWIDGETS" && words[1] == "ON")
958 properties["project set USE_KWWIDGETS"] = true;
960 else if (words[0] == "USE_VTK" && words[1] == "ON")
962 properties["project set USE_VTK"] = true;
964 else if (words[0] == "USE_ITK" && words[1] == "ON")
966 properties["project set USE_ITK"] = true;
968 else if (words[0] == "USE_BOOST" && words[1] == "ON")
970 properties["project set USE_BOOST"] = true;
975 else if (words.size() > 0 && words[words.size()-1] == "ADD_SUBDIRECTORY")
977 std::getline(ss,word, ')');
978 //std::cout << word << std::endl;
979 CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::no_empties);
981 if (words.size() > 0)
983 if(words[0] == "appli")
985 properties["project add "+words[0]] = this->appli != NULL;
987 else if(words[0] == "lib")
989 properties["project add "+words[0]] = this->lib != NULL;
993 properties["project add "+words[0]] = true;
1001 //check appli's structure
1002 this->appli->CheckStructure(properties);
1003 //check lib's structure
1004 this->lib->CheckStructure(properties);
1005 //check packages' structure
1006 for (int i = 0; i < (int)(this->packages.size()); i++)
1008 properties["package " + this->packages[i]->GetName()] = true;
1009 this->packages[i]->CheckStructure(properties);
1013 bool modelCDMProject::IsPackageIncluded(const std::string& package_name)
1015 if(this->HasCMakeLists())
1017 std::ifstream CMFile(this->CMakeLists->GetPath().c_str());
1018 if (CMFile.is_open())
1021 while(!CMFile.eof())
1023 std::getline(CMFile, line);
1028 std::vector<std::string> lineSeg;
1029 CDMUtilities::splitter::split(lineSeg,line,"()",CDMUtilities::splitter::no_empties);
1030 if(lineSeg.size() > 0 && lineSeg[0] == "ADD_SUBDIRECTORY" && lineSeg[1] == package_name)
1043 bool modelCDMProject::SetPackageInclude(const std::string& package_name, const bool& toInclude)
1045 if (this->HasCMakeLists())
1047 std::ifstream CMFile(this->CMakeLists->GetPath().c_str());
1048 if (CMFile.is_open())
1050 std::stringstream outs;
1053 while(!CMFile.eof())
1055 std::getline(CMFile, line);
1061 std::vector<std::string> segs;
1062 CDMUtilities::splitter::split(segs, line, " ", CDMUtilities::splitter::no_empties);
1064 if(segs.size() > 0 && segs[0][0] == '#')
1068 CDMUtilities::splitter::split(segs, line, " #()", CDMUtilities::splitter::no_empties);
1069 if (segs.size() > 1 && segs[0] == "ADD_SUBDIRECTORY" && segs[1] == package_name)
1072 outs << "ADD_SUBDIRECTORY(" << package_name << ")\n";
1075 outs << line << "\n";
1079 outs << line << "\n";
1085 if (segs.size() > 0 && !toInclude)
1087 CDMUtilities::splitter::split(segs, line, " ()", CDMUtilities::splitter::no_empties);
1088 if (segs.size() > 1 && segs[0] == "ADD_SUBDIRECTORY" && segs[1] == package_name)
1090 outs << "#" << line << "\n";
1094 outs << line << "\n";
1099 CDMUtilities::splitter::split(segs, line, " ()", CDMUtilities::splitter::no_empties);
1100 if (segs.size() > 1 && segs[0] == "ADD_SUBDIRECTORY" && segs[1] == package_name)
1104 outs << line << "\n";
1116 if(!found && toInclude)
1117 outs << "ADD_SUBDIRECTORY(" << package_name << ")\n";
1119 std::ofstream CMFileOut(this->CMakeLists->GetPath().c_str());
1120 if (CMFileOut.is_open())
1122 CMFileOut << outs.rdbuf();