summaryrefslogtreecommitdiffstats
path: root/Source/cmFindPackageCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2012-02-28 14:51:10 (GMT)
committerBrad King <brad.king@kitware.com>2012-02-28 15:01:44 (GMT)
commitd3651041e9f16876d227c757254256039d62d85b (patch)
tree749b74fe9142a703f802efc71653883064f72b5b /Source/cmFindPackageCommand.cxx
parent31ead5f695182dbb96196f9795b6437e013c6567 (diff)
downloadCMake-d3651041e9f16876d227c757254256039d62d85b.zip
CMake-d3651041e9f16876d227c757254256039d62d85b.tar.gz
CMake-d3651041e9f16876d227c757254256039d62d85b.tar.bz2
find_package: Optionally warn when implicitly using Config mode
Define variable CMAKE_FIND_PACKAGE_WARN_NO_MODULE for use by a project that wants to use an explicit mode in every call to find_package in order to generate more specific failure messages. Word the warning using the new CONFIG and MODULE mode keywords when the minimum required version of CMake is new enough to have them. Otherwise word the warning using the old NO_MODULE mode keyword. Inspired-by: Alex Neundorf <neundorf@kde.org>
Diffstat (limited to 'Source/cmFindPackageCommand.cxx')
-rw-r--r--Source/cmFindPackageCommand.cxx41
1 files changed, 41 insertions, 0 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index 437f47a..d632570 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -73,6 +73,7 @@ cmFindPackageCommand::cmFindPackageCommand()
this->VersionFoundPatch = 0;
this->VersionFoundTweak = 0;
this->VersionFoundCount = 0;
+ this->RequiredCMakeVersion = 0;
}
//----------------------------------------------------------------------------
@@ -372,6 +373,15 @@ bool cmFindPackageCommand
return false;
}
+ // Lookup required version of CMake.
+ if(const char* rv =
+ this->Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION"))
+ {
+ unsigned int v[3] = {0,0,0};
+ sscanf(rv, "%u.%u.%u", &v[0], &v[1], &v[2]);
+ this->RequiredCMakeVersion = CMake_VERSION_ENCODE(v[0],v[1],v[2]);
+ }
+
// Check for debug mode.
this->DebugMode = this->Makefile->IsOn("CMAKE_FIND_DEBUG_MODE");
@@ -691,6 +701,37 @@ bool cmFindPackageCommand
}
}
+ if(this->UseFindModules && this->UseConfigFiles &&
+ this->Makefile->IsOn("CMAKE_FIND_PACKAGE_WARN_NO_MODULE"))
+ {
+ cmOStringStream aw;
+ if(this->RequiredCMakeVersion >= CMake_VERSION_ENCODE(2,8,8))
+ {
+ aw << "find_package called without either MODULE or CONFIG option and "
+ "no Find" << this->Name << ".cmake module is in CMAKE_MODULE_PATH. "
+ "Add MODULE to exclusively request Module mode and fail if "
+ "Find" << this->Name << ".cmake is missing. "
+ "Add CONFIG to exclusively request Config mode and search for a "
+ "package configuration file provided by " << this->Name <<
+ " (" << this->Name << "Config.cmake or " <<
+ cmSystemTools::LowerCase(this->Name) << "-config.cmake). ";
+ }
+ else
+ {
+ aw << "find_package called without NO_MODULE option and no "
+ "Find" << this->Name << ".cmake module is in CMAKE_MODULE_PATH. "
+ "Add NO_MODULE to exclusively request Config mode and search for a "
+ "package configuration file provided by " << this->Name <<
+ " (" << this->Name << "Config.cmake or " <<
+ cmSystemTools::LowerCase(this->Name) << "-config.cmake). "
+ "Otherwise make Find" << this->Name << ".cmake available in "
+ "CMAKE_MODULE_PATH.";
+ }
+ aw << "\n"
+ "(Variable CMAKE_FIND_PACKAGE_WARN_NO_MODULE enabled this warning.)";
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, aw.str());
+ }
+
// No find module. Assume the project has a CMake config file. Use
// a <package>_DIR cache variable to locate it.
this->Variable = this->Name;