summaryrefslogtreecommitdiffstats
path: root/Source/cmFindPackageCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2009-01-22 18:18:40 (GMT)
committerBrad King <brad.king@kitware.com>2009-01-22 18:18:40 (GMT)
commitc332e0bf3c4e619358322bd0d0961af45653eb5b (patch)
tree3e31da4052687557169b0e8da2cf897f42cbcb63 /Source/cmFindPackageCommand.cxx
parent3028ca756c8621b3cc37032987eb01fbe61da248 (diff)
downloadCMake-c332e0bf3c4e619358322bd0d0961af45653eb5b.zip
CMake-c332e0bf3c4e619358322bd0d0961af45653eb5b.tar.gz
CMake-c332e0bf3c4e619358322bd0d0961af45653eb5b.tar.bz2
ENH: Isolate policy changes in included scripts
Isolation of policy changes inside scripts is important for protecting the including context. This teaches include() and find_package() to imply a cmake_policy(PUSH) and cmake_policy(POP) around the scripts they load, with a NO_POLICY_SCOPE option to disable the behavior. This also creates CMake Policy CMP0011 to provide compatibility. See issue #8192.
Diffstat (limited to 'Source/cmFindPackageCommand.cxx')
-rw-r--r--Source/cmFindPackageCommand.cxx30
1 files changed, 23 insertions, 7 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index a57a4f1..5b61180 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -64,6 +64,7 @@ cmFindPackageCommand::cmFindPackageCommand()
this->NoModule = false;
this->DebugMode = false;
this->UseLib64Paths = false;
+ this->PolicyScope = true;
this->VersionMajor = 0;
this->VersionMinor = 0;
this->VersionPatch = 0;
@@ -77,7 +78,8 @@ cmFindPackageCommand::cmFindPackageCommand()
this->VersionFoundCount = 0;
this->CommandDocumentation =
" find_package(<package> [version] [EXACT] [QUIET]\n"
- " [[REQUIRED|COMPONENTS] [components...]])\n"
+ " [[REQUIRED|COMPONENTS] [components...]]\n"
+ " [NO_POLICY_SCOPE])\n"
"Finds and loads settings from an external project. "
"<package>_FOUND will be set to indicate whether the package was found. "
"When the package is found package-specific information is provided "
@@ -116,6 +118,7 @@ cmFindPackageCommand::cmFindPackageCommand()
"The complete Config mode command signature is:\n"
" find_package(<package> [version] [EXACT] [QUIET]\n"
" [[REQUIRED|COMPONENTS] [components...]] [NO_MODULE]\n"
+ " [NO_POLICY_SCOPE]\n"
" [NAMES name1 [name2 ...]]\n"
" [CONFIGS config1 [config2 ...]]\n"
" [HINTS path1 [path2 ... ]]\n"
@@ -290,6 +293,11 @@ cmFindPackageCommand::cmFindPackageCommand()
this->CommandDocumentation += this->GenericDocumentationMacPolicy;
this->CommandDocumentation += this->GenericDocumentationRootPath;
this->CommandDocumentation += this->GenericDocumentationPathsOrder;
+ this->CommandDocumentation +=
+ "\n"
+ "See the cmake_policy() command documentation for discussion of the "
+ "NO_POLICY_SCOPE option."
+ ;
}
//----------------------------------------------------------------------------
@@ -406,6 +414,12 @@ bool cmFindPackageCommand
this->Compatibility_1_6 = false;
doing = DoingConfigs;
}
+ else if(args[i] == "NO_POLICY_SCOPE")
+ {
+ this->PolicyScope = false;
+ this->Compatibility_1_6 = false;
+ doing = DoingNone;
+ }
else if(args[i] == "NO_CMAKE_BUILDS_PATH")
{
this->NoBuilds = true;
@@ -675,7 +689,7 @@ bool cmFindPackageCommand::FindModule(bool& found)
std::string var = this->Name;
var += "_FIND_MODULE";
this->Makefile->AddDefinition(var.c_str(), "1");
- bool result = this->ReadListFile(mfile.c_str());
+ bool result = this->ReadListFile(mfile.c_str(), DoPolicyScope);
this->Makefile->RemoveDefinition(var.c_str());
return result;
}
@@ -753,7 +767,7 @@ bool cmFindPackageCommand::HandlePackageMode()
this->StoreVersionFound();
// Parse the configuration file.
- if(this->ReadListFile(this->FileFound.c_str()))
+ if(this->ReadListFile(this->FileFound.c_str(), DoPolicyScope))
{
// The package has been found.
found = true;
@@ -963,9 +977,10 @@ bool cmFindPackageCommand::FindAppBundleConfig()
}
//----------------------------------------------------------------------------
-bool cmFindPackageCommand::ReadListFile(const char* f)
+bool cmFindPackageCommand::ReadListFile(const char* f, PolicyScopeRule psr)
{
- if(this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(),f))
+ if(this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(), f, 0,
+ !this->PolicyScope || psr == NoPolicyScope))
{
return true;
}
@@ -1304,9 +1319,10 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file)
sprintf(buf, "%u", this->VersionCount);
this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_COUNT", buf);
- // Load the version check file.
+ // Load the version check file. Pass NoPolicyScope because we do
+ // our own policy push/pop independent of CMP0011.
bool suitable = false;
- if(this->ReadListFile(version_file.c_str()))
+ if(this->ReadListFile(version_file.c_str(), NoPolicyScope))
{
// Check the output variables.
bool okay = this->Makefile->IsOn("PACKAGE_VERSION_EXACT");