[cmake-commits] king committed cmFindPackageCommand.cxx 1.30 1.31
cmFindPackageCommand.h 1.16 1.17
cmake-commits at cmake.org
cmake-commits at cmake.org
Mon Jan 21 08:48:35 EST 2008
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv9907/Source
Modified Files:
cmFindPackageCommand.cxx cmFindPackageCommand.h
Log Message:
ENH: Implement version support in the find_package command module mode. Version numbers provided to the command are converted to variable settings to tell the FindXXX.cmake module what version is requested. This addresses issue #1645.
Index: cmFindPackageCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFindPackageCommand.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- cmFindPackageCommand.h 17 Jan 2008 14:02:31 -0000 1.16
+++ cmFindPackageCommand.h 21 Jan 2008 13:48:33 -0000 1.17
@@ -94,6 +94,11 @@
std::string CommandDocumentation;
cmStdString Name;
cmStdString Variable;
+ cmStdString Version;
+ unsigned int VersionMajor;
+ unsigned int VersionMinor;
+ unsigned int VersionPatch;
+ unsigned int VersionCount;
cmStdString FileFound;
bool Quiet;
bool Required;
Index: cmFindPackageCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFindPackageCommand.cxx,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- cmFindPackageCommand.cxx 18 Jan 2008 13:19:37 -0000 1.30
+++ cmFindPackageCommand.cxx 21 Jan 2008 13:48:33 -0000 1.31
@@ -63,8 +63,12 @@
this->NoBuilds = false;
this->NoModule = false;
this->DebugMode = false;
+ this->VersionMajor = 0;
+ this->VersionMinor = 0;
+ this->VersionPatch = 0;
+ this->VersionCount = 0;
this->CommandDocumentation =
- " find_package(<package> [major.minor] [QUIET] [NO_MODULE]\n"
+ " find_package(<package> [major[.minor[.patch]]] [QUIET] [NO_MODULE]\n"
" [[REQUIRED|COMPONENTS] [components...]]\n"
" [NAMES name1 [name2 ...]]\n"
" [CONFIGS config1 [config2 ...]]\n"
@@ -84,13 +88,15 @@
"can be used when <package>_FOUND is true are package-specific. "
"A package-specific list of components may be listed after the "
"REQUIRED option, or after the COMPONENTS option if no REQUIRED "
- "option is given. The \"major.minor\" version argument is currently "
- "a placeholder for future use and is ignored. "
+ "option is given. The \"[major[.minor[.patch]]]\" version argument "
+ "specifies a desired version with which the package found should be "
+ "compatible. Version support is currently provided only on a "
+ "package-by-package basis and is not enforced by the command. "
"The command has two modes by which it searches for packages: "
"\"Module\" mode and \"Config\" mode."
"\n"
"Module mode has a reduced signature:\n"
- " find_package(<package> [major.minor] [QUIET]\n"
+ " find_package(<package> [major[.minor[.patch]]] [QUIET]\n"
" [[REQUIRED|COMPONENTS] [components...]])\n"
"CMake searches for a file called \"Find<package>.cmake\" in "
"the CMAKE_MODULE_PATH followed by the CMake installation. "
@@ -104,6 +110,7 @@
"Config mode attempts to locate a configuration file provided by the "
"package to be found. A cache entry called <package>_DIR is created to "
"hold the directory containing the file. "
+ "Currently versioning is not implemented by Config mode. "
"By default the command searches for a package with the name <package>. "
"If the NAMES option is given the names following it are used instead "
"of <package>. "
@@ -338,6 +345,7 @@
else if(!haveVersion && version.find(args[i].c_str()))
{
haveVersion = true;
+ this->Version = args[i];
}
else
{
@@ -348,6 +356,24 @@
}
}
+ if(!this->Version.empty())
+ {
+ // Try to parse the version number and store the results that were
+ // successfully parsed.
+ unsigned int parsed_major;
+ unsigned int parsed_minor;
+ unsigned int parsed_patch;
+ this->VersionCount = sscanf(this->Version.c_str(), "%u.%u.%u",
+ &parsed_major, &parsed_minor, &parsed_patch);
+ switch(this->VersionCount)
+ {
+ case 3: this->VersionPatch = parsed_patch; // no break!
+ case 2: this->VersionMinor = parsed_minor; // no break!
+ case 1: this->VersionMajor = parsed_major; // no break!
+ default: break;
+ }
+ }
+
// Store the list of components.
std::string components_var = Name + "_FIND_COMPONENTS";
this->Makefile->AddDefinition(components_var.c_str(), components.c_str());
@@ -428,6 +454,35 @@
this->Makefile->AddDefinition(req.c_str(), "1");
}
+ if(!this->Version.empty())
+ {
+ // Tell the module that is about to be read what version of the
+ // package has been requested.
+ std::string ver = this->Name;
+ ver += "_FIND_VERSION";
+ this->Makefile->AddDefinition(ver.c_str(), this->Version.c_str());
+ char buf[64];
+ switch(this->VersionCount)
+ {
+ case 3:
+ {
+ snprintf(buf, 64, "%u", this->VersionPatch);
+ this->Makefile->AddDefinition((ver+"_PATCH").c_str(), buf);
+ } // no break
+ case 2:
+ {
+ snprintf(buf, 64, "%u", this->VersionMinor);
+ this->Makefile->AddDefinition((ver+"_MINOR").c_str(), buf);
+ } // no break
+ case 1:
+ {
+ snprintf(buf, 64, "%u", this->VersionMajor);
+ this->Makefile->AddDefinition((ver+"_MAJOR").c_str(), buf);
+ } // no break
+ default: break;
+ }
+ }
+
// Load the module we found.
found = true;
return this->ReadListFile(mfile.c_str());
More information about the Cmake-commits
mailing list