- // look at every syntax element
- for (int i = 0; i < cmlFile.size(); ++i)
- {
- // if the element is a command and is a SET command
- if (cmlFile[i].first == "command" && cmlFile[i].second[0] == "SET")
- {
- // search first parameter
- 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] != '(' && cmlFile[i].second[pos][0] != ')')
- {
- break;
- }
- pos++;
- }
- // if the first parameter is a third party statement
- if (pos < cmlFile[i].second.size() && cmlFile[i].second[pos] == library_command)
- {
- std::string foundLibrary = cmlFile[i].second[pos];
- // search for second parameter
- pos++;
- while (pos < cmlFile[i].second.size())
- {
- if (!isspace(cmlFile[i].second[pos][0]) && cmlFile[i].second[pos][0] != '#' && cmlFile[i].second[pos][0] != '(' && cmlFile[i].second[pos][0] != ')')
+
+// std::cout << "found cmakefile: " << CMfile << std::endl;
+// std::cout.flush();
+
+ try {
+// std::cout << "first regex" << std::endl;
+// std::cout.flush();
+ boost::regex expression("^\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+ON([\\s]|#[^\\n]*\\n)*\\)");
+
+ std::string::const_iterator start, end;
+ start = CMfile.begin();
+ end = CMfile.end();
+ boost::match_results<std::string::const_iterator> what;
+ boost::match_flag_type flags = boost::match_default;
+ if(boost::regex_search(start, end, what, expression, flags))
+ {
+// std::cout << "found " << what.str() << std::endl;
+// std::cout.flush();
+ found = true;
+ resCMfile += what.prefix().str();
+ if (toInclude)
+ resCMfile += what.str();
+ else
+ resCMfile += "#" + what.str();
+ resCMfile += what.suffix().str();
+
+ return CDMUtilities::writeFile(this->CMakeLists->GetPath().c_str(), resCMfile);
+ }
+ else
+ {
+// std::cout << "second regex" << std::endl;
+// std::cout.flush();
+ boost::regex expression("^\\h*#\\h*SET([\\s]|#[^\\n]*\\n)*\\(([\\s]|#[^\\n]*\\n)*\\$\\{BBTK_PACKAGE_NAME\\}"+library_command+"([\\s]|#[^\\n]*\\n)+ON([\\s]|#[^\\n]*\\n)*\\)");
+ if(boost::regex_search(start, end, what, expression, flags))
+ {
+ found = true;
+ resCMfile += what.prefix().str();
+ if(toInclude)
+ {
+ std::string dete = what[0].str();
+ for (int i = 0; i < dete.size(); ++i) {
+ if (dete[i] != '#')
+ resCMfile.push_back(dete[i]);
+ if (dete[i] == 'S')