diff options
Diffstat (limited to 'Source/cmFindBase.cxx')
-rw-r--r-- | Source/cmFindBase.cxx | 255 |
1 files changed, 133 insertions, 122 deletions
diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index e4e819a..2b9acae 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -140,11 +140,11 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn) } else if(doing == DoingPaths) { - this->AddUserPath(args[j], this->UserPaths); + this->AddUserPath(args[j], this->UserGuessPaths); } else if(doing == DoingHints) { - this->AddUserPath(args[j], this->UserHints); + this->AddUserPath(args[j], this->UserHintsPaths); } else if(doing == DoingPathSuffixes) { @@ -186,16 +186,11 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn) this->Names.push_back(shortArgs[0]); for(unsigned int j = 1; j < shortArgs.size(); ++j) { - this->AddUserPath(shortArgs[j], this->UserPaths); + this->AddUserPath(shortArgs[j], this->UserGuessPaths); } } this->ExpandPaths(); - // Filter out ignored paths from the prefix list - std::set<std::string> ignored; - this->GetIgnoredPaths(ignored); - this->FilterPaths(this->SearchPaths, ignored); - this->ComputeFinalPaths(); return true; @@ -203,20 +198,40 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn) void cmFindBase::ExpandPaths() { - this->AddCMakeVariablePath(); - this->AddCMakeEnvironmentPath(); - this->AddUserHintsPath(); - this->AddSystemEnvironmentPath(); - this->AddCMakeSystemVariablePath(); - this->AddUserGuessPath(); - - // Add suffixes and clean up paths. - this->AddPathSuffixes(); + if(!this->NoDefaultPath) + { + if(!this->NoCMakePath) + { + this->FillCMakeVariablePath(); + this->AddPathSuffixes(this->CMakeVariablePaths); + } + if(!this->NoCMakeEnvironmentPath) + { + this->FillCMakeEnvironmentPath(); + this->AddPathSuffixes(this->CMakeEnvironmentPaths); + } + if(!this->NoSystemEnvironmentPath) + { + this->FillSystemEnvironmentPath(); + this->AddPathSuffixes(this->SystemEnvironmentPaths); + } + if(!this->NoCMakeSystemPath) + { + this->FillCMakeSystemVariablePath(); + this->AddPathSuffixes(this->CMakeSystemVariablePaths); + } + } + + this->FillUserHintsPath(); + this->AddPathSuffixes(this->UserHintsPaths); + this->FillUserGuessPath(); + this->AddPathSuffixes(this->UserGuessPaths); } //---------------------------------------------------------------------------- -void cmFindBase::AddPrefixPaths(std::vector<std::string> const& in_paths, - PathType pathType) +void cmFindBase::AddPrefixPaths(std::vector<std::string> const& inPaths, + PathType pt, + std::vector<std::string>& outPaths) { // default for programs std::string subdir = "bin"; @@ -234,8 +249,8 @@ void cmFindBase::AddPrefixPaths(std::vector<std::string> const& in_paths, subdir = ""; // ? what to do for frameworks ? } - for(std::vector<std::string>::const_iterator it = in_paths.begin(); - it != in_paths.end(); ++it) + for(std::vector<std::string>::const_iterator it = inPaths.begin(); + it != inPaths.end(); ++it) { std::string dir = *it; if(!subdir.empty() && !dir.empty() && dir[dir.size()-1] != '/') @@ -248,178 +263,173 @@ void cmFindBase::AddPrefixPaths(std::vector<std::string> const& in_paths, this->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE"); if(arch && *arch) { - this->AddPathInternal(dir+subdir+"/"+arch, pathType); + this->AddPathInternal(this->MakeFullPath(dir+subdir+"/"+arch, pt), + outPaths); } } std::string add = dir + subdir; if(add != "/") { - this->AddPathInternal(add, pathType); + this->AddPathInternal(this->MakeFullPath(add, pt), outPaths); } if (subdir == "bin") { - this->AddPathInternal(dir+"sbin", pathType); + this->AddPathInternal(this->MakeFullPath(dir+"sbin", pt), outPaths); } if(!subdir.empty() && *it != "/") { - this->AddPathInternal(*it, pathType); + this->AddPathInternal(this->MakeFullPath(*it, pt), outPaths); } } } //---------------------------------------------------------------------------- -void cmFindBase::AddCMakePrefixPath(const std::string& variable) +void cmFindBase::AddCMakePrefixPath(const std::string& variable, + std::vector<std::string>& outPaths) { // Get a path from a CMake variable. if(const char* varPath = this->Makefile->GetDefinition(variable)) { std::vector<std::string> tmp; cmSystemTools::ExpandListArgument(varPath, tmp); - this->AddPrefixPaths(tmp, CMakePath); + this->AddPrefixPaths(tmp, CMakePath, outPaths); } } //---------------------------------------------------------------------------- -void cmFindBase::AddEnvPrefixPath(const std::string& variable) +void cmFindBase::AddEnvPrefixPath(const std::string& variable, + std::vector<std::string>& outPaths) { // Get a path from the environment. std::vector<std::string> tmp; cmSystemTools::GetPath(tmp, variable.c_str()); - this->AddPrefixPaths(tmp, EnvPath); + this->AddPrefixPaths(tmp, EnvPath, outPaths); } //---------------------------------------------------------------------------- -void cmFindBase::AddCMakeEnvironmentPath() +void cmFindBase::FillCMakeEnvironmentPath() { - if(!this->NoCMakeEnvironmentPath && !this->NoDefaultPath) + // Add CMAKE_*_PATH environment variables + std::string var = "CMAKE_"; + var += this->CMakePathName; + var += "_PATH"; + this->AddEnvPrefixPath("CMAKE_PREFIX_PATH", this->CMakeEnvironmentPaths); + this->AddEnvPath(var.c_str(), this->CMakeEnvironmentPaths); + + if(this->CMakePathName == "PROGRAM") { - // Add CMAKE_*_PATH environment variables - std::string var = "CMAKE_"; - var += this->CMakePathName; - var += "_PATH"; - this->AddEnvPrefixPath("CMAKE_PREFIX_PATH"); - this->AddEnvPath(var.c_str()); - - if(this->CMakePathName == "PROGRAM") - { - this->AddEnvPath("CMAKE_APPBUNDLE_PATH"); - } - else - { - this->AddEnvPath("CMAKE_FRAMEWORK_PATH"); - } + this->AddEnvPath("CMAKE_APPBUNDLE_PATH", this->CMakeEnvironmentPaths); + } + else + { + this->AddEnvPath("CMAKE_FRAMEWORK_PATH", this->CMakeEnvironmentPaths); } } //---------------------------------------------------------------------------- -void cmFindBase::AddCMakeVariablePath() +void cmFindBase::FillCMakeVariablePath() { - if(!this->NoCMakePath && !this->NoDefaultPath) + // Add CMake varibles of the same name as the previous environment + // varibles CMAKE_*_PATH to be used most of the time with -D + // command line options + std::string var = "CMAKE_"; + var += this->CMakePathName; + var += "_PATH"; + this->AddCMakePrefixPath("CMAKE_PREFIX_PATH", this->CMakeVariablePaths); + this->AddCMakePath(var, this->CMakeVariablePaths); + + if(this->CMakePathName == "PROGRAM") { - // Add CMake varibles of the same name as the previous environment - // varibles CMAKE_*_PATH to be used most of the time with -D - // command line options - std::string var = "CMAKE_"; - var += this->CMakePathName; - var += "_PATH"; - this->AddCMakePrefixPath("CMAKE_PREFIX_PATH"); - this->AddCMakePath(var); - - if(this->CMakePathName == "PROGRAM") - { - this->AddCMakePath("CMAKE_APPBUNDLE_PATH"); - } - else - { - this->AddCMakePath("CMAKE_FRAMEWORK_PATH"); - } + this->AddCMakePath("CMAKE_APPBUNDLE_PATH", this->CMakeVariablePaths); + } + else + { + this->AddCMakePath("CMAKE_FRAMEWORK_PATH", this->CMakeVariablePaths); } } //---------------------------------------------------------------------------- -void cmFindBase::AddSystemEnvironmentPath() +void cmFindBase::FillSystemEnvironmentPath() { - if(!this->NoSystemEnvironmentPath && !this->NoDefaultPath) + // Add LIB or INCLUDE + if(!this->EnvironmentPath.empty()) { - // Add LIB or INCLUDE - if(!this->EnvironmentPath.empty()) - { - this->AddEnvPath(this->EnvironmentPath.c_str()); - } - // Add PATH - this->AddEnvPath(0); + this->AddEnvPath(this->EnvironmentPath.c_str(), + this->SystemEnvironmentPaths); } + // Add PATH + this->AddEnvPath(0, this->SystemEnvironmentPaths); } //---------------------------------------------------------------------------- -void cmFindBase::AddCMakeSystemVariablePath() +void cmFindBase::FillCMakeSystemVariablePath() { - if(!this->NoCMakeSystemPath && !this->NoDefaultPath) + std::string var = "CMAKE_SYSTEM_"; + var += this->CMakePathName; + var += "_PATH"; + this->AddCMakePrefixPath("CMAKE_SYSTEM_PREFIX_PATH", + this->CMakeSystemVariablePaths); + this->AddCMakePath(var, this->CMakeSystemVariablePaths); + + if(this->CMakePathName == "PROGRAM") { - std::string var = "CMAKE_SYSTEM_"; - var += this->CMakePathName; - var += "_PATH"; - this->AddCMakePrefixPath("CMAKE_SYSTEM_PREFIX_PATH"); - this->AddCMakePath(var); - - if(this->CMakePathName == "PROGRAM") - { - this->AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH"); - } - else - { - this->AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH"); - } + this->AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH", + this->CMakeSystemVariablePaths); + } + else + { + this->AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH", + this->CMakeSystemVariablePaths); } } //---------------------------------------------------------------------------- -void cmFindBase::AddUserHintsPath() +void cmFindBase::FillUserHintsPath() { - this->AddPathsInternal(this->UserHints, CMakePath); + std::vector<std::string> inPaths; + inPaths.swap(this->UserHintsPaths); + this->AddPathsInternal(inPaths, CMakePath, this->UserHintsPaths); } //---------------------------------------------------------------------------- -void cmFindBase::AddUserGuessPath() +void cmFindBase::FillUserGuessPath() { - this->AddPathsInternal(this->UserPaths, CMakePath); + std::vector<std::string> inPaths; + inPaths.swap(this->UserGuessPaths); + this->AddPathsInternal(inPaths, CMakePath, this->UserGuessPaths); } //---------------------------------------------------------------------------- -void cmFindBase::AddPathSuffixes() +void cmFindBase::AddPathSuffixes(std::vector<std::string>& paths) { - std::vector<std::string>& paths = this->SearchPaths; - std::vector<std::string> finalPath = paths; - std::vector<std::string>::iterator i; - // clear the path - paths.clear(); - // convert all paths to unix slashes and add search path suffixes - // if there are any - for(i = finalPath.begin(); - i != finalPath.end(); ++i) + std::vector<std::string> inPaths; + inPaths.swap(paths); + paths.reserve(inPaths.size()*(this->SearchPathSuffixes.size()+1)); + + for(std::vector<std::string>::iterator ip = inPaths.begin(); + ip != inPaths.end(); ++ip) { - cmSystemTools::ConvertToUnixSlashes(*i); - // copy each finalPath combined with SearchPathSuffixes - // to the SearchPaths ivar - for(std::vector<std::string>::iterator j = + cmSystemTools::ConvertToUnixSlashes(*ip); + + // if *i is only / then do not add a // + // this will get incorrectly considered a network + // path on windows and cause huge delays. + std::string p = *ip; + if(!p.empty() && *p.rbegin() != '/') + { + p += "/"; + } + + for(std::vector<std::string>::iterator sps = this->SearchPathSuffixes.begin(); - j != this->SearchPathSuffixes.end(); ++j) + sps != this->SearchPathSuffixes.end(); ++sps) { - // if *i is only / then do not add a // - // this will get incorrectly considered a network - // path on windows and cause huge delays. - std::string p = *i; - if(p.size() && p[p.size()-1] != '/') - { - p += std::string("/"); - } - p += *j; // add to all paths because the search path may be modified // later with lib being replaced for lib64 which may exist - paths.push_back(p); + paths.push_back(p+*sps); } // now put the path without the path suffixes in the SearchPaths - paths.push_back(*i); + paths.push_back(*ip); } } @@ -457,9 +467,10 @@ void cmFindBase::PrintFindStuff() } std::cerr << "\n"; std::cerr << "SearchPaths\n"; - for(unsigned int i =0; i < this->SearchPaths.size(); ++i) + for(std::vector<std::string>::const_iterator i = this->SearchPaths.begin(); + i != this->SearchPaths.end(); ++i) { - std::cerr << "[" << this->SearchPaths[i] << "]\n"; + std::cerr << "[" << *i << "]\n"; } } |