[Cmake-commits] [cmake-commits] king committed cmFindPackageCommand.cxx 1.49 1.50 cmFindPackageCommand.h 1.25 1.26
cmake-commits at cmake.org
cmake-commits at cmake.org
Tue Dec 9 10:08:56 EST 2008
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv25256/Source
Modified Files:
cmFindPackageCommand.cxx cmFindPackageCommand.h
Log Message:
ENH: Preserve <pkg>_FIND_XXX vars in find_package
When the find_package command loads a module it sets several
<pkg>_FIND_XXX variables to communicate information about the command
invocation to the module. This restores the original state of the
variables when the command returns. This behavior is useful when a
find-module recursively calls find_package with NO_MODULE so that the
inner call does not change the values in the find-module.
Index: cmFindPackageCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFindPackageCommand.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -C 2 -d -r1.25 -r1.26
*** cmFindPackageCommand.h 10 Sep 2008 14:11:48 -0000 1.25
--- cmFindPackageCommand.h 9 Dec 2008 15:08:54 -0000 1.26
***************
*** 76,79 ****
--- 76,81 ----
void SetModuleVariables(const std::string& components);
bool FindModule(bool& found);
+ void AddFindDefinition(const char* var, const char* val);
+ void RestoreFindDefinitions();
bool HandlePackageMode();
void FindConfig();
***************
*** 105,108 ****
--- 107,113 ----
friend class cmFindPackageFileList;
+ struct OriginalDef { bool exists; std::string value; };
+ std::map<cmStdString, OriginalDef> OriginalDefs;
+
std::string CommandDocumentation;
cmStdString Name;
Index: cmFindPackageCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFindPackageCommand.cxx,v
retrieving revision 1.49
retrieving revision 1.50
diff -C 2 -d -r1.49 -r1.50
*** cmFindPackageCommand.cxx 8 Oct 2008 14:56:23 -0000 1.49
--- cmFindPackageCommand.cxx 9 Dec 2008 15:08:53 -0000 1.50
***************
*** 423,427 ****
// is required.
std::string req_var = this->Name + "_FIND_REQUIRED_" + args[i];
! this->Makefile->AddDefinition(req_var.c_str(), "1");
// Append to the list of required components.
--- 423,427 ----
// is required.
std::string req_var = this->Name + "_FIND_REQUIRED_" + args[i];
! this->AddFindDefinition(req_var.c_str(), "1");
// Append to the list of required components.
***************
*** 580,584 ****
// Store the list of components.
std::string components_var = this->Name + "_FIND_COMPONENTS";
! this->Makefile->AddDefinition(components_var.c_str(), components.c_str());
if(this->Quiet)
--- 580,584 ----
// Store the list of components.
std::string components_var = this->Name + "_FIND_COMPONENTS";
! this->AddFindDefinition(components_var.c_str(), components.c_str());
if(this->Quiet)
***************
*** 588,592 ****
std::string quietly = this->Name;
quietly += "_FIND_QUIETLY";
! this->Makefile->AddDefinition(quietly.c_str(), "1");
}
--- 588,592 ----
std::string quietly = this->Name;
quietly += "_FIND_QUIETLY";
! this->AddFindDefinition(quietly.c_str(), "1");
}
***************
*** 597,601 ****
std::string req = this->Name;
req += "_FIND_REQUIRED";
! this->Makefile->AddDefinition(req.c_str(), "1");
}
--- 597,601 ----
std::string req = this->Name;
req += "_FIND_REQUIRED";
! this->AddFindDefinition(req.c_str(), "1");
}
***************
*** 606,630 ****
std::string ver = this->Name;
ver += "_FIND_VERSION";
! this->Makefile->AddDefinition(ver.c_str(), this->Version.c_str());
char buf[64];
sprintf(buf, "%u", this->VersionMajor);
! this->Makefile->AddDefinition((ver+"_MAJOR").c_str(), buf);
sprintf(buf, "%u", this->VersionMinor);
! this->Makefile->AddDefinition((ver+"_MINOR").c_str(), buf);
sprintf(buf, "%u", this->VersionPatch);
! this->Makefile->AddDefinition((ver+"_PATCH").c_str(), buf);
sprintf(buf, "%u", this->VersionTweak);
! this->Makefile->AddDefinition((ver+"_TWEAK").c_str(), buf);
sprintf(buf, "%u", this->VersionCount);
! this->Makefile->AddDefinition((ver+"_COUNT").c_str(), buf);
// Tell the module whether an exact version has been requested.
std::string exact = this->Name;
exact += "_FIND_VERSION_EXACT";
! this->Makefile->AddDefinition(exact.c_str(),
! this->VersionExact? "1":"0");
}
}
//----------------------------------------------------------------------------
--- 606,661 ----
std::string ver = this->Name;
ver += "_FIND_VERSION";
! this->AddFindDefinition(ver.c_str(), this->Version.c_str());
char buf[64];
sprintf(buf, "%u", this->VersionMajor);
! this->AddFindDefinition((ver+"_MAJOR").c_str(), buf);
sprintf(buf, "%u", this->VersionMinor);
! this->AddFindDefinition((ver+"_MINOR").c_str(), buf);
sprintf(buf, "%u", this->VersionPatch);
! this->AddFindDefinition((ver+"_PATCH").c_str(), buf);
sprintf(buf, "%u", this->VersionTweak);
! this->AddFindDefinition((ver+"_TWEAK").c_str(), buf);
sprintf(buf, "%u", this->VersionCount);
! this->AddFindDefinition((ver+"_COUNT").c_str(), buf);
// Tell the module whether an exact version has been requested.
std::string exact = this->Name;
exact += "_FIND_VERSION_EXACT";
! this->AddFindDefinition(exact.c_str(), this->VersionExact? "1":"0");
}
}
+ //----------------------------------------------------------------------------
+ void cmFindPackageCommand::AddFindDefinition(const char* var, const char* val)
+ {
+ if(const char* old = this->Makefile->GetDefinition(var))
+ {
+ this->OriginalDefs[var].exists = true;
+ this->OriginalDefs[var].value = old;
+ }
+ else
+ {
+ this->OriginalDefs[var].exists = false;
+ }
+ this->Makefile->AddDefinition(var, val);
+ }
+
+ //----------------------------------------------------------------------------
+ void cmFindPackageCommand::RestoreFindDefinitions()
+ {
+ for(std::map<cmStdString, OriginalDef>::iterator
+ i = this->OriginalDefs.begin(); i != this->OriginalDefs.end(); ++i)
+ {
+ OriginalDef const& od = i->second;
+ if(od.exists)
+ {
+ this->Makefile->AddDefinition(i->first.c_str(), od.value.c_str());
+ }
+ else
+ {
+ this->Makefile->RemoveDefinition(i->first.c_str());
+ }
+ }
+ }
//----------------------------------------------------------------------------
***************
*** 1009,1012 ****
--- 1040,1046 ----
}
}
+
+ // Restore original state of "_FIND_" variables we set.
+ this->RestoreFindDefinitions();
}
More information about the Cmake-commits
mailing list