diff options
author | Kitware Robot <kwrobot@kitware.com> | 2016-05-16 14:34:04 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-05-16 20:05:19 (GMT) |
commit | d9fd2f5402eeaa345691313658e02b51038f570b (patch) | |
tree | dca71b9a7e267f4c6300da3eb770415381726785 /Source/cmFindLibraryCommand.cxx | |
parent | 82df6deaafb36cbbfd450202bb20b320f637751a (diff) | |
download | CMake-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/cmFindLibraryCommand.cxx')
-rw-r--r-- | Source/cmFindLibraryCommand.cxx | 322 |
1 files changed, 134 insertions, 188 deletions
diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index a37b0bd..a4d4dbb 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -20,63 +20,53 @@ cmFindLibraryCommand::cmFindLibraryCommand() } // cmFindLibraryCommand -bool cmFindLibraryCommand -::InitialPass(std::vector<std::string> const& argsIn, cmExecutionStatus &) +bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn, + cmExecutionStatus&) { this->VariableDocumentation = "Path to a library."; this->CMakePathName = "LIBRARY"; - if(!this->ParseArguments(argsIn)) - { + if (!this->ParseArguments(argsIn)) { return false; - } - if(this->AlreadyInCache) - { + } + if (this->AlreadyInCache) { // If the user specifies the entry on the command line without a // type we should add the type and docstring but keep the original // value. - if(this->AlreadyInCacheWithoutMetaInfo) - { + if (this->AlreadyInCacheWithoutMetaInfo) { this->Makefile->AddCacheDefinition(this->VariableName, "", this->VariableDocumentation.c_str(), cmState::FILEPATH); - } - return true; } + return true; + } - if(const char* abi_name = - this->Makefile->GetDefinition("CMAKE_INTERNAL_PLATFORM_ABI")) - { + if (const char* abi_name = + this->Makefile->GetDefinition("CMAKE_INTERNAL_PLATFORM_ABI")) { std::string abi = abi_name; - if(abi.find("ELF N32") != abi.npos) - { + if (abi.find("ELF N32") != abi.npos) { // Convert lib to lib32. this->AddArchitecturePaths("32"); - } } + } - if(this->Makefile->GetState() - ->GetGlobalPropertyAsBool("FIND_LIBRARY_USE_LIB64_PATHS")) - { + if (this->Makefile->GetState()->GetGlobalPropertyAsBool( + "FIND_LIBRARY_USE_LIB64_PATHS")) { // add special 64 bit paths if this is a 64 bit compile. - if(this->Makefile->PlatformIs64Bit()) - { + if (this->Makefile->PlatformIs64Bit()) { this->AddArchitecturePaths("64"); - } } + } std::string library = this->FindLibrary(); - if(library != "") - { + if (library != "") { // Save the value in the cache - this->Makefile->AddCacheDefinition(this->VariableName, - library.c_str(), + this->Makefile->AddCacheDefinition(this->VariableName, library.c_str(), this->VariableDocumentation.c_str(), cmState::FILEPATH); return true; - } + } std::string notfound = this->VariableName + "-NOTFOUND"; - this->Makefile->AddCacheDefinition(this->VariableName, - notfound.c_str(), + this->Makefile->AddCacheDefinition(this->VariableName, notfound.c_str(), this->VariableDocumentation.c_str(), cmState::FILEPATH); return true; @@ -86,69 +76,59 @@ void cmFindLibraryCommand::AddArchitecturePaths(const char* suffix) { std::vector<std::string> original; original.swap(this->SearchPaths); - for(std::vector<std::string>::const_iterator i = original.begin(); - i != original.end(); ++i) - { + for (std::vector<std::string>::const_iterator i = original.begin(); + i != original.end(); ++i) { this->AddArchitecturePath(*i, 0, suffix); - } + } } void cmFindLibraryCommand::AddArchitecturePath( - std::string const& dir, std::string::size_type start_pos, - const char* suffix, bool fresh) + std::string const& dir, std::string::size_type start_pos, const char* suffix, + bool fresh) { std::string::size_type pos = dir.find("lib/", start_pos); - if(pos != std::string::npos) - { - std::string cur_dir = dir.substr(0,pos+3); + if (pos != std::string::npos) { + std::string cur_dir = dir.substr(0, pos + 3); // Follow "lib<suffix>". std::string next_dir = cur_dir + suffix; - if(cmSystemTools::FileIsDirectory(next_dir)) - { - next_dir += dir.substr(pos+3); - std::string::size_type next_pos = pos+3+strlen(suffix)+1; + if (cmSystemTools::FileIsDirectory(next_dir)) { + next_dir += dir.substr(pos + 3); + std::string::size_type next_pos = pos + 3 + strlen(suffix) + 1; this->AddArchitecturePath(next_dir, next_pos, suffix); - } + } // Follow "lib". - if(cmSystemTools::FileIsDirectory(cur_dir)) - { - this->AddArchitecturePath(dir, pos+3+1, suffix, false); - } + if (cmSystemTools::FileIsDirectory(cur_dir)) { + this->AddArchitecturePath(dir, pos + 3 + 1, suffix, false); } - if(fresh) - { + } + if (fresh) { // Check for <dir><suffix>/. - std::string cur_dir = dir + suffix + "/"; - if(cmSystemTools::FileIsDirectory(cur_dir)) - { + std::string cur_dir = dir + suffix + "/"; + if (cmSystemTools::FileIsDirectory(cur_dir)) { this->SearchPaths.push_back(cur_dir); - } + } // Now add the original unchanged path - if(cmSystemTools::FileIsDirectory(dir)) - { + if (cmSystemTools::FileIsDirectory(dir)) { this->SearchPaths.push_back(dir); - } } + } } std::string cmFindLibraryCommand::FindLibrary() { std::string library; - if(this->SearchFrameworkFirst || this->SearchFrameworkOnly) - { + if (this->SearchFrameworkFirst || this->SearchFrameworkOnly) { library = this->FindFrameworkLibrary(); - } - if(library.empty() && !this->SearchFrameworkOnly) - { + } + if (library.empty() && !this->SearchFrameworkOnly) { library = this->FindNormalLibrary(); - } - if(library.empty() && this->SearchFrameworkLast) - { + } + if (library.empty() && this->SearchFrameworkLast) { library = this->FindFrameworkLibrary(); - } + } return library; } @@ -179,7 +159,10 @@ struct cmFindLibraryHelper bool TryRaw; std::string Raw; cmsys::RegularExpression Regex; - Name(): TryRaw(false) {} + Name() + : TryRaw(false) + { + } }; std::vector<Name> Names; @@ -189,15 +172,15 @@ struct cmFindLibraryHelper void RegexFromLiteral(std::string& out, std::string const& in); void RegexFromList(std::string& out, std::vector<std::string> const& in); size_type GetPrefixIndex(std::string const& prefix) - { - return std::find(this->Prefixes.begin(), this->Prefixes.end(), - prefix) - this->Prefixes.begin(); - } + { + return std::find(this->Prefixes.begin(), this->Prefixes.end(), prefix) - + this->Prefixes.begin(); + } size_type GetSuffixIndex(std::string const& suffix) - { - return std::find(this->Suffixes.begin(), this->Suffixes.end(), - suffix) - this->Suffixes.begin(); - } + { + return std::find(this->Suffixes.begin(), this->Suffixes.end(), suffix) - + this->Suffixes.begin(); + } bool HasValidSuffix(std::string const& name); void AddName(std::string const& name); void SetName(std::string const& name); @@ -205,8 +188,8 @@ struct cmFindLibraryHelper bool CheckDirectoryForName(std::string const& path, Name& name); }; -cmFindLibraryHelper::cmFindLibraryHelper(cmMakefile* mf): - Makefile(mf) +cmFindLibraryHelper::cmFindLibraryHelper(cmMakefile* mf) + : Makefile(mf) { this->GG = this->Makefile->GetGlobalGenerator(); @@ -221,29 +204,26 @@ cmFindLibraryHelper::cmFindLibraryHelper(cmMakefile* mf): this->RegexFromList(this->SuffixRegexStr, this->Suffixes); // Check whether to use OpenBSD-style library version comparisons. - this->OpenBSD = - this->Makefile->GetState() - ->GetGlobalPropertyAsBool("FIND_LIBRARY_USE_OPENBSD_VERSIONING"); + this->OpenBSD = this->Makefile->GetState()->GetGlobalPropertyAsBool( + "FIND_LIBRARY_USE_OPENBSD_VERSIONING"); } void cmFindLibraryHelper::RegexFromLiteral(std::string& out, std::string const& in) { - for(std::string::const_iterator ci = in.begin(); ci != in.end(); ++ci) - { + for (std::string::const_iterator ci = in.begin(); ci != in.end(); ++ci) { char ch = *ci; - if(ch == '[' || ch == ']' || ch == '(' || ch == ')' || ch == '\\' || - ch == '.' || ch == '*' || ch == '+' || ch == '?' || ch == '-' || - ch == '^' || ch == '$') - { + if (ch == '[' || ch == ']' || ch == '(' || ch == ')' || ch == '\\' || + ch == '.' || ch == '*' || ch == '+' || ch == '?' || ch == '-' || + ch == '^' || ch == '$') { out += "\\"; - } + } #if defined(_WIN32) || defined(__APPLE__) out += tolower(ch); #else out += ch; #endif - } + } } void cmFindLibraryHelper::RegexFromList(std::string& out, @@ -253,42 +233,37 @@ void cmFindLibraryHelper::RegexFromList(std::string& out, // else and the result can be checked after matching. out += "("; const char* sep = ""; - for(std::vector<std::string>::const_iterator si = in.begin(); - si != in.end(); ++si) - { + for (std::vector<std::string>::const_iterator si = in.begin(); + si != in.end(); ++si) { // Separate from previous item. out += sep; sep = "|"; // Append this item. this->RegexFromLiteral(out, *si); - } + } out += ")"; } bool cmFindLibraryHelper::HasValidSuffix(std::string const& name) { - for(std::vector<std::string>::const_iterator si = this->Suffixes.begin(); - si != this->Suffixes.end(); ++si) - { + for (std::vector<std::string>::const_iterator si = this->Suffixes.begin(); + si != this->Suffixes.end(); ++si) { std::string suffix = *si; - if(name.length() <= suffix.length()) - { + if (name.length() <= suffix.length()) { continue; - } + } // Check if the given name ends in a valid library suffix. - if(name.substr(name.size()-suffix.length()) == suffix) - { + if (name.substr(name.size() - suffix.length()) == suffix) { return true; - } + } // Check if a valid library suffix is somewhere in the name, // this may happen e.g. for versioned shared libraries: libfoo.so.2 suffix += "."; - if(name.find(suffix) != name.npos) - { + if (name.find(suffix) != name.npos) { return true; - } } + } return false; } @@ -305,10 +280,9 @@ void cmFindLibraryHelper::AddName(std::string const& name) regex += this->PrefixRegexStr; this->RegexFromLiteral(regex, name); regex += this->SuffixRegexStr; - if(this->OpenBSD) - { + if (this->OpenBSD) { regex += "(\\.[0-9]+\\.[0-9]+)?"; - } + } regex += "$"; entry.Regex.compile(regex.c_str()); this->Names.push_back(entry); @@ -322,14 +296,12 @@ void cmFindLibraryHelper::SetName(std::string const& name) bool cmFindLibraryHelper::CheckDirectory(std::string const& path) { - for(std::vector<Name>::iterator i = this->Names.begin(); - i != this->Names.end(); ++i) - { - if(this->CheckDirectoryForName(path, *i)) - { + for (std::vector<Name>::iterator i = this->Names.begin(); + i != this->Names.end(); ++i) { + if (this->CheckDirectoryForName(path, *i)) { return true; - } } + } return false; } @@ -341,18 +313,15 @@ bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path, // specifically for a static library on some platforms (on MS tools // one cannot tell just from the library name whether it is a static // library or an import library). - if(name.TryRaw) - { + if (name.TryRaw) { this->TestPath = path; this->TestPath += name.Raw; - if(cmSystemTools::FileExists(this->TestPath.c_str(), true)) - { - this->BestPath = - cmSystemTools::CollapseFullPath(this->TestPath); + if (cmSystemTools::FileExists(this->TestPath.c_str(), true)) { + this->BestPath = cmSystemTools::CollapseFullPath(this->TestPath); cmSystemTools::ConvertToUnixSlashes(this->BestPath); return true; - } } + } // No library file has yet been found. size_type bestPrefix = this->Prefixes.size(); @@ -364,21 +333,18 @@ bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path, std::string dir = path; cmSystemTools::ConvertToUnixSlashes(dir); std::set<std::string> const& files = this->GG->GetDirectoryContent(dir); - for(std::set<std::string>::const_iterator fi = files.begin(); - fi != files.end(); ++fi) - { + for (std::set<std::string>::const_iterator fi = files.begin(); + fi != files.end(); ++fi) { std::string const& origName = *fi; #if defined(_WIN32) || defined(__APPLE__) std::string testName = cmSystemTools::LowerCase(origName); #else std::string const& testName = origName; #endif - if(name.Regex.find(testName)) - { + if (name.Regex.find(testName)) { this->TestPath = path; this->TestPath += origName; - if(!cmSystemTools::FileIsDirectory(this->TestPath)) - { + if (!cmSystemTools::FileIsDirectory(this->TestPath)) { // This is a matching file. Check if it is better than the // best name found so far. Earlier prefixes are preferred, // followed by earlier suffixes. For OpenBSD, shared library @@ -387,25 +353,23 @@ bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path, size_type suffix = this->GetSuffixIndex(name.Regex.match(2)); unsigned int major = 0; unsigned int minor = 0; - if(this->OpenBSD) - { + if (this->OpenBSD) { sscanf(name.Regex.match(3).c_str(), ".%u.%u", &major, &minor); - } - if(this->BestPath.empty() || prefix < bestPrefix || - (prefix == bestPrefix && suffix < bestSuffix) || - (prefix == bestPrefix && suffix == bestSuffix && - (major > bestMajor || - (major == bestMajor && minor > bestMinor)))) - { + } + if (this->BestPath.empty() || prefix < bestPrefix || + (prefix == bestPrefix && suffix < bestSuffix) || + (prefix == bestPrefix && suffix == bestSuffix && + (major > bestMajor || + (major == bestMajor && minor > bestMinor)))) { this->BestPath = this->TestPath; bestPrefix = prefix; bestSuffix = suffix; bestMajor = major; bestMinor = minor; - } } } } + } // Use the best candidate found in this directory, if any. return !this->BestPath.empty(); @@ -413,34 +377,28 @@ bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path, std::string cmFindLibraryCommand::FindNormalLibrary() { - if(this->NamesPerDir) - { + if (this->NamesPerDir) { return this->FindNormalLibraryNamesPerDir(); - } - else - { + } else { return this->FindNormalLibraryDirsPerName(); - } + } } std::string cmFindLibraryCommand::FindNormalLibraryNamesPerDir() { // Search for all names in each directory. cmFindLibraryHelper helper(this->Makefile); - 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) { helper.AddName(*ni); - } + } // Search every directory. - for(std::vector<std::string>::const_iterator - p = this->SearchPaths.begin(); p != this->SearchPaths.end(); ++p) - { - if(helper.CheckDirectory(*p)) - { + for (std::vector<std::string>::const_iterator p = this->SearchPaths.begin(); + p != this->SearchPaths.end(); ++p) { + if (helper.CheckDirectory(*p)) { return helper.BestPath; - } } + } // Couldn't find the library. return ""; } @@ -449,58 +407,49 @@ std::string cmFindLibraryCommand::FindNormalLibraryDirsPerName() { // Search the entire path for each name. cmFindLibraryHelper helper(this->Makefile); - 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) { // Switch to searching for this name. helper.SetName(*ni); // Search every directory. - for(std::vector<std::string>::const_iterator - p = this->SearchPaths.begin(); - p != this->SearchPaths.end(); ++p) - { - if(helper.CheckDirectory(*p)) - { + for (std::vector<std::string>::const_iterator p = + this->SearchPaths.begin(); + p != this->SearchPaths.end(); ++p) { + if (helper.CheckDirectory(*p)) { return helper.BestPath; - } } } + } // Couldn't find the library. return ""; } std::string cmFindLibraryCommand::FindFrameworkLibrary() { - if(this->NamesPerDir) - { + if (this->NamesPerDir) { return this->FindFrameworkLibraryNamesPerDir(); - } - else - { + } else { return this->FindFrameworkLibraryDirsPerName(); - } + } } std::string cmFindLibraryCommand::FindFrameworkLibraryNamesPerDir() { std::string fwPath; // Search for all names in each search path. - for(std::vector<std::string>::const_iterator di = this->SearchPaths.begin(); - di != this->SearchPaths.end(); ++di) - { - for(std::vector<std::string>::const_iterator ni = this->Names.begin(); - ni != this->Names.end() ; ++ni) - { + for (std::vector<std::string>::const_iterator di = this->SearchPaths.begin(); + di != this->SearchPaths.end(); ++di) { + for (std::vector<std::string>::const_iterator ni = this->Names.begin(); + ni != this->Names.end(); ++ni) { fwPath = *di; fwPath += *ni; fwPath += ".framework"; - if(cmSystemTools::FileIsDirectory(fwPath)) - { + if (cmSystemTools::FileIsDirectory(fwPath)) { return cmSystemTools::CollapseFullPath(fwPath); - } } } + } // No framework found. return ""; @@ -510,22 +459,19 @@ std::string cmFindLibraryCommand::FindFrameworkLibraryDirsPerName() { std::string fwPath; // Search for each name in all search paths. - for(std::vector<std::string>::const_iterator ni = this->Names.begin(); - ni != this->Names.end() ; ++ni) - { - for(std::vector<std::string>::const_iterator - di = this->SearchPaths.begin(); - di != this->SearchPaths.end(); ++di) - { + for (std::vector<std::string>::const_iterator ni = this->Names.begin(); + ni != this->Names.end(); ++ni) { + for (std::vector<std::string>::const_iterator di = + this->SearchPaths.begin(); + di != this->SearchPaths.end(); ++di) { fwPath = *di; fwPath += *ni; fwPath += ".framework"; - if(cmSystemTools::FileIsDirectory(fwPath)) - { + if (cmSystemTools::FileIsDirectory(fwPath)) { return cmSystemTools::CollapseFullPath(fwPath); - } } } + } // No framework found. return ""; |