summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
authorAlex Neundorf <neundorf@kde.org>2010-11-17 21:32:53 (GMT)
committerBrad King <brad.king@kitware.com>2011-01-04 13:06:20 (GMT)
commitdb44848f441673909e909755d7b833aa474791c7 (patch)
treeac9f6a49c40a6c050947237d1d470e96b8cb7468 /Source/cmMakefile.cxx
parent1e69c6f37fa4a3a1a0c2f8fa665ad07a78fed580 (diff)
downloadCMake-db44848f441673909e909755d7b833aa474791c7.zip
CMake-db44848f441673909e909755d7b833aa474791c7.tar.gz
CMake-db44848f441673909e909755d7b833aa474791c7.tar.bz2
Prefer files from CMAKE_ROOT when including from CMAKE_ROOT
This patch makes include() and find_package() prefer cmake files located in CMAKE_ROOT over those in CMAKE_MODULE_PATH. This makes sure that the including file gets that file included which it expects, i.e. the one from cmake with which it was tested. It only changes behaviour when such an included file exists both in CMAKE_MODULE_PATH and in CMAKE_ROOT. This comes together with a new policy CMP0017, with default behaviour it behaves as it always did, but warns. With NEW behaviour it includes the file from CMAKE_ROOT instead from CMAKE_MODULE_PATH. This fixes (if CMP0017 is set) building KDE 4.5 with cmake >= 2.8.3. Also a basic test for this policy in included.
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 56e0ed9..ccf4d7a 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -2822,35 +2822,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,