summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx105
1 files changed, 85 insertions, 20 deletions
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,