1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 22:37:30 +08:00

cmFindLibraryCommand: Refactor AddArchitecturePath logic

Use boolean variables to save results and rename variables to more
closely represent their roles.
This commit is contained in:
Brad King
2017-02-28 11:30:14 -05:00
parent 2b1cdd85b8
commit e67963ed73

View File

@@ -77,31 +77,41 @@ void cmFindLibraryCommand::AddArchitecturePath(
bool fresh) bool fresh)
{ {
std::string::size_type pos = dir.find("lib/", start_pos); std::string::size_type pos = dir.find("lib/", start_pos);
if (pos != std::string::npos) {
std::string cur_dir = dir.substr(0, pos + 3);
// Follow "lib<suffix>". if (pos != std::string::npos) {
std::string next_dir = cur_dir + suffix; // Check for "lib".
if (cmSystemTools::FileIsDirectory(next_dir)) { std::string lib = dir.substr(0, pos + 3);
next_dir += dir.substr(pos + 3); bool use_lib = cmSystemTools::FileIsDirectory(lib);
std::string::size_type next_pos = pos + 3 + strlen(suffix) + 1;
this->AddArchitecturePath(next_dir, next_pos, suffix); // Check for "lib<suffix>" and use it first.
std::string libX = lib + suffix;
bool use_libX = cmSystemTools::FileIsDirectory(libX);
if (use_libX) {
libX += dir.substr(pos + 3);
std::string::size_type libX_pos = pos + 3 + strlen(suffix) + 1;
this->AddArchitecturePath(libX, libX_pos, suffix);
} }
// Follow "lib". if (use_lib) {
if (cmSystemTools::FileIsDirectory(cur_dir)) {
this->AddArchitecturePath(dir, pos + 3 + 1, suffix, false); this->AddArchitecturePath(dir, pos + 3 + 1, suffix, false);
} }
} }
if (fresh) { if (fresh) {
// Check for <dir><suffix>/. // Check for the original unchanged path.
std::string cur_dir = dir + suffix + "/"; bool use_dir = cmSystemTools::FileIsDirectory(dir);
if (cmSystemTools::FileIsDirectory(cur_dir)) {
this->SearchPaths.push_back(cur_dir); // Check for <dir><suffix>/ and use it first.
std::string dirX = dir + suffix;
bool use_dirX = cmSystemTools::FileIsDirectory(dirX);
if (use_dirX) {
dirX += "/";
this->SearchPaths.push_back(dirX);
} }
// Now add the original unchanged path if (use_dir) {
if (cmSystemTools::FileIsDirectory(dir)) {
this->SearchPaths.push_back(dir); this->SearchPaths.push_back(dir);
} }
} }