123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #include "cmLoadCacheCommand.h"
- #include "cmsys/FStream.hxx"
- #include "cmMakefile.h"
- #include "cmStateTypes.h"
- #include "cmSystemTools.h"
- #include "cmake.h"
- class cmExecutionStatus;
- bool cmLoadCacheCommand::InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus&)
- {
- if (args.empty()) {
- this->SetError("called with wrong number of arguments.");
- }
- if (args.size() >= 2 && args[1] == "READ_WITH_PREFIX") {
- return this->ReadWithPrefix(args);
- }
-
-
-
- bool excludeFiles = false;
- std::set<std::string> excludes;
- for (std::string const& arg : args) {
- if (excludeFiles) {
- excludes.insert(arg);
- }
- if (arg == "EXCLUDE") {
- excludeFiles = true;
- }
- if (excludeFiles && (arg == "INCLUDE_INTERNALS")) {
- break;
- }
- }
-
-
-
- bool includeFiles = false;
- std::set<std::string> includes;
- for (std::string const& arg : args) {
- if (includeFiles) {
- includes.insert(arg);
- }
- if (arg == "INCLUDE_INTERNALS") {
- includeFiles = true;
- }
- if (includeFiles && (arg == "EXCLUDE")) {
- break;
- }
- }
-
-
- for (std::string const& arg : args) {
- if ((arg == "EXCLUDE") || (arg == "INCLUDE_INTERNALS")) {
- break;
- }
- this->Makefile->GetCMakeInstance()->LoadCache(arg, false, excludes,
- includes);
- }
- return true;
- }
- bool cmLoadCacheCommand::ReadWithPrefix(std::vector<std::string> const& args)
- {
-
- if (args.size() < 3) {
- this->SetError("READ_WITH_PREFIX form must specify a prefix.");
- return false;
- }
-
- std::string cacheFile = args[0] + "/CMakeCache.txt";
- if (!cmSystemTools::FileExists(cacheFile)) {
- std::string e = "Cannot load cache file from " + cacheFile;
- this->SetError(e);
- return false;
- }
-
- this->Prefix = args[2];
- this->VariablesToRead.insert(args.begin() + 3, args.end());
-
- cmsys::ifstream fin(cacheFile.c_str());
-
-
-
- const int bufferSize = 4096;
- char buffer[bufferSize];
- std::string line;
- while (fin) {
-
- fin.read(buffer, bufferSize);
- if (fin.gcount()) {
-
- const char* i = buffer;
- const char* end = buffer + fin.gcount();
- while (i != end) {
- const char* begin = i;
- while (i != end && *i != '\n') {
- ++i;
- }
- if (i == begin || *(i - 1) != '\r') {
-
- line += std::string(begin, i - begin);
- } else {
-
-
- line += std::string(begin, i - 1 - begin);
- }
- if (i != end) {
-
- this->CheckLine(line.c_str());
- line.clear();
-
- ++i;
- }
- }
- }
- }
- if (!line.empty()) {
-
- this->CheckLine(line.c_str());
- }
- return true;
- }
- void cmLoadCacheCommand::CheckLine(const char* line)
- {
-
- std::string var;
- std::string value;
- cmStateEnums::CacheEntryType type = cmStateEnums::UNINITIALIZED;
- if (cmake::ParseCacheEntry(line, var, value, type)) {
-
- if (this->VariablesToRead.find(var) != this->VariablesToRead.end()) {
-
-
- var = this->Prefix + var;
- if (!value.empty()) {
- this->Makefile->AddDefinition(var, value.c_str());
- } else {
- this->Makefile->RemoveDefinition(var);
- }
- }
- }
- }
|