X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FmodelCDMProject.cpp;h=08cafc74f530d554663117f56d05106ee6c34d43;hb=38fb78e3930c8ba01021536630624e4b0b03dd87;hp=a021a1025a7424a6c6e1149de3a21ff9f5e54a64;hpb=e6d99bba438e086b10239a42492532ff194edb88;p=crea.git diff --git a/lib/creaDevManagerLib/modelCDMProject.cpp b/lib/creaDevManagerLib/modelCDMProject.cpp index a021a10..08cafc7 100644 --- a/lib/creaDevManagerLib/modelCDMProject.cpp +++ b/lib/creaDevManagerLib/modelCDMProject.cpp @@ -387,6 +387,14 @@ modelCDMIProjectTreeNode* modelCDMProject::CreatePackage( return NULL; } + //add library to project CMakeLists + std::fstream out1((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str(), std::fstream::in | std::fstream::out | std::fstream::app); + if (out1.is_open()) + { + out1 << "ADD_SUBDIRECTORY(bbtk_" << nameFixed << "_PKG)" << std::endl; + out1.close(); + } + //add library to model modelCDMPackage* package = new modelCDMPackage(this, this->path + CDMUtilities::SLASH + "bbtk_" + nameFixed + "_PKG", "bbtk_" + nameFixed + "_PKG", this->level + 1); this->packages.push_back(package); @@ -833,13 +841,34 @@ bool modelCDMProject::Connect(std::string*& result, const std::string& folder) return false; } //create plug command - std::string plugComm = "bbPlugPackage \"" + this->buildPath + "\" > \"" + this->buildPath + CDMUtilities::SLASH + "plugging.log\" 2>&1"; - std::cout << "executing '" << plugComm << "'" << std::endl; + std::string plugComm = "bbPlugPackage \"" + this->buildPath + "\""; + + std::string Comm = "gnome-terminal -e \"bash -c \\\""; + for (int i = 0; i < plugComm.size(); i++) + { + if(plugComm[i] == '"') + { + Comm+="\\\\\\\""; + } + else if(plugComm[i] == '\\') + { + Comm+="\\\\\\\\"; + } + else + { + Comm.push_back(plugComm[i]); + } + } + Comm += "; echo -e '\\a'; bash"; + Comm += "\\\"\""; + + + std::cout << "executing '" << Comm << "'" << std::endl; //execute plug command - if(system(plugComm.c_str())) + if(system(Comm.c_str())) { //if there was an error then report it - result = new std::string("There was an error plugging the packages of the project, please check the plugging.log in the build folder file to read more about the problem."); + result = new std::string("There was an error plugging the packages of the project, please check the console to read more about the problem."); return false; } #endif @@ -980,3 +1009,96 @@ void modelCDMProject::CheckStructure(std::map& properties) this->packages[i]->CheckStructure(properties); } } + +bool modelCDMProject::IsPackageIncluded(const std::string& package_name) +{ + if (this->HasCMakeLists()) + { + CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str()); + for (int i = 0; i < cmlFile.size(); ++i) + { + if (cmlFile[i].first=="command" && cmlFile[i].second[0] == "ADD_SUBDIRECTORY") + { + int pos = 1; + while (pos < cmlFile[i].second.size()) + { + if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != '#') + { + if (package_name == cmlFile[i].second[pos]) + return true; + break; + } + pos++; + } + } + } + } + return false; + +} + +bool modelCDMProject::SetPackageInclude(const std::string& package_name, const bool& toInclude) +{ + if (this->HasCMakeLists()) + { + CDMUtilities::CMLFile cmlFile = CDMUtilities::readCMLFile(this->CMakeLists->GetPath().c_str()); + + bool found = false; + + for (int i = 0; i < cmlFile.size(); ++i) + { + if(toInclude && cmlFile[i].first == "comment") + { + std::vector segments; + std::string line = cmlFile[i].second[0]; + while(line[0] == '#') + line.erase(0,1); + + CDMUtilities::splitter::split(segments, line, " ()", CDMUtilities::splitter::no_empties); + if (segments.size() > 1 && segments[0] == "ADD_SUBDIRECTORY" && segments[1] == package_name) + { + found = true; + while(cmlFile[i].second[0][0] == '#') + cmlFile[i].second[0].erase(0,1); + } + } + else if(cmlFile[i].first == "command" && cmlFile[i].second[0] == "ADD_SUBDIRECTORY") + { + int pos = 1; + while (pos < cmlFile[i].second.size()) + { + if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != '#') + { + if (package_name == cmlFile[i].second[pos]) + { + found = true; + if (!toInclude) + { + cmlFile[i].first = "comment"; + cmlFile[i].second[0] = "#" + cmlFile[i].second[0]; + while (cmlFile[i].second.size() > 1) + { + cmlFile[i].second[0] += cmlFile[i].second[1]; + cmlFile[i].second.erase(cmlFile[i].second.begin()+1); + } + + } + } + break; + } + pos++; + } + } + } + if (!found && toInclude) + { + CDMUtilities::syntaxElement element; + element.first = "command"; + element.second.push_back("ADD_SUBDIRECTORY(" + package_name + ")"); + cmlFile.push_back(element); + } + + return CDMUtilities::writeCMLFile(this->CMakeLists->GetPath().c_str(),cmlFile); + } + return false; +}