summaryrefslogtreecommitdiffstats
path: root/Source/cmFindPackageCommand.cxx
diff options
context:
space:
mode:
authorKitware Robot <kwrobot@kitware.com>2016-05-16 14:34:04 (GMT)
committerBrad King <brad.king@kitware.com>2016-05-16 20:05:19 (GMT)
commitd9fd2f5402eeaa345691313658e02b51038f570b (patch)
treedca71b9a7e267f4c6300da3eb770415381726785 /Source/cmFindPackageCommand.cxx
parent82df6deaafb36cbbfd450202bb20b320f637751a (diff)
downloadCMake-d9fd2f5402eeaa345691313658e02b51038f570b.zip
CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.gz
CMake-d9fd2f5402eeaa345691313658e02b51038f570b.tar.bz2
Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update all our C++ code to a new style defined by `.clang-format`. Use `clang-format` version 3.8. * If you reached this commit for a line in `git blame`, re-run the blame operation starting at the parent of this commit to see older history for the content. * See the parent commit for instructions to rebase a change across this style transition commit.
Diffstat (limited to 'Source/cmFindPackageCommand.cxx')
-rw-r--r--Source/cmFindPackageCommand.cxx1738
1 files changed, 776 insertions, 962 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index d08441b..7908afe 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -26,10 +26,10 @@
#include <string.h>
#endif
-cmFindPackageCommand::PathLabel
- cmFindPackageCommand::PathLabel::UserRegistry("PACKAGE_REGISTRY");
-cmFindPackageCommand::PathLabel
- cmFindPackageCommand::PathLabel::Builds("BUILDS");
+cmFindPackageCommand::PathLabel cmFindPackageCommand::PathLabel::UserRegistry(
+ "PACKAGE_REGISTRY");
+cmFindPackageCommand::PathLabel cmFindPackageCommand::PathLabel::Builds(
+ "BUILDS");
cmFindPackageCommand::PathLabel
cmFindPackageCommand::PathLabel::SystemRegistry("SYSTEM_PACKAGE_REGISTRY");
@@ -67,71 +67,65 @@ void cmFindPackageCommand::AppendSearchPathGroups()
// Update the All group with new paths
labels = &this->PathGroupLabelMap[PathGroup::All];
- labels->insert(std::find(labels->begin(), labels->end(),
- PathLabel::CMakeSystem),
- PathLabel::UserRegistry);
- labels->insert(std::find(labels->begin(), labels->end(),
- PathLabel::CMakeSystem),
- PathLabel::Builds);
+ labels->insert(
+ std::find(labels->begin(), labels->end(), PathLabel::CMakeSystem),
+ PathLabel::UserRegistry);
+ labels->insert(
+ std::find(labels->begin(), labels->end(), PathLabel::CMakeSystem),
+ PathLabel::Builds);
labels->insert(std::find(labels->begin(), labels->end(), PathLabel::Guess),
PathLabel::SystemRegistry);
// Create the new path objects
- this->LabeledPaths.insert(std::make_pair(PathLabel::UserRegistry,
- cmSearchPath(this)));
- this->LabeledPaths.insert(std::make_pair(PathLabel::Builds,
- cmSearchPath(this)));
- this->LabeledPaths.insert(std::make_pair(PathLabel::SystemRegistry,
- cmSearchPath(this)));
+ this->LabeledPaths.insert(
+ std::make_pair(PathLabel::UserRegistry, cmSearchPath(this)));
+ this->LabeledPaths.insert(
+ std::make_pair(PathLabel::Builds, cmSearchPath(this)));
+ this->LabeledPaths.insert(
+ std::make_pair(PathLabel::SystemRegistry, cmSearchPath(this)));
}
-bool cmFindPackageCommand
-::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
+bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus&)
{
- if(args.size() < 1)
- {
+ if (args.size() < 1) {
this->SetError("called with incorrect number of arguments");
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};
+ 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]);
- }
+ this->RequiredCMakeVersion = CMake_VERSION_ENCODE(v[0], v[1], v[2]);
+ }
// Check for debug mode.
this->DebugMode = this->Makefile->IsOn("CMAKE_FIND_DEBUG_MODE");
// Lookup target architecture, if any.
- if(const char* arch =
- this->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE"))
- {
+ if (const char* arch =
+ this->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE")) {
this->LibraryArchitecture = arch;
- }
+ }
// Lookup whether lib64 paths should be used.
- if(this->Makefile->PlatformIs64Bit() &&
- this->Makefile->GetState()
- ->GetGlobalPropertyAsBool("FIND_LIBRARY_USE_LIB64_PATHS"))
- {
+ if (this->Makefile->PlatformIs64Bit() &&
+ this->Makefile->GetState()->GetGlobalPropertyAsBool(
+ "FIND_LIBRARY_USE_LIB64_PATHS")) {
this->UseLib64Paths = true;
- }
+ }
// Check if User Package Registry should be disabled
- if(this->Makefile->IsOn("CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY"))
- {
+ if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY")) {
this->NoUserRegistry = true;
- }
+ }
// Check if System Package Registry should be disabled
- if(this->Makefile->IsOn("CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY"))
- {
+ if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY")) {
this->NoSystemRegistry = true;
- }
+ }
// Find the current root path mode.
this->SelectDefaultRootPathMode();
@@ -150,120 +144,89 @@ bool cmFindPackageCommand
this->SearchPathSuffixes.push_back("");
// Parse the arguments.
- enum Doing { DoingNone, DoingComponents, DoingOptionalComponents, DoingNames,
- DoingPaths, DoingPathSuffixes, DoingConfigs, DoingHints };
+ enum Doing
+ {
+ DoingNone,
+ DoingComponents,
+ DoingOptionalComponents,
+ DoingNames,
+ DoingPaths,
+ DoingPathSuffixes,
+ DoingConfigs,
+ DoingHints
+ };
Doing doing = DoingNone;
cmsys::RegularExpression version("^[0-9.]+$");
bool haveVersion = false;
std::set<unsigned int> configArgs;
std::set<unsigned int> moduleArgs;
- for(unsigned int i=1; i < args.size(); ++i)
- {
- if(args[i] == "QUIET")
- {
+ for (unsigned int i = 1; i < args.size(); ++i) {
+ if (args[i] == "QUIET") {
this->Quiet = true;
doing = DoingNone;
- }
- else if(args[i] == "EXACT")
- {
+ } else if (args[i] == "EXACT") {
this->VersionExact = true;
doing = DoingNone;
- }
- else if(args[i] == "MODULE")
- {
+ } else if (args[i] == "MODULE") {
moduleArgs.insert(i);
doing = DoingNone;
- }
- else if(args[i] == "CONFIG")
- {
+ } else if (args[i] == "CONFIG") {
configArgs.insert(i);
doing = DoingNone;
- }
- else if(args[i] == "NO_MODULE")
- {
+ } else if (args[i] == "NO_MODULE") {
configArgs.insert(i);
doing = DoingNone;
- }
- else if(args[i] == "REQUIRED")
- {
+ } else if (args[i] == "REQUIRED") {
this->Required = true;
doing = DoingComponents;
- }
- else if(args[i] == "COMPONENTS")
- {
+ } else if (args[i] == "COMPONENTS") {
doing = DoingComponents;
- }
- else if(args[i] == "OPTIONAL_COMPONENTS")
- {
+ } else if (args[i] == "OPTIONAL_COMPONENTS") {
doing = DoingOptionalComponents;
- }
- else if(args[i] == "NAMES")
- {
+ } else if (args[i] == "NAMES") {
configArgs.insert(i);
doing = DoingNames;
- }
- else if(args[i] == "PATHS")
- {
+ } else if (args[i] == "PATHS") {
configArgs.insert(i);
doing = DoingPaths;
- }
- else if(args[i] == "HINTS")
- {
+ } else if (args[i] == "HINTS") {
configArgs.insert(i);
doing = DoingHints;
- }
- else if(args[i] == "PATH_SUFFIXES")
- {
+ } else if (args[i] == "PATH_SUFFIXES") {
configArgs.insert(i);
doing = DoingPathSuffixes;
- }
- else if(args[i] == "CONFIGS")
- {
+ } else if (args[i] == "CONFIGS") {
configArgs.insert(i);
doing = DoingConfigs;
- }
- else if(args[i] == "NO_POLICY_SCOPE")
- {
+ } else if (args[i] == "NO_POLICY_SCOPE") {
this->PolicyScope = false;
doing = DoingNone;
- }
- else if(args[i] == "NO_CMAKE_PACKAGE_REGISTRY")
- {
+ } else if (args[i] == "NO_CMAKE_PACKAGE_REGISTRY") {
this->NoUserRegistry = true;
configArgs.insert(i);
doing = DoingNone;
- }
- else if(args[i] == "NO_CMAKE_SYSTEM_PACKAGE_REGISTRY")
- {
+ } else if (args[i] == "NO_CMAKE_SYSTEM_PACKAGE_REGISTRY") {
this->NoSystemRegistry = true;
configArgs.insert(i);
doing = DoingNone;
- }
- else if(args[i] == "NO_CMAKE_BUILDS_PATH")
- {
+ } else if (args[i] == "NO_CMAKE_BUILDS_PATH") {
// Ignore legacy option.
configArgs.insert(i);
doing = DoingNone;
- }
- else if(this->CheckCommonArgument(args[i]))
- {
+ } else if (this->CheckCommonArgument(args[i])) {
configArgs.insert(i);
doing = DoingNone;
- }
- else if((doing == DoingComponents) || (doing == DoingOptionalComponents))
- {
+ } else if ((doing == DoingComponents) ||
+ (doing == DoingOptionalComponents)) {
// Set a variable telling the find script whether this component
// is required.
const char* isRequired = "1";
- if (doing == DoingOptionalComponents)
- {
+ if (doing == DoingOptionalComponents) {
isRequired = "0";
optionalComponents.insert(args[i]);
- }
- else
- {
+ } else {
requiredComponents.insert(args[i]);
- }
+ }
std::string req_var = this->Name + "_FIND_REQUIRED_" + args[i];
this->AddFindDefinition(req_var, isRequired);
@@ -272,105 +235,82 @@ bool cmFindPackageCommand
components += components_sep;
components += args[i];
components_sep = ";";
- }
- else if(doing == DoingNames)
- {
+ } else if (doing == DoingNames) {
this->Names.push_back(args[i]);
- }
- else if(doing == DoingPaths)
- {
+ } else if (doing == DoingPaths) {
this->UserGuessArgs.push_back(args[i]);
- }
- else if(doing == DoingHints)
- {
+ } else if (doing == DoingHints) {
this->UserHintsArgs.push_back(args[i]);
- }
- else if(doing == DoingPathSuffixes)
- {
+ } else if (doing == DoingPathSuffixes) {
this->AddPathSuffix(args[i]);
- }
- else if(doing == DoingConfigs)
- {
- if(args[i].find_first_of(":/\\") != args[i].npos ||
- cmSystemTools::GetFilenameLastExtension(args[i]) != ".cmake")
- {
+ } else if (doing == DoingConfigs) {
+ if (args[i].find_first_of(":/\\") != args[i].npos ||
+ cmSystemTools::GetFilenameLastExtension(args[i]) != ".cmake") {
std::ostringstream e;
- e << "given CONFIGS option followed by invalid file name \""
- << args[i] << "\". The names given must be file names without "
+ e << "given CONFIGS option followed by invalid file name \"" << args[i]
+ << "\". The names given must be file names without "
<< "a path and with a \".cmake\" extension.";
this->SetError(e.str());
return false;
- }
- this->Configs.push_back(args[i]);
}
- else if(!haveVersion && version.find(args[i].c_str()))
- {
+ this->Configs.push_back(args[i]);
+ } else if (!haveVersion && version.find(args[i].c_str())) {
haveVersion = true;
this->Version = args[i];
- }
- else
- {
+ } else {
std::ostringstream e;
e << "called with invalid argument \"" << args[i] << "\"";
this->SetError(e.str());
return false;
- }
}
+ }
std::vector<std::string> doubledComponents;
std::set_intersection(requiredComponents.begin(), requiredComponents.end(),
optionalComponents.begin(), optionalComponents.end(),
std::back_inserter(doubledComponents));
- if(!doubledComponents.empty())
- {
+ if (!doubledComponents.empty()) {
std::ostringstream e;
e << "called with components that are both required and optional:\n";
e << cmWrap(" ", doubledComponents, "", "\n") << "\n";
this->SetError(e.str());
return false;
- }
+ }
// Maybe choose one mode exclusively.
this->UseFindModules = configArgs.empty();
this->UseConfigFiles = moduleArgs.empty();
- if(!this->UseFindModules && !this->UseConfigFiles)
- {
+ if (!this->UseFindModules && !this->UseConfigFiles) {
std::ostringstream e;
e << "given options exclusive to Module mode:\n";
- for(std::set<unsigned int>::const_iterator si = moduleArgs.begin();
- si != moduleArgs.end(); ++si)
- {
+ for (std::set<unsigned int>::const_iterator si = moduleArgs.begin();
+ si != moduleArgs.end(); ++si) {
e << " " << args[*si] << "\n";
- }
+ }
e << "and options exclusive to Config mode:\n";
- for(std::set<unsigned int>::const_iterator si = configArgs.begin();
- si != configArgs.end(); ++si)
- {
+ for (std::set<unsigned int>::const_iterator si = configArgs.begin();
+ si != configArgs.end(); ++si) {
e << " " << args[*si] << "\n";
- }
+ }
e << "The options are incompatible.";
this->SetError(e.str());
return false;
- }
+ }
// Ignore EXACT with no version.
- if(this->Version.empty() && this->VersionExact)
- {
+ if (this->Version.empty() && this->VersionExact) {
this->VersionExact = false;
this->Makefile->IssueMessage(
cmake::AUTHOR_WARNING, "Ignoring EXACT since no version is requested.");
- }
+ }
- if(this->Version.empty() || components.empty())
- {
+ if (this->Version.empty() || components.empty()) {
// Check whether we are recursing inside "Find<name>.cmake" within
// another find_package(<name>) call.
std::string mod = this->Name;
mod += "_FIND_MODULE";
- if(this->Makefile->IsOn(mod))
- {
- if(this->Version.empty())
- {
+ if (this->Makefile->IsOn(mod)) {
+ if (this->Version.empty()) {
// Get version information from the outer call if necessary.
// Requested version string.
std::string ver = this->Name;
@@ -381,102 +321,102 @@ bool cmFindPackageCommand
std::string exact = this->Name;
exact += "_FIND_VERSION_EXACT";
this->VersionExact = this->Makefile->IsOn(exact);
- }
- if(components.empty())
- {
+ }
+ if (components.empty()) {
std::string components_var = this->Name + "_FIND_COMPONENTS";
components = this->Makefile->GetSafeDefinition(components_var);
- }
}
}
+ }
- if(!this->Version.empty())
- {
+ 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;
unsigned int parsed_tweak;
- this->VersionCount = sscanf(this->Version.c_str(), "%u.%u.%u.%u",
- &parsed_major, &parsed_minor,
- &parsed_patch, &parsed_tweak);
- switch(this->VersionCount)
- {
- case 4: this->VersionTweak = parsed_tweak; // no break!
- 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;
- }
+ this->VersionCount =
+ sscanf(this->Version.c_str(), "%u.%u.%u.%u", &parsed_major,
+ &parsed_minor, &parsed_patch, &parsed_tweak);
+ switch (this->VersionCount) {
+ case 4:
+ this->VersionTweak = parsed_tweak; // no break!
+ 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;
}
+ }
std::string disableFindPackageVar = "CMAKE_DISABLE_FIND_PACKAGE_";
disableFindPackageVar += this->Name;
- if(this->Makefile->IsOn(disableFindPackageVar))
- {
- if (this->Required)
- {
+ if (this->Makefile->IsOn(disableFindPackageVar)) {
+ if (this->Required) {
std::ostringstream e;
e << "for module " << this->Name << " called with REQUIRED, but "
<< disableFindPackageVar
<< " is enabled. A REQUIRED package cannot be disabled.";
this->SetError(e.str());
return false;
- }
-
- return true;
}
+ return true;
+ }
this->SetModuleVariables(components);
// See if there is a Find<package>.cmake module.
- if(this->UseFindModules)
- {
+ if (this->UseFindModules) {
bool foundModule = false;
- if(!this->FindModule(foundModule))
- {
+ if (!this->FindModule(foundModule)) {
this->AppendSuccessInformation();
return false;
- }
- if(foundModule)
- {
+ }
+ if (foundModule) {
this->AppendSuccessInformation();
return true;
- }
}
+ }
- if(this->UseFindModules && this->UseConfigFiles &&
- this->Makefile->IsOn("CMAKE_FIND_PACKAGE_WARN_NO_MODULE"))
- {
+ if (this->UseFindModules && this->UseConfigFiles &&
+ this->Makefile->IsOn("CMAKE_FIND_PACKAGE_WARN_NO_MODULE")) {
std::ostringstream aw;
- if(this->RequiredCMakeVersion >= CMake_VERSION_ENCODE(2,8,8))
- {
+ 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.";
- }
+ "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.)";
+ "(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.
@@ -484,17 +424,14 @@ bool cmFindPackageCommand
this->Variable += "_DIR";
// Add the default name.
- if(this->Names.empty())
- {
+ if (this->Names.empty()) {
this->Names.push_back(this->Name);
- }
+ }
// Add the default configs.
- if(this->Configs.empty())
- {
- for(std::vector<std::string>::const_iterator ni = this->Names.begin();
- ni != this->Names.end(); ++ni)
- {
+ if (this->Configs.empty()) {
+ for (std::vector<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end(); ++ni) {
std::string config = *ni;
config += "Config.cmake";
this->Configs.push_back(config);
@@ -502,8 +439,8 @@ bool cmFindPackageCommand
config = cmSystemTools::LowerCase(*ni);
config += "-config.cmake";
this->Configs.push_back(config);
- }
}
+ }
// get igonored paths from vars and reroot them.
std::vector<std::string> ignored;
@@ -520,7 +457,6 @@ bool cmFindPackageCommand
return result;
}
-
void cmFindPackageCommand::SetModuleVariables(const std::string& components)
{
this->AddFindDefinition("CMAKE_FIND_PACKAGE_NAME", this->Name.c_str());
@@ -529,26 +465,23 @@ void cmFindPackageCommand::SetModuleVariables(const std::string& components)
std::string components_var = this->Name + "_FIND_COMPONENTS";
this->AddFindDefinition(components_var, components.c_str());
- if(this->Quiet)
- {
+ if (this->Quiet) {
// Tell the module that is about to be read that it should find
// quietly.
std::string quietly = this->Name;
quietly += "_FIND_QUIETLY";
this->AddFindDefinition(quietly, "1");
- }
+ }
- if(this->Required)
- {
+ if (this->Required) {
// Tell the module that is about to be read that it should report
// a fatal error if the package is not found.
std::string req = this->Name;
req += "_FIND_REQUIRED";
this->AddFindDefinition(req, "1");
- }
+ }
- if(!this->Version.empty())
- {
+ 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;
@@ -556,53 +489,47 @@ void cmFindPackageCommand::SetModuleVariables(const std::string& components)
this->AddFindDefinition(ver, this->Version.c_str());
char buf[64];
sprintf(buf, "%u", this->VersionMajor);
- this->AddFindDefinition(ver+"_MAJOR", buf);
+ this->AddFindDefinition(ver + "_MAJOR", buf);
sprintf(buf, "%u", this->VersionMinor);
- this->AddFindDefinition(ver+"_MINOR", buf);
+ this->AddFindDefinition(ver + "_MINOR", buf);
sprintf(buf, "%u", this->VersionPatch);
- this->AddFindDefinition(ver+"_PATCH", buf);
+ this->AddFindDefinition(ver + "_PATCH", buf);
sprintf(buf, "%u", this->VersionTweak);
- this->AddFindDefinition(ver+"_TWEAK", buf);
+ this->AddFindDefinition(ver + "_TWEAK", buf);
sprintf(buf, "%u", this->VersionCount);
- this->AddFindDefinition(ver+"_COUNT", buf);
+ this->AddFindDefinition(ver + "_COUNT", buf);
// Tell the module whether an exact version has been requested.
std::string exact = this->Name;
exact += "_FIND_VERSION_EXACT";
- this->AddFindDefinition(exact, this->VersionExact? "1":"0");
- }
+ this->AddFindDefinition(exact, this->VersionExact ? "1" : "0");
+ }
}
void cmFindPackageCommand::AddFindDefinition(const std::string& var,
const char* val)
{
- if(const char* old = this->Makefile->GetDefinition(var))
- {
+ if (const char* old = this->Makefile->GetDefinition(var)) {
this->OriginalDefs[var].exists = true;
this->OriginalDefs[var].value = old;
- }
- else
- {
+ } else {
this->OriginalDefs[var].exists = false;
- }
+ }
this->Makefile->AddDefinition(var, val);
}
void cmFindPackageCommand::RestoreFindDefinitions()
{
- for(std::map<std::string, OriginalDef>::iterator
- i = this->OriginalDefs.begin(); i != this->OriginalDefs.end(); ++i)
- {
+ for (std::map<std::string, OriginalDef>::iterator i =
+ this->OriginalDefs.begin();
+ i != this->OriginalDefs.end(); ++i) {
OriginalDef const& od = i->second;
- if(od.exists)
- {
+ if (od.exists) {
this->Makefile->AddDefinition(i->first, od.value.c_str());
- }
- else
- {
+ } else {
this->Makefile->RemoveDefinition(i->first);
- }
}
+ }
}
bool cmFindPackageCommand::FindModule(bool& found)
@@ -611,8 +538,7 @@ bool cmFindPackageCommand::FindModule(bool& found)
module += this->Name;
module += ".cmake";
std::string mfile = this->Makefile->GetModulesFile(module.c_str());
- if (!mfile.empty())
- {
+ if (!mfile.empty()) {
// Load the module we found, and set "<name>_FIND_MODULE" to true
// while inside it.
found = true;
@@ -622,7 +548,7 @@ bool cmFindPackageCommand::FindModule(bool& found)
bool result = this->ReadListFile(mfile.c_str(), DoPolicyScope);
this->Makefile->RemoveDefinition(var);
return result;
- }
+ }
return true;
}
@@ -641,44 +567,38 @@ bool cmFindPackageCommand::HandlePackageMode()
// Try to load the config file if the directory is known
bool fileFound = false;
- if (this->UseConfigFiles)
- {
- if(!cmSystemTools::IsOff(def))
- {
+ if (this->UseConfigFiles) {
+ if (!cmSystemTools::IsOff(def)) {
// Get the directory from the variable value.
std::string dir = def;
cmSystemTools::ConvertToUnixSlashes(dir);
// Treat relative paths with respect to the current source dir.
- if(!cmSystemTools::FileIsFullPath(dir.c_str()))
- {
+ if (!cmSystemTools::FileIsFullPath(dir.c_str())) {
dir = "/" + dir;
dir = this->Makefile->GetCurrentSourceDirectory() + dir;
- }
+ }
// The file location was cached. Look for the correct file.
std::string file;
- if (this->FindConfigFile(dir, file))
- {
+ if (this->FindConfigFile(dir, file)) {
this->FileFound = file;
fileFound = true;
- }
- def = this->Makefile->GetDefinition(this->Variable);
}
+ def = this->Makefile->GetDefinition(this->Variable);
+ }
// Search for the config file if it is not already found.
- if(cmSystemTools::IsOff(def) || !fileFound)
- {
+ if (cmSystemTools::IsOff(def) || !fileFound) {
fileFound = this->FindConfig();
- }
+ }
// Sanity check.
- if(fileFound && this->FileFound.empty())
- {
+ if (fileFound && this->FileFound.empty()) {
this->Makefile->IssueMessage(
cmake::INTERNAL_ERROR, "fileFound is true but FileFound is empty!");
fileFound = false;
- }
}
+ }
std::string foundVar = this->Name;
foundVar += "_FOUND";
@@ -691,17 +611,15 @@ bool cmFindPackageCommand::HandlePackageMode()
bool found = false;
bool configFileSetFOUNDFalse = false;
- if(fileFound)
- {
- if ((this->Makefile->IsDefinitionSet(foundVar))
- && (this->Makefile->IsOn(foundVar) == false))
- {
+ if (fileFound) {
+ if ((this->Makefile->IsDefinitionSet(foundVar)) &&
+ (this->Makefile->IsOn(foundVar) == false)) {
// by removing Foo_FOUND here if it is FALSE, we don't really change
// the situation for the Config file which is about to be included,
// but we make it possible to detect later on whether the Config file
// has set Foo_FOUND to FALSE itself:
this->Makefile->RemoveDefinition(foundVar);
- }
+ }
this->Makefile->RemoveDefinition(notFoundMessageVar);
// Set the version variables before loading the config file.
@@ -709,151 +627,135 @@ bool cmFindPackageCommand::HandlePackageMode()
this->StoreVersionFound();
// Parse the configuration file.
- if(this->ReadListFile(this->FileFound.c_str(), DoPolicyScope))
- {
+ if (this->ReadListFile(this->FileFound.c_str(), DoPolicyScope)) {
// The package has been found.
found = true;
// Check whether the Config file has set Foo_FOUND to FALSE:
- if ((this->Makefile->IsDefinitionSet(foundVar))
- && (this->Makefile->IsOn(foundVar) == false))
- {
+ if ((this->Makefile->IsDefinitionSet(foundVar)) &&
+ (this->Makefile->IsOn(foundVar) == false)) {
// we get here if the Config file has set Foo_FOUND actively to FALSE
found = false;
configFileSetFOUNDFalse = true;
- notFoundMessage = this->Makefile->GetSafeDefinition(
- notFoundMessageVar);
- }
+ notFoundMessage =
+ this->Makefile->GetSafeDefinition(notFoundMessageVar);
}
- else
- {
+ } else {
// The configuration file is invalid.
result = false;
- }
}
+ }
- if (result && !found && (!this->Quiet || this->Required))
- {
+ if (result && !found && (!this->Quiet || this->Required)) {
// The variable is not set.
std::ostringstream e;
std::ostringstream aw;
- if (configFileSetFOUNDFalse)
- {
+ if (configFileSetFOUNDFalse) {
/* clang-format off */
e << "Found package configuration file:\n"
" " << this->FileFound << "\n"
"but it set " << foundVar << " to FALSE so package \"" <<
this->Name << "\" is considered to be NOT FOUND.";
/* clang-format on */
- if (!notFoundMessage.empty())
- {
+ if (!notFoundMessage.empty()) {
e << " Reason given by package: \n" << notFoundMessage << "\n";
- }
}
+ }
// If there are files in ConsideredConfigs, it means that FooConfig.cmake
// have been found, but they didn't have appropriate versions.
- else if (!this->ConsideredConfigs.empty())
- {
- e << "Could not find a configuration file for package \""
- << this->Name << "\" that "
- << (this->VersionExact? "exactly matches" : "is compatible with")
+ else if (!this->ConsideredConfigs.empty()) {
+ e << "Could not find a configuration file for package \"" << this->Name
+ << "\" that "
+ << (this->VersionExact ? "exactly matches" : "is compatible with")
<< " requested version \"" << this->Version << "\".\n"
<< "The following configuration files were considered but not "
"accepted:\n";
- for(std::vector<ConfigFileInfo>::size_type i=0;
- i<this->ConsideredConfigs.size(); i++)
- {
+ for (std::vector<ConfigFileInfo>::size_type i = 0;
+ i < this->ConsideredConfigs.size(); i++) {
e << " " << this->ConsideredConfigs[i].filename
<< ", version: " << this->ConsideredConfigs[i].version << "\n";
- }
}
- else
- {
+ } else {
std::string requestedVersionString;
- if(!this->Version.empty())
- {
+ if (!this->Version.empty()) {
requestedVersionString = " (requested version ";
requestedVersionString += this->Version;
requestedVersionString += ")";
- }
+ }
- if (this->UseConfigFiles)
- {
- if(this->UseFindModules)
- {
- e << "By not providing \"Find" << this->Name << ".cmake\" in "
+ if (this->UseConfigFiles) {
+ if (this->UseFindModules) {
+ e << "By not providing \"Find" << this->Name
+ << ".cmake\" in "
"CMAKE_MODULE_PATH this project has asked CMake to find a "
- "package configuration file provided by \""<<this->Name<< "\", "
- "but CMake did not find one.\n";
- }
+ "package configuration file provided by \""
+ << this->Name << "\", "
+ "but CMake did not find one.\n";
+ }
- if(this->Configs.size() == 1)
- {
+ if (this->Configs.size() == 1) {
e << "Could not find a package configuration file named \""
- << this->Configs[0] << "\" provided by package \""
- << this->Name << "\"" << requestedVersionString <<".\n";
- }
- else
- {
+ << this->Configs[0] << "\" provided by package \"" << this->Name
+ << "\"" << requestedVersionString << ".\n";
+ } else {
e << "Could not find a package configuration file provided by \""
<< this->Name << "\"" << requestedVersionString
<< " with any of the following names:\n"
<< cmWrap(" ", this->Configs, "", "\n") << "\n";
- }
-
- e << "Add the installation prefix of \"" << this->Name << "\" to "
- "CMAKE_PREFIX_PATH or set \"" << this->Variable << "\" to a "
- "directory containing one of the above files. "
- "If \"" << this->Name << "\" provides a separate development "
- "package or SDK, be sure it has been installed.";
}
- else // if(!this->UseFindModules && !this->UseConfigFiles)
- {
+
+ e << "Add the installation prefix of \"" << this->Name
+ << "\" to "
+ "CMAKE_PREFIX_PATH or set \""
+ << this->Variable << "\" to a "
+ "directory containing one of the above files. "
+ "If \""
+ << this->Name << "\" provides a separate development "
+ "package or SDK, be sure it has been installed.";
+ } else // if(!this->UseFindModules && !this->UseConfigFiles)
+ {
e << "No \"Find" << this->Name << ".cmake\" found in "
<< "CMAKE_MODULE_PATH.";
- aw<< "Find"<< this->Name <<".cmake must either be part of this "
- "project itself, in this case adjust CMAKE_MODULE_PATH so that "
- "it points to the correct location inside its source tree.\n"
- "Or it must be installed by a package which has already been "
- "found via find_package(). In this case make sure that "
- "package has indeed been found and adjust CMAKE_MODULE_PATH to "
- "contain the location where that package has installed "
- "Find" << this->Name << ".cmake. This must be a location "
- "provided by that package. This error in general means that "
- "the buildsystem of this project is relying on a Find-module "
- "without ensuring that it is actually available.\n";
- }
+ aw << "Find" << this->Name
+ << ".cmake must either be part of this "
+ "project itself, in this case adjust CMAKE_MODULE_PATH so that "
+ "it points to the correct location inside its source tree.\n"
+ "Or it must be installed by a package which has already been "
+ "found via find_package(). In this case make sure that "
+ "package has indeed been found and adjust CMAKE_MODULE_PATH to "
+ "contain the location where that package has installed "
+ "Find"
+ << this->Name
+ << ".cmake. This must be a location "
+ "provided by that package. This error in general means that "
+ "the buildsystem of this project is relying on a Find-module "
+ "without ensuring that it is actually available.\n";
}
-
+ }
this->Makefile->IssueMessage(
- this->Required? cmake::FATAL_ERROR : cmake::WARNING, e.str());
- if (this->Required)
- {
+ this->Required ? cmake::FATAL_ERROR : cmake::WARNING, e.str());
+ if (this->Required) {
cmSystemTools::SetFatalErrorOccured();
- }
+ }
- if (!aw.str().empty())
- {
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,aw.str());
- }
+ if (!aw.str().empty()) {
+ this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, aw.str());
}
+ }
// Set a variable marking whether the package was found.
- this->Makefile->AddDefinition(foundVar, found? "1":"0");
+ this->Makefile->AddDefinition(foundVar, found ? "1" : "0");
// Set a variable naming the configuration file that was found.
std::string fileVar = this->Name;
fileVar += "_CONFIG";
- if(found)
- {
+ if (found) {
this->Makefile->AddDefinition(fileVar, this->FileFound.c_str());
- }
- else
- {
+ } else {
this->Makefile->RemoveDefinition(fileVar);
- }
+ }
std::string consideredConfigsVar = this->Name;
consideredConfigsVar += "_CONSIDERED_CONFIGS";
@@ -864,15 +766,14 @@ bool cmFindPackageCommand::HandlePackageMode()
std::string consideredVersions;
const char* sep = "";
- for(std::vector<ConfigFileInfo>::size_type i=0;
- i<this->ConsideredConfigs.size(); i++)
- {
+ for (std::vector<ConfigFileInfo>::size_type i = 0;
+ i < this->ConsideredConfigs.size(); i++) {
consideredConfigFiles += sep;
consideredVersions += sep;
consideredConfigFiles += this->ConsideredConfigs[i].filename;
consideredVersions += this->ConsideredConfigs[i].version;
sep = ";";
- }
+ }
this->Makefile->AddDefinition(consideredConfigsVar,
consideredConfigFiles.c_str());
@@ -892,105 +793,89 @@ bool cmFindPackageCommand::FindConfig()
bool found = false;
// Search for frameworks.
- if(!found && (this->SearchFrameworkFirst || this->SearchFrameworkOnly))
- {
+ if (!found && (this->SearchFrameworkFirst || this->SearchFrameworkOnly)) {
found = this->FindFrameworkConfig();
- }
+ }
// Search for apps.
- if(!found && (this->SearchAppBundleFirst || this->SearchAppBundleOnly))
- {
+ if (!found && (this->SearchAppBundleFirst || this->SearchAppBundleOnly)) {
found = this->FindAppBundleConfig();
- }
+ }
// Search prefixes.
- if(!found && !(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
- {
+ if (!found && !(this->SearchFrameworkOnly || this->SearchAppBundleOnly)) {
found = this->FindPrefixedConfig();
- }
+ }
// Search for frameworks.
- if(!found && this->SearchFrameworkLast)
- {
+ if (!found && this->SearchFrameworkLast) {
found = this->FindFrameworkConfig();
- }
+ }
// Search for apps.
- if(!found && this->SearchAppBundleLast)
- {
+ if (!found && this->SearchAppBundleLast) {
found = this->FindAppBundleConfig();
- }
+ }
// Store the entry in the cache so it can be set by the user.
std::string init;
- if(found)
- {
+ if (found) {
init = cmSystemTools::GetFilenamePath(this->FileFound);
- }
- else
- {
+ } else {
init = this->Variable + "-NOTFOUND";
- }
+ }
std::string help =
"The directory containing a CMake configuration file for ";
help += this->Name;
help += ".";
// We force the value since we do not get here if it was already set.
- this->Makefile->AddCacheDefinition(this->Variable,
- init.c_str(), help.c_str(),
- cmState::PATH, true);
+ this->Makefile->AddCacheDefinition(this->Variable, init.c_str(),
+ help.c_str(), cmState::PATH, true);
return found;
}
bool cmFindPackageCommand::FindPrefixedConfig()
{
std::vector<std::string>& prefixes = this->SearchPaths;
- for(std::vector<std::string>::const_iterator pi = prefixes.begin();
- pi != prefixes.end(); ++pi)
- {
- if(this->SearchPrefix(*pi))
- {
+ for (std::vector<std::string>::const_iterator pi = prefixes.begin();
+ pi != prefixes.end(); ++pi) {
+ if (this->SearchPrefix(*pi)) {
return true;
- }
}
+ }
return false;
}
bool cmFindPackageCommand::FindFrameworkConfig()
{
std::vector<std::string>& prefixes = this->SearchPaths;
- for(std::vector<std::string>::const_iterator i = prefixes.begin();
- i != prefixes.end(); ++i)
- {
- if(this->SearchFrameworkPrefix(*i))
- {
+ for (std::vector<std::string>::const_iterator i = prefixes.begin();
+ i != prefixes.end(); ++i) {
+ if (this->SearchFrameworkPrefix(*i)) {
return true;
- }
}
+ }
return false;
}
bool cmFindPackageCommand::FindAppBundleConfig()
{
std::vector<std::string>& prefixes = this->SearchPaths;
- for(std::vector<std::string>::const_iterator i = prefixes.begin();
- i != prefixes.end(); ++i)
- {
- if(this->SearchAppBundlePrefix(*i))
- {
+ for (std::vector<std::string>::const_iterator i = prefixes.begin();
+ i != prefixes.end(); ++i) {
+ if (this->SearchAppBundlePrefix(*i)) {
return true;
- }
}
+ }
return false;
}
bool cmFindPackageCommand::ReadListFile(const char* f, PolicyScopeRule psr)
{
const bool noPolicyScope = !this->PolicyScope || psr == NoPolicyScope;
- if(this->Makefile->ReadDependentFile(f, noPolicyScope))
- {
+ if (this->Makefile->ReadDependentFile(f, noPolicyScope)) {
return true;
- }
+ }
std::string e = "Error reading CMake code from \"";
e += f;
e += "\".";
@@ -1001,64 +886,53 @@ bool cmFindPackageCommand::ReadListFile(const char* f, PolicyScopeRule psr)
void cmFindPackageCommand::AppendToFoundProperty(bool found)
{
std::vector<std::string> foundContents;
- const char *foundProp = this->Makefile->GetState()
- ->GetGlobalProperty("PACKAGES_FOUND");
- if (foundProp && *foundProp)
- {
+ const char* foundProp =
+ this->Makefile->GetState()->GetGlobalProperty("PACKAGES_FOUND");
+ if (foundProp && *foundProp) {
std::string tmp = foundProp;
cmSystemTools::ExpandListArgument(tmp, foundContents, false);
- std::vector<std::string>::iterator nameIt = std::find(
- foundContents.begin(), foundContents.end(), this->Name);
- if(nameIt != foundContents.end())
- {
+ std::vector<std::string>::iterator nameIt =
+ std::find(foundContents.begin(), foundContents.end(), this->Name);
+ if (nameIt != foundContents.end()) {
foundContents.erase(nameIt);
- }
}
+ }
std::vector<std::string> notFoundContents;
- const char *notFoundProp =
- this->Makefile->GetState()
- ->GetGlobalProperty("PACKAGES_NOT_FOUND");
- if (notFoundProp && *notFoundProp)
- {
+ const char* notFoundProp =
+ this->Makefile->GetState()->GetGlobalProperty("PACKAGES_NOT_FOUND");
+ if (notFoundProp && *notFoundProp) {
std::string tmp = notFoundProp;
cmSystemTools::ExpandListArgument(tmp, notFoundContents, false);
- std::vector<std::string>::iterator nameIt = std::find(
- notFoundContents.begin(), notFoundContents.end(), this->Name);
- if(nameIt != notFoundContents.end())
- {
+ std::vector<std::string>::iterator nameIt =
+ std::find(notFoundContents.begin(), notFoundContents.end(), this->Name);
+ if (nameIt != notFoundContents.end()) {
notFoundContents.erase(nameIt);
- }
}
+ }
- if(found)
- {
+ if (found) {
foundContents.push_back(this->Name);
- }
- else
- {
+ } else {
notFoundContents.push_back(this->Name);
- }
-
+ }
std::string tmp = cmJoin(foundContents, ";");
- this->Makefile->GetState()
- ->SetGlobalProperty("PACKAGES_FOUND", tmp.c_str());
+ this->Makefile->GetState()->SetGlobalProperty("PACKAGES_FOUND", tmp.c_str());
tmp = cmJoin(notFoundContents, ";");
- this->Makefile->GetState()
- ->SetGlobalProperty("PACKAGES_NOT_FOUND", tmp.c_str());
+ this->Makefile->GetState()->SetGlobalProperty("PACKAGES_NOT_FOUND",
+ tmp.c_str());
}
void cmFindPackageCommand::AppendSuccessInformation()
{
{
- std::string transitivePropName = "_CMAKE_";
- transitivePropName += this->Name + "_TRANSITIVE_DEPENDENCY";
- this->Makefile->GetState()
- ->SetGlobalProperty(transitivePropName, "False");
+ std::string transitivePropName = "_CMAKE_";
+ transitivePropName += this->Name + "_TRANSITIVE_DEPENDENCY";
+ this->Makefile->GetState()->SetGlobalProperty(transitivePropName, "False");
}
std::string found = this->Name;
found += "_FOUND";
@@ -1066,8 +940,8 @@ void cmFindPackageCommand::AppendSuccessInformation()
const char* upperResult = this->Makefile->GetDefinition(upperFound);
const char* result = this->Makefile->GetDefinition(found);
- bool packageFound = ((cmSystemTools::IsOn(result))
- || (cmSystemTools::IsOn(upperResult)));
+ bool packageFound =
+ ((cmSystemTools::IsOn(result)) || (cmSystemTools::IsOn(upperResult)));
this->AppendToFoundProperty(packageFound);
@@ -1076,31 +950,28 @@ void cmFindPackageCommand::AppendSuccessInformation()
std::string quietInfoPropName = "_CMAKE_";
quietInfoPropName += this->Name;
quietInfoPropName += "_QUIET";
- this->Makefile->GetState()
- ->SetGlobalProperty(quietInfoPropName, this->Quiet ? "TRUE" : "FALSE");
+ this->Makefile->GetState()->SetGlobalProperty(
+ quietInfoPropName, this->Quiet ? "TRUE" : "FALSE");
// set a global property to record the required version of this package
std::string versionInfoPropName = "_CMAKE_";
versionInfoPropName += this->Name;
versionInfoPropName += "_REQUIRED_VERSION";
std::string versionInfo;
- if(!this->Version.empty())
- {
+ if (!this->Version.empty()) {
versionInfo = this->VersionExact ? "==" : ">=";
versionInfo += " ";
versionInfo += this->Version;
- }
- this->Makefile->GetState()
- ->SetGlobalProperty(versionInfoPropName, versionInfo.c_str());
- if (this->Required)
- {
+ }
+ this->Makefile->GetState()->SetGlobalProperty(versionInfoPropName,
+ versionInfo.c_str());
+ if (this->Required) {
std::string requiredInfoPropName = "_CMAKE_";
requiredInfoPropName += this->Name;
requiredInfoPropName += "_TYPE";
- this->Makefile->GetState()
- ->SetGlobalProperty(requiredInfoPropName, "REQUIRED");
- }
-
+ this->Makefile->GetState()->SetGlobalProperty(requiredInfoPropName,
+ "REQUIRED");
+ }
// Restore original state of "_FIND_" variables we set.
this->RestoreFindDefinitions();
@@ -1108,37 +979,29 @@ void cmFindPackageCommand::AppendSuccessInformation()
void cmFindPackageCommand::ComputePrefixes()
{
- if(!this->NoDefaultPath)
- {
- if(!this->NoCMakePath)
- {
+ if (!this->NoDefaultPath) {
+ if (!this->NoCMakePath) {
this->FillPrefixesCMakeVariable();
- }
- if(!this->NoCMakeEnvironmentPath)
- {
+ }
+ if (!this->NoCMakeEnvironmentPath) {
this->FillPrefixesCMakeEnvironment();
- }
}
+ }
this->FillPrefixesUserHints();
- if(!this->NoDefaultPath)
- {
- if(!this->NoSystemEnvironmentPath)
- {
+ if (!this->NoDefaultPath) {
+ if (!this->NoSystemEnvironmentPath) {
this->FillPrefixesSystemEnvironment();
- }
- if(!this->NoUserRegistry)
- {
+ }
+ if (!this->NoUserRegistry) {
this->FillPrefixesUserRegistry();
- }
- if(!this->NoCMakeSystemPath)
- {
+ }
+ if (!this->NoCMakeSystemPath) {
this->FillPrefixesCMakeSystemVariable();
- }
- if(!this->NoSystemRegistry)
- {
+ }
+ if (!this->NoSystemRegistry) {
this->FillPrefixesSystemRegistry();
- }
}
+ }
this->FillPrefixesUserGuess();
this->ComputeFinalPaths();
@@ -1146,7 +1009,7 @@ void cmFindPackageCommand::ComputePrefixes()
void cmFindPackageCommand::FillPrefixesCMakeEnvironment()
{
- cmSearchPath &paths = this->LabeledPaths[PathLabel::CMakeEnvironment];
+ cmSearchPath& paths = this->LabeledPaths[PathLabel::CMakeEnvironment];
// Check the environment variable with the same name as the cache
// entry.
@@ -1160,7 +1023,7 @@ void cmFindPackageCommand::FillPrefixesCMakeEnvironment()
void cmFindPackageCommand::FillPrefixesCMakeVariable()
{
- cmSearchPath &paths = this->LabeledPaths[PathLabel::CMake];
+ cmSearchPath& paths = this->LabeledPaths[PathLabel::CMake];
paths.AddCMakePath("CMAKE_PREFIX_PATH");
paths.AddCMakePath("CMAKE_FRAMEWORK_PATH");
@@ -1169,27 +1032,23 @@ void cmFindPackageCommand::FillPrefixesCMakeVariable()
void cmFindPackageCommand::FillPrefixesSystemEnvironment()
{
- cmSearchPath &paths = this->LabeledPaths[PathLabel::SystemEnvironment];
+ cmSearchPath& paths = this->LabeledPaths[PathLabel::SystemEnvironment];
// Use the system search path to generate prefixes.
// Relative paths are interpreted with respect to the current
// working directory.
std::vector<std::string> tmp;
cmSystemTools::GetPath(tmp);
- for(std::vector<std::string>::iterator i = tmp.begin();
- i != tmp.end(); ++i)
- {
+ for (std::vector<std::string>::iterator i = tmp.begin(); i != tmp.end();
+ ++i) {
// If the path is a PREFIX/bin case then add its parent instead.
- if((cmHasLiteralSuffix(*i, "/bin")) ||
- (cmHasLiteralSuffix(*i, "/sbin")))
- {
+ if ((cmHasLiteralSuffix(*i, "/bin")) ||
+ (cmHasLiteralSuffix(*i, "/sbin"))) {
paths.AddPath(cmSystemTools::GetFilenamePath(*i));
- }
- else
- {
+ } else {
paths.AddPath(*i);
- }
}
+ }
}
void cmFindPackageCommand::FillPrefixesUserRegistry()
@@ -1199,32 +1058,29 @@ void cmFindPackageCommand::FillPrefixesUserRegistry()
#elif defined(__HAIKU__)
char dir[B_PATH_NAME_LENGTH];
if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, dir, sizeof(dir)) ==
- B_OK)
- {
+ B_OK) {
std::string fname = dir;
fname += "/cmake/packages/";
fname += Name;
this->LoadPackageRegistryDir(fname,
this->LabeledPaths[PathLabel::UserRegistry]);
- }
+ }
#else
- if(const char* home = cmSystemTools::GetEnv("HOME"))
- {
+ if (const char* home = cmSystemTools::GetEnv("HOME")) {
std::string dir = home;
dir += "/.cmake/packages/";
dir += this->Name;
this->LoadPackageRegistryDir(dir,
this->LabeledPaths[PathLabel::UserRegistry]);
- }
+ }
#endif
}
void cmFindPackageCommand::FillPrefixesSystemRegistry()
{
- if(this->NoSystemRegistry || this->NoDefaultPath)
- {
+ if (this->NoSystemRegistry || this->NoDefaultPath) {
return;
- }
+ }
#if defined(_WIN32) && !defined(__CYGWIN__)
this->LoadPackageRegistryWinSystem();
@@ -1232,15 +1088,15 @@ void cmFindPackageCommand::FillPrefixesSystemRegistry()
}
#if defined(_WIN32) && !defined(__CYGWIN__)
-# include <windows.h>
-# undef GetCurrentDirectory
- // http://msdn.microsoft.com/en-us/library/aa384253%28v=vs.85%29.aspx
-# if !defined(KEY_WOW64_32KEY)
-# define KEY_WOW64_32KEY 0x0200
-# endif
-# if !defined(KEY_WOW64_64KEY)
-# define KEY_WOW64_64KEY 0x0100
-# endif
+#include <windows.h>
+#undef GetCurrentDirectory
+// http://msdn.microsoft.com/en-us/library/aa384253%28v=vs.85%29.aspx
+#if !defined(KEY_WOW64_32KEY)
+#define KEY_WOW64_32KEY 0x0200
+#endif
+#if !defined(KEY_WOW64_64KEY)
+#define KEY_WOW64_64KEY 0x0100
+#endif
void cmFindPackageCommand::LoadPackageRegistryWinUser()
{
// HKEY_CURRENT_USER\\Software shares 32-bit and 64-bit views.
@@ -1250,20 +1106,17 @@ void cmFindPackageCommand::LoadPackageRegistryWinUser()
void cmFindPackageCommand::LoadPackageRegistryWinSystem()
{
- cmSearchPath &paths = this->LabeledPaths[PathLabel::SystemRegistry];
+ cmSearchPath& paths = this->LabeledPaths[PathLabel::SystemRegistry];
// HKEY_LOCAL_MACHINE\\SOFTWARE has separate 32-bit and 64-bit views.
// Prefer the target platform view first.
- if(this->Makefile->PlatformIs64Bit())
- {
+ if (this->Makefile->PlatformIs64Bit()) {
this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY, paths);
this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY, paths);
- }
- else
- {
+ } else {
this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY, paths);
this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY, paths);
- }
+ }
}
void cmFindPackageCommand::LoadPackageRegistryWin(bool user, unsigned int view,
@@ -1273,64 +1126,68 @@ void cmFindPackageCommand::LoadPackageRegistryWin(bool user, unsigned int view,
key += cmsys::Encoding::ToWide(this->Name);
std::set<std::wstring> bad;
HKEY hKey;
- if(RegOpenKeyExW(user? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, key.c_str(),
- 0, KEY_QUERY_VALUE|view, &hKey) == ERROR_SUCCESS)
- {
+ if (RegOpenKeyExW(user ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, key.c_str(),
+ 0, KEY_QUERY_VALUE | view, &hKey) == ERROR_SUCCESS) {
DWORD valueType = REG_NONE;
wchar_t name[16383]; // RegEnumValue docs limit name to 32767 _bytes_
std::vector<wchar_t> data(512);
bool done = false;
DWORD index = 0;
- while(!done)
- {
+ while (!done) {
DWORD nameSize = static_cast<DWORD>(sizeof(name));
- DWORD dataSize = static_cast<DWORD>(data.size()*sizeof(data[0]));
- switch(RegEnumValueW(hKey, index, name, &nameSize,
- 0, &valueType, (BYTE*)&data[0], &dataSize))
- {
+ DWORD dataSize = static_cast<DWORD>(data.size() * sizeof(data[0]));
+ switch (RegEnumValueW(hKey, index, name, &nameSize, 0, &valueType,
+ (BYTE*)&data[0], &dataSize)) {
case ERROR_SUCCESS:
++index;
- if(valueType == REG_SZ)
- {
+ if (valueType == REG_SZ) {
data[dataSize] = 0;
- if(!this->CheckPackageRegistryEntry(
- cmsys::Encoding::ToNarrow(&data[0]), outPaths))
- {
+ if (!this->CheckPackageRegistryEntry(
+ cmsys::Encoding::ToNarrow(&data[0]), outPaths)) {
// The entry is invalid.
bad.insert(name);
- }
}
+ }
break;
case ERROR_MORE_DATA:
- data.resize((dataSize+sizeof(data[0])-1)/sizeof(data[0]));
+ data.resize((dataSize + sizeof(data[0]) - 1) / sizeof(data[0]));
+ break;
+ case ERROR_NO_MORE_ITEMS:
+ default:
+ done = true;
break;
- case ERROR_NO_MORE_ITEMS: default: done = true; break;
- }
}
- RegCloseKey(hKey);
}
+ RegCloseKey(hKey);
+ }
// Remove bad values if possible.
- if(user && !bad.empty() &&
- RegOpenKeyExW(HKEY_CURRENT_USER, key.c_str(),
- 0, KEY_SET_VALUE|view, &hKey) == ERROR_SUCCESS)
- {
- for(std::set<std::wstring>::const_iterator vi = bad.begin();
- vi != bad.end(); ++vi)
- {
+ if (user && !bad.empty() &&
+ RegOpenKeyExW(HKEY_CURRENT_USER, key.c_str(), 0, KEY_SET_VALUE | view,
+ &hKey) == ERROR_SUCCESS) {
+ for (std::set<std::wstring>::const_iterator vi = bad.begin();
+ vi != bad.end(); ++vi) {
RegDeleteValueW(hKey, vi->c_str());
- }
- RegCloseKey(hKey);
}
+ RegCloseKey(hKey);
+ }
}
#else
class cmFindPackageCommandHoldFile
{
const char* File;
+
public:
- cmFindPackageCommandHoldFile(const char* f): File(f) {}
+ cmFindPackageCommandHoldFile(const char* f)
+ : File(f)
+ {
+ }
~cmFindPackageCommandHoldFile()
- { if(this->File) { cmSystemTools::RemoveFile(this->File); } }
+ {
+ if (this->File) {
+ cmSystemTools::RemoveFile(this->File);
+ }
+ }
void Release() { this->File = 0; }
};
@@ -1338,34 +1195,30 @@ void cmFindPackageCommand::LoadPackageRegistryDir(std::string const& dir,
cmSearchPath& outPaths)
{
cmsys::Directory files;
- if(!files.Load(dir))
- {
+ if (!files.Load(dir)) {
return;
- }
+ }
std::string fname;
- for(unsigned long i=0; i < files.GetNumberOfFiles(); ++i)
- {
+ for (unsigned long i = 0; i < files.GetNumberOfFiles(); ++i) {
fname = dir;
fname += "/";
fname += files.GetFile(i);
- if(!cmSystemTools::FileIsDirectory(fname))
- {
+ if (!cmSystemTools::FileIsDirectory(fname)) {
// Hold this file hostage until it behaves.
cmFindPackageCommandHoldFile holdFile(fname.c_str());
// Load the file.
cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
std::string fentry;
- if(fin && cmSystemTools::GetLineFromStream(fin, fentry) &&
- this->CheckPackageRegistryEntry(fentry, outPaths))
- {
+ if (fin && cmSystemTools::GetLineFromStream(fin, fentry) &&
+ this->CheckPackageRegistryEntry(fentry, outPaths)) {
// The file references an existing package, so release it.
holdFile.Release();
- }
}
}
+ }
// TODO: Wipe out the directory if it is empty.
}
@@ -1375,43 +1228,34 @@ bool cmFindPackageCommand::CheckPackageRegistryEntry(const std::string& fname,
cmSearchPath& outPaths)
{
// Parse the content of one package registry entry.
- if(cmSystemTools::FileIsFullPath(fname.c_str()))
- {
+ if (cmSystemTools::FileIsFullPath(fname.c_str())) {
// The first line in the stream is the full path to a file or
// directory containing the package.
- if(cmSystemTools::FileExists(fname.c_str()))
- {
+ if (cmSystemTools::FileExists(fname.c_str())) {
// The path exists. Look for the package here.
- if(!cmSystemTools::FileIsDirectory(fname))
- {
+ if (!cmSystemTools::FileIsDirectory(fname)) {
outPaths.AddPath(cmSystemTools::GetFilenamePath(fname));
- }
- else
- {
+ } else {
outPaths.AddPath(fname);
- }
- return true;
}
- else
- {
+ return true;
+ } else {
// The path does not exist. Assume the stream content is
// associated with an old package that no longer exists, and
// delete it to keep the package registry clean.
return false;
- }
}
- else
- {
+ } else {
// The first line in the stream is not the full path to a file or
// directory. Assume the stream content was created by a future
// version of CMake that uses a different format, and leave it.
return true;
- }
+ }
}
void cmFindPackageCommand::FillPrefixesCMakeSystemVariable()
{
- cmSearchPath &paths = this->LabeledPaths[PathLabel::CMakeSystem];
+ cmSearchPath& paths = this->LabeledPaths[PathLabel::CMakeSystem];
paths.AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH");
paths.AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
@@ -1420,88 +1264,80 @@ void cmFindPackageCommand::FillPrefixesCMakeSystemVariable()
void cmFindPackageCommand::FillPrefixesUserGuess()
{
- cmSearchPath &paths = this->LabeledPaths[PathLabel::Guess];
+ cmSearchPath& paths = this->LabeledPaths[PathLabel::Guess];
- for(std::vector<std::string>::const_iterator p = this->UserGuessArgs.begin();
- p != this->UserGuessArgs.end(); ++p)
- {
+ for (std::vector<std::string>::const_iterator p =
+ this->UserGuessArgs.begin();
+ p != this->UserGuessArgs.end(); ++p) {
paths.AddUserPath(*p);
- }
+ }
}
void cmFindPackageCommand::FillPrefixesUserHints()
{
- cmSearchPath &paths = this->LabeledPaths[PathLabel::Hints];
+ cmSearchPath& paths = this->LabeledPaths[PathLabel::Hints];
- for(std::vector<std::string>::const_iterator p = this->UserHintsArgs.begin();
- p != this->UserHintsArgs.end(); ++p)
- {
+ for (std::vector<std::string>::const_iterator p =
+ this->UserHintsArgs.begin();
+ p != this->UserHintsArgs.end(); ++p) {
paths.AddUserPath(*p);
- }
+ }
}
bool cmFindPackageCommand::SearchDirectory(std::string const& dir)
{
- assert(!dir.empty() && dir[dir.size()-1] == '/');
+ assert(!dir.empty() && dir[dir.size() - 1] == '/');
// Check each path suffix on this directory.
- for(std::vector<std::string>::const_iterator
- si = this->SearchPathSuffixes.begin();
- si != this->SearchPathSuffixes.end(); ++si)
- {
+ for (std::vector<std::string>::const_iterator si =
+ this->SearchPathSuffixes.begin();
+ si != this->SearchPathSuffixes.end(); ++si) {
std::string d = dir;
- if(!si->empty())
- {
+ if (!si->empty()) {
d += *si;
d += "/";
- }
- if(this->CheckDirectory(d))
- {
+ }
+ if (this->CheckDirectory(d)) {
return true;
- }
}
+ }
return false;
}
bool cmFindPackageCommand::CheckDirectory(std::string const& dir)
{
- assert(!dir.empty() && dir[dir.size()-1] == '/');
+ assert(!dir.empty() && dir[dir.size() - 1] == '/');
// Look for the file in this directory.
- std::string d = dir.substr(0, dir.size()-1);
- if(this->FindConfigFile(d, this->FileFound))
- {
+ std::string d = dir.substr(0, dir.size() - 1);
+ if (this->FindConfigFile(d, this->FileFound)) {
// Remove duplicate slashes.
cmSystemTools::ConvertToUnixSlashes(this->FileFound);
return true;
- }
+ }
return false;
}
bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
std::string& file)
{
- if (this->IgnoredPaths.count(dir))
- {
+ if (this->IgnoredPaths.count(dir)) {
return false;
- }
+ }
- for(std::vector<std::string>::const_iterator ci = this->Configs.begin();
- ci != this->Configs.end(); ++ci)
- {
+ for (std::vector<std::string>::const_iterator ci = this->Configs.begin();
+ ci != this->Configs.end(); ++ci) {
file = dir;
file += "/";
file += *ci;
- if(this->DebugMode)
- {
+ if (this->DebugMode) {
fprintf(stderr, "Checking file [%s]\n", file.c_str());
- }
- if(cmSystemTools::FileExists(file.c_str(), true) &&
- this->CheckVersion(file))
- {
+ }
+ if (cmSystemTools::FileExists(file.c_str(), true) &&
+ this->CheckVersion(file)) {
return true;
- }
}
+ }
return false;
}
@@ -1518,29 +1354,25 @@ bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
// Look for foo-config-version.cmake
std::string version_file = version_file_base;
version_file += "-version.cmake";
- if ((haveResult == false)
- && (cmSystemTools::FileExists(version_file.c_str(), true)))
- {
+ if ((haveResult == false) &&
+ (cmSystemTools::FileExists(version_file.c_str(), true))) {
result = this->CheckVersionFile(version_file, version);
haveResult = true;
- }
+ }
// Look for fooConfigVersion.cmake
version_file = version_file_base;
version_file += "Version.cmake";
- if ((haveResult == false)
- && (cmSystemTools::FileExists(version_file.c_str(), true)))
- {
+ if ((haveResult == false) &&
+ (cmSystemTools::FileExists(version_file.c_str(), true))) {
result = this->CheckVersionFile(version_file, version);
haveResult = true;
- }
-
+ }
// If no version was requested a versionless package is acceptable.
- if ((haveResult == false) && (this->Version.empty()))
- {
+ if ((haveResult == false) && (this->Version.empty())) {
result = true;
- }
+ }
ConfigFileInfo configFileInfo;
configFileInfo.filename = config_file;
@@ -1567,8 +1399,7 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file,
// Set the input variables.
this->Makefile->AddDefinition("PACKAGE_FIND_NAME", this->Name.c_str());
- this->Makefile->AddDefinition("PACKAGE_FIND_VERSION",
- this->Version.c_str());
+ this->Makefile->AddDefinition("PACKAGE_FIND_VERSION", this->Version.c_str());
char buf[64];
sprintf(buf, "%u", this->VersionMajor);
this->Makefile->AddDefinition("PACKAGE_FIND_VERSION_MAJOR", buf);
@@ -1584,21 +1415,18 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file,
// Load the version check file. Pass NoPolicyScope because we do
// our own policy push/pop independent of CMP0011.
bool suitable = false;
- if(this->ReadListFile(version_file.c_str(), NoPolicyScope))
- {
+ if (this->ReadListFile(version_file.c_str(), NoPolicyScope)) {
// Check the output variables.
bool okay = this->Makefile->IsOn("PACKAGE_VERSION_EXACT");
bool unsuitable = this->Makefile->IsOn("PACKAGE_VERSION_UNSUITABLE");
- if(!okay && !this->VersionExact)
- {
+ if (!okay && !this->VersionExact) {
okay = this->Makefile->IsOn("PACKAGE_VERSION_COMPATIBLE");
- }
+ }
// The package is suitable if the version is okay and not
// explicitly unsuitable.
suitable = !unsuitable && (okay || this->Version.empty());
- if(suitable)
- {
+ if (suitable) {
// Get the version found.
this->VersionFound =
this->Makefile->GetSafeDefinition("PACKAGE_VERSION");
@@ -1610,25 +1438,27 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file,
unsigned int parsed_patch;
unsigned int parsed_tweak;
this->VersionFoundCount =
- sscanf(this->VersionFound.c_str(), "%u.%u.%u.%u",
- &parsed_major, &parsed_minor,
- &parsed_patch, &parsed_tweak);
- switch(this->VersionFoundCount)
- {
- case 4: this->VersionFoundTweak = parsed_tweak; // no break!
- case 3: this->VersionFoundPatch = parsed_patch; // no break!
- case 2: this->VersionFoundMinor = parsed_minor; // no break!
- case 1: this->VersionFoundMajor = parsed_major; // no break!
- default: break;
- }
+ sscanf(this->VersionFound.c_str(), "%u.%u.%u.%u", &parsed_major,
+ &parsed_minor, &parsed_patch, &parsed_tweak);
+ switch (this->VersionFoundCount) {
+ case 4:
+ this->VersionFoundTweak = parsed_tweak; // no break!
+ case 3:
+ this->VersionFoundPatch = parsed_patch; // no break!
+ case 2:
+ this->VersionFoundMinor = parsed_minor; // no break!
+ case 1:
+ this->VersionFoundMajor = parsed_major; // no break!
+ default:
+ break;
}
}
+ }
result_version = this->Makefile->GetSafeDefinition("PACKAGE_VERSION");
- if (result_version.empty())
- {
+ if (result_version.empty()) {
result_version = "unknown";
- }
+ }
// Succeed if the version is suitable.
return suitable;
@@ -1639,27 +1469,24 @@ void cmFindPackageCommand::StoreVersionFound()
// Store the whole version string.
std::string ver = this->Name;
ver += "_VERSION";
- if(this->VersionFound.empty())
- {
+ if (this->VersionFound.empty()) {
this->Makefile->RemoveDefinition(ver);
- }
- else
- {
+ } else {
this->Makefile->AddDefinition(ver, this->VersionFound.c_str());
- }
+ }
// Store the version components.
char buf[64];
sprintf(buf, "%u", this->VersionFoundMajor);
- this->Makefile->AddDefinition(ver+"_MAJOR", buf);
+ this->Makefile->AddDefinition(ver + "_MAJOR", buf);
sprintf(buf, "%u", this->VersionFoundMinor);
- this->Makefile->AddDefinition(ver+"_MINOR", buf);
+ this->Makefile->AddDefinition(ver + "_MINOR", buf);
sprintf(buf, "%u", this->VersionFoundPatch);
- this->Makefile->AddDefinition(ver+"_PATCH", buf);
+ this->Makefile->AddDefinition(ver + "_PATCH", buf);
sprintf(buf, "%u", this->VersionFoundTweak);
- this->Makefile->AddDefinition(ver+"_TWEAK", buf);
+ this->Makefile->AddDefinition(ver + "_TWEAK", buf);
sprintf(buf, "%u", this->VersionFoundCount);
- this->Makefile->AddDefinition(ver+"_COUNT", buf);
+ this->Makefile->AddDefinition(ver + "_COUNT", buf);
}
#include <cmsys/Glob.hxx>
@@ -1673,6 +1500,7 @@ public:
virtual ~cmFileListGeneratorBase() {}
protected:
bool Consider(std::string const& fullPath, cmFileList& listing);
+
private:
bool Search(cmFileList&);
virtual bool Search(std::string const& parent, cmFileList&) = 0;
@@ -1685,29 +1513,30 @@ private:
class cmFileList
{
public:
- cmFileList(): First(), Last(0) {}
+ cmFileList()
+ : First()
+ , Last(0)
+ {
+ }
virtual ~cmFileList() {}
cmFileList& operator/(cmFileListGeneratorBase const& rhs)
- {
- if(this->Last)
- {
+ {
+ if (this->Last) {
this->Last = this->Last->SetNext(rhs);
- }
- else
- {
+ } else {
this->First = rhs.Clone();
this->Last = this->First.get();
- }
- return *this;
}
+ return *this;
+ }
bool Search()
- {
- if(this->First.get())
- {
+ {
+ if (this->First.get()) {
return this->First->Search(*this);
- }
- return false;
}
+ return false;
+ }
+
private:
virtual bool Visit(std::string const& fullPath) = 0;
friend class cmFileListGeneratorBase;
@@ -1715,24 +1544,25 @@ private:
cmFileListGeneratorBase* Last;
};
-class cmFindPackageFileList: public cmFileList
+class cmFindPackageFileList : public cmFileList
{
public:
- cmFindPackageFileList(cmFindPackageCommand* fpc,
- bool use_suffixes = true):
- cmFileList(), FPC(fpc), UseSuffixes(use_suffixes) {}
+ cmFindPackageFileList(cmFindPackageCommand* fpc, bool use_suffixes = true)
+ : cmFileList()
+ , FPC(fpc)
+ , UseSuffixes(use_suffixes)
+ {
+ }
+
private:
bool Visit(std::string const& fullPath)
- {
- if(this->UseSuffixes)
- {
+ {
+ if (this->UseSuffixes) {
return this->FPC->SearchDirectory(fullPath);
- }
- else
- {
+ } else {
return this->FPC->CheckDirectory(fullPath);
- }
}
+ }
cmFindPackageCommand* FPC;
bool UseSuffixes;
};
@@ -1742,8 +1572,8 @@ bool cmFileListGeneratorBase::Search(cmFileList& listing)
return this->Search("", listing);
}
-cmFileListGeneratorBase*
-cmFileListGeneratorBase::SetNext(cmFileListGeneratorBase const& next)
+cmFileListGeneratorBase* cmFileListGeneratorBase::SetNext(
+ cmFileListGeneratorBase const& next)
{
this->Next = next.Clone();
return this->Next.get();
@@ -1752,371 +1582,369 @@ cmFileListGeneratorBase::SetNext(cmFileListGeneratorBase const& next)
bool cmFileListGeneratorBase::Consider(std::string const& fullPath,
cmFileList& listing)
{
- if(this->Next.get())
- {
+ if (this->Next.get()) {
return this->Next->Search(fullPath + "/", listing);
- }
- else
- {
+ } else {
return listing.Visit(fullPath + "/");
- }
+ }
}
-class cmFileListGeneratorFixed: public cmFileListGeneratorBase
+class cmFileListGeneratorFixed : public cmFileListGeneratorBase
{
public:
- cmFileListGeneratorFixed(std::string const& str):
- cmFileListGeneratorBase(), String(str) {}
- cmFileListGeneratorFixed(cmFileListGeneratorFixed const& r):
- cmFileListGeneratorBase(), String(r.String) {}
+ cmFileListGeneratorFixed(std::string const& str)
+ : cmFileListGeneratorBase()
+ , String(str)
+ {
+ }
+ cmFileListGeneratorFixed(cmFileListGeneratorFixed const& r)
+ : cmFileListGeneratorBase()
+ , String(r.String)
+ {
+ }
+
private:
std::string String;
virtual bool Search(std::string const& parent, cmFileList& lister)
- {
+ {
std::string fullPath = parent + this->String;
return this->Consider(fullPath, lister);
- }
+ }
virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
- {
- cmsys::auto_ptr<cmFileListGeneratorBase>
- g(new cmFileListGeneratorFixed(*this));
+ {
+ cmsys::auto_ptr<cmFileListGeneratorBase> g(
+ new cmFileListGeneratorFixed(*this));
return g;
- }
+ }
};
-class cmFileListGeneratorEnumerate: public cmFileListGeneratorBase
+class cmFileListGeneratorEnumerate : public cmFileListGeneratorBase
{
public:
- cmFileListGeneratorEnumerate(std::vector<std::string> const& v):
- cmFileListGeneratorBase(), Vector(v) {}
- cmFileListGeneratorEnumerate(cmFileListGeneratorEnumerate const& r):
- cmFileListGeneratorBase(), Vector(r.Vector) {}
+ cmFileListGeneratorEnumerate(std::vector<std::string> const& v)
+ : cmFileListGeneratorBase()
+ , Vector(v)
+ {
+ }
+ cmFileListGeneratorEnumerate(cmFileListGeneratorEnumerate const& r)
+ : cmFileListGeneratorBase()
+ , Vector(r.Vector)
+ {
+ }
+
private:
std::vector<std::string> const& Vector;
virtual bool Search(std::string const& parent, cmFileList& lister)
- {
- for(std::vector<std::string>::const_iterator i = this->Vector.begin();
- i != this->Vector.end(); ++i)
- {
- if(this->Consider(parent + *i, lister))
- {
+ {
+ for (std::vector<std::string>::const_iterator i = this->Vector.begin();
+ i != this->Vector.end(); ++i) {
+ if (this->Consider(parent + *i, lister)) {
return true;
- }
}
- return false;
}
+ return false;
+ }
virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
- {
- cmsys::auto_ptr<cmFileListGeneratorBase>
- g(new cmFileListGeneratorEnumerate(*this));
+ {
+ cmsys::auto_ptr<cmFileListGeneratorBase> g(
+ new cmFileListGeneratorEnumerate(*this));
return g;
- }
+ }
};
-class cmFileListGeneratorProject: public cmFileListGeneratorBase
+class cmFileListGeneratorProject : public cmFileListGeneratorBase
{
public:
- cmFileListGeneratorProject(std::vector<std::string> const& names):
- cmFileListGeneratorBase(), Names(names) {}
- cmFileListGeneratorProject(cmFileListGeneratorProject const& r):
- cmFileListGeneratorBase(), Names(r.Names) {}
+ cmFileListGeneratorProject(std::vector<std::string> const& names)
+ : cmFileListGeneratorBase()
+ , Names(names)
+ {
+ }
+ cmFileListGeneratorProject(cmFileListGeneratorProject const& r)
+ : cmFileListGeneratorBase()
+ , Names(r.Names)
+ {
+ }
+
private:
std::vector<std::string> const& Names;
virtual bool Search(std::string const& parent, cmFileList& lister)
- {
+ {
// Construct a list of matches.
std::vector<std::string> matches;
cmsys::Directory d;
d.Load(parent);
- for(unsigned long i=0; i < d.GetNumberOfFiles(); ++i)
- {
+ for (unsigned long i = 0; i < d.GetNumberOfFiles(); ++i) {
const char* fname = d.GetFile(i);
- if(strcmp(fname, ".") == 0 ||
- strcmp(fname, "..") == 0)
- {
+ if (strcmp(fname, ".") == 0 || strcmp(fname, "..") == 0) {
continue;
- }
- for(std::vector<std::string>::const_iterator ni = this->Names.begin();
- ni != this->Names.end(); ++ni)
- {
- if(cmsysString_strncasecmp(fname, ni->c_str(),
- ni->length()) == 0)
- {
+ }
+ for (std::vector<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end(); ++ni) {
+ if (cmsysString_strncasecmp(fname, ni->c_str(), ni->length()) == 0) {
matches.push_back(fname);
- }
}
}
+ }
- for(std::vector<std::string>::const_iterator i = matches.begin();
- i != matches.end(); ++i)
- {
- if(this->Consider(parent + *i, lister))
- {
+ for (std::vector<std::string>::const_iterator i = matches.begin();
+ i != matches.end(); ++i) {
+ if (this->Consider(parent + *i, lister)) {
return true;
- }
}
- return false;
}
+ return false;
+ }
virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
- {
- cmsys::auto_ptr<cmFileListGeneratorBase>
- g(new cmFileListGeneratorProject(*this));
+ {
+ cmsys::auto_ptr<cmFileListGeneratorBase> g(
+ new cmFileListGeneratorProject(*this));
return g;
- }
+ }
};
-class cmFileListGeneratorMacProject: public cmFileListGeneratorBase
+class cmFileListGeneratorMacProject : public cmFileListGeneratorBase
{
public:
cmFileListGeneratorMacProject(std::vector<std::string> const& names,
- const char* ext):
- cmFileListGeneratorBase(), Names(names), Extension(ext) {}
- cmFileListGeneratorMacProject(cmFileListGeneratorMacProject const& r):
- cmFileListGeneratorBase(), Names(r.Names), Extension(r.Extension) {}
+ const char* ext)
+ : cmFileListGeneratorBase()
+ , Names(names)
+ , Extension(ext)
+ {
+ }
+ cmFileListGeneratorMacProject(cmFileListGeneratorMacProject const& r)
+ : cmFileListGeneratorBase()
+ , Names(r.Names)
+ , Extension(r.Extension)
+ {
+ }
+
private:
std::vector<std::string> const& Names;
std::string Extension;
virtual bool Search(std::string const& parent, cmFileList& lister)
- {
+ {
// Construct a list of matches.
std::vector<std::string> matches;
cmsys::Directory d;
d.Load(parent);
- for(unsigned long i=0; i < d.GetNumberOfFiles(); ++i)
- {
+ for (unsigned long i = 0; i < d.GetNumberOfFiles(); ++i) {
const char* fname = d.GetFile(i);
- if(strcmp(fname, ".") == 0 ||
- strcmp(fname, "..") == 0)
- {
+ if (strcmp(fname, ".") == 0 || strcmp(fname, "..") == 0) {
continue;
- }
- for(std::vector<std::string>::const_iterator ni = this->Names.begin();
- ni != this->Names.end(); ++ni)
- {
+ }
+ for (std::vector<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end(); ++ni) {
std::string name = *ni;
name += this->Extension;
- if(cmsysString_strcasecmp(fname, name.c_str()) == 0)
- {
+ if (cmsysString_strcasecmp(fname, name.c_str()) == 0) {
matches.push_back(fname);
- }
}
}
+ }
- for(std::vector<std::string>::const_iterator i = matches.begin();
- i != matches.end(); ++i)
- {
- if(this->Consider(parent + *i, lister))
- {
+ for (std::vector<std::string>::const_iterator i = matches.begin();
+ i != matches.end(); ++i) {
+ if (this->Consider(parent + *i, lister)) {
return true;
- }
}
- return false;
}
+ return false;
+ }
virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
- {
- cmsys::auto_ptr<cmFileListGeneratorBase>
- g(new cmFileListGeneratorMacProject(*this));
+ {
+ cmsys::auto_ptr<cmFileListGeneratorBase> g(
+ new cmFileListGeneratorMacProject(*this));
return g;
- }
+ }
};
-class cmFileListGeneratorCaseInsensitive: public cmFileListGeneratorBase
+class cmFileListGeneratorCaseInsensitive : public cmFileListGeneratorBase
{
public:
- cmFileListGeneratorCaseInsensitive(std::string const& str):
- cmFileListGeneratorBase(), String(str) {}
+ cmFileListGeneratorCaseInsensitive(std::string const& str)
+ : cmFileListGeneratorBase()
+ , String(str)
+ {
+ }
cmFileListGeneratorCaseInsensitive(
- cmFileListGeneratorCaseInsensitive const& r):
- cmFileListGeneratorBase(), String(r.String) {}
+ cmFileListGeneratorCaseInsensitive const& r)
+ : cmFileListGeneratorBase()
+ , String(r.String)
+ {
+ }
+
private:
std::string String;
virtual bool Search(std::string const& parent, cmFileList& lister)
- {
+ {
// Look for matching files.
std::vector<std::string> matches;
cmsys::Directory d;
d.Load(parent);
- for(unsigned long i=0; i < d.GetNumberOfFiles(); ++i)
- {
+ for (unsigned long i = 0; i < d.GetNumberOfFiles(); ++i) {
const char* fname = d.GetFile(i);
- if(strcmp(fname, ".") == 0 ||
- strcmp(fname, "..") == 0)
- {
+ if (strcmp(fname, ".") == 0 || strcmp(fname, "..") == 0) {
continue;
- }
- if(cmsysString_strcasecmp(fname, this->String.c_str()) == 0)
- {
- if(this->Consider(parent + fname, lister))
- {
+ }
+ if (cmsysString_strcasecmp(fname, this->String.c_str()) == 0) {
+ if (this->Consider(parent + fname, lister)) {
return true;
- }
}
}
- return false;
}
+ return false;
+ }
virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
- {
- cmsys::auto_ptr<cmFileListGeneratorBase>
- g(new cmFileListGeneratorCaseInsensitive(*this));
+ {
+ cmsys::auto_ptr<cmFileListGeneratorBase> g(
+ new cmFileListGeneratorCaseInsensitive(*this));
return g;
- }
+ }
};
-class cmFileListGeneratorGlob: public cmFileListGeneratorBase
+class cmFileListGeneratorGlob : public cmFileListGeneratorBase
{
public:
- cmFileListGeneratorGlob(std::string const& str):
- cmFileListGeneratorBase(), Pattern(str) {}
- cmFileListGeneratorGlob(cmFileListGeneratorGlob const& r):
- cmFileListGeneratorBase(), Pattern(r.Pattern) {}
+ cmFileListGeneratorGlob(std::string const& str)
+ : cmFileListGeneratorBase()
+ , Pattern(str)
+ {
+ }
+ cmFileListGeneratorGlob(cmFileListGeneratorGlob const& r)
+ : cmFileListGeneratorBase()
+ , Pattern(r.Pattern)
+ {
+ }
+
private:
std::string Pattern;
virtual bool Search(std::string const& parent, cmFileList& lister)
- {
+ {
// Glob the set of matching files.
std::string expr = parent;
expr += this->Pattern;
cmsys::Glob g;
- if(!g.FindFiles(expr))
- {
+ if (!g.FindFiles(expr)) {
return false;
- }
+ }
std::vector<std::string> const& files = g.GetFiles();
// Look for directories among the matches.
- for(std::vector<std::string>::const_iterator fi = files.begin();
- fi != files.end(); ++fi)
- {
- if(cmSystemTools::FileIsDirectory(*fi))
- {
- if(this->Consider(*fi, lister))
- {
+ for (std::vector<std::string>::const_iterator fi = files.begin();
+ fi != files.end(); ++fi) {
+ if (cmSystemTools::FileIsDirectory(*fi)) {
+ if (this->Consider(*fi, lister)) {
return true;
- }
}
}
- return false;
}
+ return false;
+ }
virtual cmsys::auto_ptr<cmFileListGeneratorBase> Clone() const
- {
- cmsys::auto_ptr<cmFileListGeneratorBase>
- g(new cmFileListGeneratorGlob(*this));
+ {
+ cmsys::auto_ptr<cmFileListGeneratorBase> g(
+ new cmFileListGeneratorGlob(*this));
return g;
- }
+ }
};
bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
{
- assert(!prefix_in.empty() && prefix_in[prefix_in.size()-1] == '/');
- if(this->DebugMode)
- {
+ assert(!prefix_in.empty() && prefix_in[prefix_in.size() - 1] == '/');
+ if (this->DebugMode) {
fprintf(stderr, "Checking prefix [%s]\n", prefix_in.c_str());
- }
+ }
// Skip this if the prefix does not exist.
- if(!cmSystemTools::FileIsDirectory(prefix_in))
- {
+ if (!cmSystemTools::FileIsDirectory(prefix_in)) {
return false;
- }
+ }
// PREFIX/ (useful on windows or in build trees)
- if(this->SearchDirectory(prefix_in))
- {
+ if (this->SearchDirectory(prefix_in)) {
return true;
- }
+ }
// Strip the trailing slash because the path generator is about to
// add one.
- std::string prefix = prefix_in.substr(0, prefix_in.size()-1);
+ std::string prefix = prefix_in.substr(0, prefix_in.size() - 1);
// PREFIX/(cmake|CMake)/ (useful on windows or in build trees)
{
- cmFindPackageFileList lister(this);
- lister
- / cmFileListGeneratorFixed(prefix)
- / cmFileListGeneratorCaseInsensitive("cmake");
- if(lister.Search())
- {
- return true;
+ cmFindPackageFileList lister(this);
+ lister / cmFileListGeneratorFixed(prefix) /
+ cmFileListGeneratorCaseInsensitive("cmake");
+ if (lister.Search()) {
+ return true;
}
}
// PREFIX/(Foo|foo|FOO).*/
{
- cmFindPackageFileList lister(this);
- lister
- / cmFileListGeneratorFixed(prefix)
- / cmFileListGeneratorProject(this->Names);
- if(lister.Search())
- {
- return true;
+ cmFindPackageFileList lister(this);
+ lister / cmFileListGeneratorFixed(prefix) /
+ cmFileListGeneratorProject(this->Names);
+ if (lister.Search()) {
+ return true;
}
}
// PREFIX/(Foo|foo|FOO).*/(cmake|CMake)/
{
- cmFindPackageFileList lister(this);
- lister
- / cmFileListGeneratorFixed(prefix)
- / cmFileListGeneratorProject(this->Names)
- / cmFileListGeneratorCaseInsensitive("cmake");
- if(lister.Search())
- {
- return true;
+ cmFindPackageFileList lister(this);
+ lister / cmFileListGeneratorFixed(prefix) /
+ cmFileListGeneratorProject(this->Names) /
+ cmFileListGeneratorCaseInsensitive("cmake");
+ if (lister.Search()) {
+ return true;
}
}
// Construct list of common install locations (lib and share).
std::vector<std::string> common;
- if(!this->LibraryArchitecture.empty())
- {
- common.push_back("lib/"+this->LibraryArchitecture);
- }
- if(this->UseLib64Paths)
- {
+ if (!this->LibraryArchitecture.empty()) {
+ common.push_back("lib/" + this->LibraryArchitecture);
+ }
+ if (this->UseLib64Paths) {
common.push_back("lib64");
- }
+ }
common.push_back("lib");
common.push_back("share");
// PREFIX/(lib/ARCH|lib|share)/cmake/(Foo|foo|FOO).*/
{
- cmFindPackageFileList lister(this);
- lister
- / cmFileListGeneratorFixed(prefix)
- / cmFileListGeneratorEnumerate(common)
- / cmFileListGeneratorFixed("cmake")
- / cmFileListGeneratorProject(this->Names);
- if(lister.Search())
- {
- return true;
+ cmFindPackageFileList lister(this);
+ lister / cmFileListGeneratorFixed(prefix) /
+ cmFileListGeneratorEnumerate(common) /
+ cmFileListGeneratorFixed("cmake") /
+ cmFileListGeneratorProject(this->Names);
+ if (lister.Search()) {
+ return true;
}
}
// PREFIX/(lib/ARCH|lib|share)/(Foo|foo|FOO).*/
{
- cmFindPackageFileList lister(this);
- lister
- / cmFileListGeneratorFixed(prefix)
- / cmFileListGeneratorEnumerate(common)
- / cmFileListGeneratorProject(this->Names);
- if(lister.Search())
- {
- return true;
+ cmFindPackageFileList lister(this);
+ lister / cmFileListGeneratorFixed(prefix) /
+ cmFileListGeneratorEnumerate(common) /
+ cmFileListGeneratorProject(this->Names);
+ if (lister.Search()) {
+ return true;
}
}
// PREFIX/(lib/ARCH|lib|share)/(Foo|foo|FOO).*/(cmake|CMake)/
{
- cmFindPackageFileList lister(this);
- lister
- / cmFileListGeneratorFixed(prefix)
- / cmFileListGeneratorEnumerate(common)
- / cmFileListGeneratorProject(this->Names)
- / cmFileListGeneratorCaseInsensitive("cmake");
- if(lister.Search())
- {
- return true;
+ cmFindPackageFileList lister(this);
+ lister / cmFileListGeneratorFixed(prefix) /
+ cmFileListGeneratorEnumerate(common) /
+ cmFileListGeneratorProject(this->Names) /
+ cmFileListGeneratorCaseInsensitive("cmake");
+ if (lister.Search()) {
+ return true;
}
}
@@ -2125,68 +1953,59 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
bool cmFindPackageCommand::SearchFrameworkPrefix(std::string const& prefix_in)
{
- assert(!prefix_in.empty() && prefix_in[prefix_in.size()-1] == '/');
- if(this->DebugMode)
- {
+ assert(!prefix_in.empty() && prefix_in[prefix_in.size() - 1] == '/');
+ if (this->DebugMode) {
fprintf(stderr, "Checking framework prefix [%s]\n", prefix_in.c_str());
- }
+ }
// Strip the trailing slash because the path generator is about to
// add one.
- std::string prefix = prefix_in.substr(0, prefix_in.size()-1);
+ std::string prefix = prefix_in.substr(0, prefix_in.size() - 1);
// <prefix>/Foo.framework/Resources/
{
- cmFindPackageFileList lister(this);
- lister
- / cmFileListGeneratorFixed(prefix)
- / cmFileListGeneratorMacProject(this->Names, ".framework")
- / cmFileListGeneratorFixed("Resources");
- if(lister.Search())
- {
- return true;
+ cmFindPackageFileList lister(this);
+ lister / cmFileListGeneratorFixed(prefix) /
+ cmFileListGeneratorMacProject(this->Names, ".framework") /
+ cmFileListGeneratorFixed("Resources");
+ if (lister.Search()) {
+ return true;
}
}
// <prefix>/Foo.framework/Resources/CMake/
{
- cmFindPackageFileList lister(this);
- lister
- / cmFileListGeneratorFixed(prefix)
- / cmFileListGeneratorMacProject(this->Names, ".framework")
- / cmFileListGeneratorFixed("Resources")
- / cmFileListGeneratorCaseInsensitive("cmake");
- if(lister.Search())
- {
- return true;
+ cmFindPackageFileList lister(this);
+ lister / cmFileListGeneratorFixed(prefix) /
+ cmFileListGeneratorMacProject(this->Names, ".framework") /
+ cmFileListGeneratorFixed("Resources") /
+ cmFileListGeneratorCaseInsensitive("cmake");
+ if (lister.Search()) {
+ return true;
}
}
// <prefix>/Foo.framework/Versions/*/Resources/
{
- cmFindPackageFileList lister(this);
- lister
- / cmFileListGeneratorFixed(prefix)
- / cmFileListGeneratorMacProject(this->Names, ".framework")
- / cmFileListGeneratorFixed("Versions")
- / cmFileListGeneratorGlob("*/Resources");
- if(lister.Search())
- {
- return true;
+ cmFindPackageFileList lister(this);
+ lister / cmFileListGeneratorFixed(prefix) /
+ cmFileListGeneratorMacProject(this->Names, ".framework") /
+ cmFileListGeneratorFixed("Versions") /
+ cmFileListGeneratorGlob("*/Resources");
+ if (lister.Search()) {
+ return true;
}
}
// <prefix>/Foo.framework/Versions/*/Resources/CMake/
{
- cmFindPackageFileList lister(this);
- lister
- / cmFileListGeneratorFixed(prefix)
- / cmFileListGeneratorMacProject(this->Names, ".framework")
- / cmFileListGeneratorFixed("Versions")
- / cmFileListGeneratorGlob("*/Resources")
- / cmFileListGeneratorCaseInsensitive("cmake");
- if(lister.Search())
- {
- return true;
+ cmFindPackageFileList lister(this);
+ lister / cmFileListGeneratorFixed(prefix) /
+ cmFileListGeneratorMacProject(this->Names, ".framework") /
+ cmFileListGeneratorFixed("Versions") /
+ cmFileListGeneratorGlob("*/Resources") /
+ cmFileListGeneratorCaseInsensitive("cmake");
+ if (lister.Search()) {
+ return true;
}
}
@@ -2195,40 +2014,35 @@ bool cmFindPackageCommand::SearchFrameworkPrefix(std::string const& prefix_in)
bool cmFindPackageCommand::SearchAppBundlePrefix(std::string const& prefix_in)
{
- assert(!prefix_in.empty() && prefix_in[prefix_in.size()-1] == '/');
- if(this->DebugMode)
- {
+ assert(!prefix_in.empty() && prefix_in[prefix_in.size() - 1] == '/');
+ if (this->DebugMode) {
fprintf(stderr, "Checking bundle prefix [%s]\n", prefix_in.c_str());
- }
+ }
// Strip the trailing slash because the path generator is about to
// add one.
- std::string prefix = prefix_in.substr(0, prefix_in.size()-1);
+ std::string prefix = prefix_in.substr(0, prefix_in.size() - 1);
// <prefix>/Foo.app/Contents/Resources
{
- cmFindPackageFileList lister(this);
- lister
- / cmFileListGeneratorFixed(prefix)
- / cmFileListGeneratorMacProject(this->Names, ".app")
- / cmFileListGeneratorFixed("Contents/Resources");
- if(lister.Search())
- {
- return true;
+ cmFindPackageFileList lister(this);
+ lister / cmFileListGeneratorFixed(prefix) /
+ cmFileListGeneratorMacProject(this->Names, ".app") /
+ cmFileListGeneratorFixed("Contents/Resources");
+ if (lister.Search()) {
+ return true;
}
}
// <prefix>/Foo.app/Contents/Resources/CMake
{
- cmFindPackageFileList lister(this);
- lister
- / cmFileListGeneratorFixed(prefix)
- / cmFileListGeneratorMacProject(this->Names, ".app")
- / cmFileListGeneratorFixed("Contents/Resources")
- / cmFileListGeneratorCaseInsensitive("cmake");
- if(lister.Search())
- {
- return true;
+ cmFindPackageFileList lister(this);
+ lister / cmFileListGeneratorFixed(prefix) /
+ cmFileListGeneratorMacProject(this->Names, ".app") /
+ cmFileListGeneratorFixed("Contents/Resources") /
+ cmFileListGeneratorCaseInsensitive("cmake");
+ if (lister.Search()) {
+ return true;
}
}