summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2011-01-11 20:56:59 (GMT)
committerBrad King <brad.king@kitware.com>2011-01-11 20:56:59 (GMT)
commit784d5ce0f8bf630901dece526df7ce663da17e6a (patch)
tree0b4647ace5986304b15b3f900fee969e278f33db /Source
parent2d3594b1bbd48d0dc7a071a6806c75c89341e1c5 (diff)
parentce28737c933a749cbc84c601f3ac9f56e4c832aa (diff)
downloadCMake-784d5ce0f8bf630901dece526df7ce663da17e6a.zip
CMake-784d5ce0f8bf630901dece526df7ce663da17e6a.tar.gz
CMake-784d5ce0f8bf630901dece526df7ce663da17e6a.tar.bz2
Merge branch 'policy-CMP0017' into resolve/python-versions/policy-CMP0017
Conflicts: Modules/FindPythonInterp.cmake
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCMakePolicyCommand.h3
-rw-r--r--Source/cmDocumentVariables.cxx19
-rw-r--r--Source/cmIncludeCommand.cxx16
-rw-r--r--Source/cmIncludeCommand.h18
-rw-r--r--Source/cmMakefile.cxx105
-rw-r--r--Source/cmPolicies.cxx83
-rw-r--r--Source/cmPolicies.h5
7 files changed, 197 insertions, 52 deletions
diff --git a/Source/cmCMakePolicyCommand.h b/Source/cmCMakePolicyCommand.h
index b326865..afd3001 100644
--- a/Source/cmCMakePolicyCommand.h
+++ b/Source/cmCMakePolicyCommand.h
@@ -85,7 +85,8 @@ public:
"given version of CMake. "
"All policies introduced in the specified version or earlier "
"will be set to use NEW behavior. "
- "All policies introduced after the specified version will be unset. "
+ "All policies introduced after the specified version will be unset "
+ "(unless variable CMAKE_POLICY_DEFAULT_CMP<NNNN> sets a default). "
"This effectively requests behavior preferred as of a given CMake "
"version and tells newer CMake versions to warn about their new "
"policies. "
diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx
index a69bb8f..5dfa64e 100644
--- a/Source/cmDocumentVariables.cxx
+++ b/Source/cmDocumentVariables.cxx
@@ -464,6 +464,25 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
// Variables defined by cmake, that change the behavior
// of cmake
+
+ cm->DefineProperty
+ ("CMAKE_POLICY_DEFAULT_CMP<NNNN>", cmProperty::VARIABLE,
+ "Default for CMake Policy CMP<NNNN> when it is otherwise left unset.",
+ "Commands cmake_minimum_required(VERSION) and cmake_policy(VERSION) "
+ "by default leave policies introduced after the given version unset. "
+ "Set CMAKE_POLICY_DEFAULT_CMP<NNNN> to OLD or NEW to specify the "
+ "default for policy CMP<NNNN>, where <NNNN> is the policy number."
+ "\n"
+ "This variable should not be set by a project in CMake code; "
+ "use cmake_policy(SET) instead. "
+ "Users running CMake may set this variable in the cache "
+ "(e.g. -DCMAKE_POLICY_DEFAULT_CMP<NNNN>=<OLD|NEW>) "
+ "to set a policy not otherwise set by the project. "
+ "Set to OLD to quiet a policy warning while using old behavior "
+ "or to NEW to try building the project with new behavior.",
+ false,
+ "Variables That Change Behavior");
+
cm->DefineProperty
("CMAKE_FIND_LIBRARY_PREFIXES", cmProperty::VARIABLE,
"Prefixes to prepend when looking for libraries.",
diff --git a/Source/cmIncludeCommand.cxx b/Source/cmIncludeCommand.cxx
index c9b14a1..0ac6df4 100644
--- a/Source/cmIncludeCommand.cxx
+++ b/Source/cmIncludeCommand.cxx
@@ -26,10 +26,10 @@ bool cmIncludeCommand
bool noPolicyScope = false;
std::string fname = args[0];
std::string resultVarName;
-
+
for (unsigned int i=1; i<args.size(); i++)
{
- if (args[i] == "OPTIONAL")
+ if (args[i] == "OPTIONAL")
{
if (optional)
{
@@ -60,10 +60,10 @@ bool cmIncludeCommand
{
noPolicyScope = true;
}
- else if(i > 1) // compat.: in previous cmake versions the second
+ else if(i > 1) // compat.: in previous cmake versions the second
// parameter was ignore if it wasn't "OPTIONAL"
{
- std::string errorText = "called with invalid argument: ";
+ std::string errorText = "called with invalid argument: ";
errorText += args[i];
this->SetError(errorText.c_str());
return false;
@@ -82,15 +82,15 @@ bool cmIncludeCommand
}
}
std::string fullFilePath;
- bool readit =
- this->Makefile->ReadListFile( this->Makefile->GetCurrentListFile(),
+ bool readit =
+ this->Makefile->ReadListFile( this->Makefile->GetCurrentListFile(),
fname.c_str(), &fullFilePath,
noPolicyScope);
-
+
// add the location of the included file if a result variable was given
if (resultVarName.size())
{
- this->Makefile->AddDefinition(resultVarName.c_str(),
+ this->Makefile->AddDefinition(resultVarName.c_str(),
readit?fullFilePath.c_str():"NOTFOUND");
}
diff --git a/Source/cmIncludeCommand.h b/Source/cmIncludeCommand.h
index a215275..d933ef3 100644
--- a/Source/cmIncludeCommand.h
+++ b/Source/cmIncludeCommand.h
@@ -15,7 +15,7 @@
#include "cmCommand.h"
/** \class cmIncludeCommand
- * \brief
+ * \brief
*
* cmIncludeCommand defines a list of distant
* files that can be "included" in the current list file.
@@ -28,7 +28,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- virtual cmCommand* Clone()
+ virtual cmCommand* Clone()
{
return new cmIncludeCommand;
}
@@ -49,15 +49,15 @@ public:
* The name of the command as specified in CMakeList.txt.
*/
virtual const char* GetName() {return "include";}
-
+
/**
* Succinct documentation.
*/
- virtual const char* GetTerseDocumentation()
+ virtual const char* GetTerseDocumentation()
{
return "Read CMake listfile code from the given file.";
}
-
+
/**
* More documentation.
*/
@@ -73,13 +73,17 @@ public:
"the variable will be set to the full filename which "
"has been included or NOTFOUND if it failed.\n"
"If a module is specified instead of a file, the file with name "
- "<modulename>.cmake is searched in the CMAKE_MODULE_PATH."
+ "<modulename>.cmake is searched first in CMAKE_MODULE_PATH, then in the "
+ "CMake module directory. There is one exception to this: if the file "
+ "which calls include() is located itself in the CMake module directory, "
+ "then first the CMake module directory is searched and "
+ "CMAKE_MODULE_PATH afterwards. See also policy CMP0017."
"\n"
"See the cmake_policy() command documentation for discussion of the "
"NO_POLICY_SCOPE option."
;
}
-
+
cmTypeMacro(cmIncludeCommand, cmCommand);
};
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index e61e157..53f4c3c 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -2825,35 +2825,100 @@ void cmMakefile::DisplayStatus(const char* message, float s)
std::string cmMakefile::GetModulesFile(const char* filename)
{
- std::vector<std::string> modulePath;
- const char* def = this->GetDefinition("CMAKE_MODULE_PATH");
- if(def)
+ std::string result;
+
+ // We search the module always in CMAKE_ROOT and in CMAKE_MODULE_PATH,
+ // and then decide based on the policy setting which one to return.
+ // See CMP0017 for more details.
+ // The specific problem was that KDE 4.5.0 installs a
+ // FindPackageHandleStandardArgs.cmake which doesn't have the new features
+ // of FPHSA.cmake introduced in CMake 2.8.3 yet, and by setting
+ // CMAKE_MODULE_PATH also e.g. FindZLIB.cmake from cmake included
+ // FPHSA.cmake from kdelibs and not from CMake, and tried to use the
+ // new features, which were not there in the version from kdelibs, and so
+ // failed ("
+ std::string moduleInCMakeRoot;
+ std::string moduleInCMakeModulePath;
+
+ // Always search in CMAKE_MODULE_PATH:
+ const char* cmakeModulePath = this->GetDefinition("CMAKE_MODULE_PATH");
+ if(cmakeModulePath)
+ {
+ std::vector<std::string> modulePath;
+ cmSystemTools::ExpandListArgument(cmakeModulePath, modulePath);
+
+ //Look through the possible module directories.
+ for(std::vector<std::string>::iterator i = modulePath.begin();
+ i != modulePath.end(); ++i)
+ {
+ std::string itempl = *i;
+ cmSystemTools::ConvertToUnixSlashes(itempl);
+ itempl += "/";
+ itempl += filename;
+ if(cmSystemTools::FileExists(itempl.c_str()))
+ {
+ moduleInCMakeModulePath = itempl;
+ break;
+ }
+ }
+ }
+
+ // Always search in the standard modules location.
+ const char* cmakeRoot = this->GetDefinition("CMAKE_ROOT");
+ if(cmakeRoot)
{
- cmSystemTools::ExpandListArgument(def, modulePath);
+ moduleInCMakeRoot = cmakeRoot;
+ moduleInCMakeRoot += "/Modules/";
+ moduleInCMakeRoot += filename;
+ cmSystemTools::ConvertToUnixSlashes(moduleInCMakeRoot);
+ if(!cmSystemTools::FileExists(moduleInCMakeRoot.c_str()))
+ {
+ moduleInCMakeRoot = "";
+ }
}
- // Also search in the standard modules location.
- def = this->GetDefinition("CMAKE_ROOT");
- if(def)
+ // Normally, prefer the files found in CMAKE_MODULE_PATH. Only when the file
+ // from which we are being called is located itself in CMAKE_ROOT, then
+ // prefer results from CMAKE_ROOT depending on the policy setting.
+ result = moduleInCMakeModulePath;
+ if (result.size() == 0)
{
- std::string rootModules = def;
- rootModules += "/Modules";
- modulePath.push_back(rootModules);
+ result = moduleInCMakeRoot;
}
- //std::string Look through the possible module directories.
- for(std::vector<std::string>::iterator i = modulePath.begin();
- i != modulePath.end(); ++i)
+
+ if ((moduleInCMakeModulePath.size()>0) && (moduleInCMakeRoot.size()>0))
{
- std::string itempl = *i;
- cmSystemTools::ConvertToUnixSlashes(itempl);
- itempl += "/";
- itempl += filename;
- if(cmSystemTools::FileExists(itempl.c_str()))
+ const char* currentFile = this->GetDefinition("CMAKE_CURRENT_LIST_FILE");
+ if (currentFile && (strstr(currentFile, cmakeRoot) == currentFile))
{
- return itempl;
+ switch (this->GetPolicyStatus(cmPolicies::CMP0017))
+ {
+ case cmPolicies::WARN:
+ {
+ cmOStringStream e;
+ e << "File " << currentFile << " includes "
+ << moduleInCMakeModulePath
+ << " (found via CMAKE_MODULE_PATH) which shadows "
+ << moduleInCMakeRoot << ". This may cause errors later on .\n"
+ << this->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0017);
+
+ this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ // break; // fall through to OLD behaviour
+ }
+ case cmPolicies::OLD:
+ result = moduleInCMakeModulePath;
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ default:
+ result = moduleInCMakeRoot;
+ break;
+ }
}
}
- return "";
+
+ return result;
}
void cmMakefile::ConfigureString(const std::string& input,
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
index 3fe92de..2d1f792 100644
--- a/Source/cmPolicies.cxx
+++ b/Source/cmPolicies.cxx
@@ -446,6 +446,23 @@ cmPolicies::cmPolicies()
"wasn't a valid target. "
"In CMake 2.8.3 and above it reports an error in this case.",
2,8,3,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0017, "CMP0017",
+ "Prefer files from the CMake module directory when including from there.",
+ "Starting with CMake 2.8.4, if a cmake-module shipped with CMake (i.e. "
+ "located in the CMake module directory) calls include() or "
+ "find_package(), the files located in the the CMake module directory are "
+ "prefered over the files in CMAKE_MODULE_PATH. "
+ "This makes sure that the modules belonging to "
+ "CMake always get those files included which they expect, and against "
+ "which they were developed and tested. "
+ "In call other cases, the files found in "
+ "CMAKE_MODULE_PATH still take precedence over the ones in "
+ "the CMake module directory. "
+ "The OLD behaviour is to always prefer files from CMAKE_MODULE_PATH over "
+ "files from the CMake modules directory.",
+ 2,8,4,0, cmPolicies::WARN);
}
cmPolicies::~cmPolicies()
@@ -495,9 +512,9 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
std::string ver = "2.4.0";
if (version && strlen(version) > 0)
- {
+ {
ver = version;
- }
+ }
unsigned int majorVer = 2;
unsigned int minorVer = 0;
@@ -556,29 +573,33 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
// now loop over all the policies and set them as appropriate
std::vector<cmPolicies::PolicyID> ancientPolicies;
- std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
- = this->Policies.begin();
- for (;i != this->Policies.end(); ++i)
- {
- if (i->second->IsPolicyNewerThan(majorVer,minorVer,patchVer,tweakVer))
+ for(std::map<cmPolicies::PolicyID,cmPolicy *>::iterator i
+ = this->Policies.begin(); i != this->Policies.end(); ++i)
{
- if(i->second->Status == cmPolicies::REQUIRED_ALWAYS)
+ if (i->second->IsPolicyNewerThan(majorVer,minorVer,patchVer,tweakVer))
{
+ if(i->second->Status == cmPolicies::REQUIRED_ALWAYS)
+ {
ancientPolicies.push_back(i->first);
+ }
+ else
+ {
+ cmPolicies::PolicyStatus status = cmPolicies::WARN;
+ if(!this->GetPolicyDefault(mf, i->second->IDString, &status) ||
+ !mf->SetPolicy(i->second->ID, status))
+ {
+ return false;
+ }
+ }
}
- else if (!mf->SetPolicy(i->second->ID, cmPolicies::WARN))
- {
- return false;
- }
- }
else
- {
- if (!mf->SetPolicy(i->second->ID, cmPolicies::NEW))
{
+ if (!mf->SetPolicy(i->second->ID, cmPolicies::NEW))
+ {
return false;
+ }
}
}
- }
// Make sure the project does not use any ancient policies.
if(!ancientPolicies.empty())
@@ -592,6 +613,36 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
return true;
}
+//----------------------------------------------------------------------------
+bool cmPolicies::GetPolicyDefault(cmMakefile* mf, std::string const& policy,
+ cmPolicies::PolicyStatus* defaultSetting)
+{
+ std::string defaultVar = "CMAKE_POLICY_DEFAULT_" + policy;
+ std::string defaultValue = mf->GetSafeDefinition(defaultVar.c_str());
+ if(defaultValue == "NEW")
+ {
+ *defaultSetting = cmPolicies::NEW;
+ }
+ else if(defaultValue == "OLD")
+ {
+ *defaultSetting = cmPolicies::OLD;
+ }
+ else if(defaultValue == "")
+ {
+ *defaultSetting = cmPolicies::WARN;
+ }
+ else
+ {
+ cmOStringStream e;
+ e << defaultVar << " has value \"" << defaultValue
+ << "\" but must be \"OLD\", \"NEW\", or \"\" (empty).";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
+ return false;
+ }
+
+ return true;
+}
+
bool cmPolicies::GetPolicyID(const char *id, cmPolicies::PolicyID &pid)
{
if (!id || strlen(id) < 1)
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index fce33ac..2160f37 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -52,6 +52,7 @@ public:
CMP0014, // Input directories must have CMakeLists.txt
CMP0015, // link_directories() treats paths relative to source dir
CMP0016, // target_link_libraries() fails if only argument is not a target
+ CMP0017, // Prefer files in CMAKE_ROOT when including from CMAKE_ROOT
// Always the last entry. Useful mostly to avoid adding a comma
// the last policy when adding a new one.
@@ -102,6 +103,10 @@ public:
void DiagnoseAncientPolicies(std::vector<PolicyID> const& ancient,
unsigned int majorVer, unsigned int minorVer,
unsigned int patchVer, cmMakefile* mf);
+
+ bool GetPolicyDefault(cmMakefile* mf, std::string const& policy,
+ cmPolicies::PolicyStatus* defaultStatus);
+
};
#endif