summaryrefslogtreecommitdiffstats
path: root/Source/cmFindPackageCommand.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmFindPackageCommand.cxx')
-rw-r--r--Source/cmFindPackageCommand.cxx245
1 files changed, 134 insertions, 111 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index 4633e71..ded6eee 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -248,11 +248,11 @@ bool cmFindPackageCommand
}
else if(doing == DoingPaths)
{
- this->AddUserPath(args[i], this->UserPaths);
+ this->AddUserPath(args[i], this->UserGuessPaths);
}
else if(doing == DoingHints)
{
- this->AddUserPath(args[i], this->UserHints);
+ this->AddUserPath(args[i], this->UserHintsPaths);
}
else if(doing == DoingPathSuffixes)
{
@@ -1111,86 +1111,99 @@ void cmFindPackageCommand::AppendSuccessInformation()
//----------------------------------------------------------------------------
void cmFindPackageCommand::ComputePrefixes()
{
- this->AddPrefixesCMakeVariable();
- this->AddPrefixesCMakeEnvironment();
- this->AddPrefixesUserHints();
- this->AddPrefixesSystemEnvironment();
- this->AddPrefixesUserRegistry();
- this->AddPrefixesBuilds();
- this->AddPrefixesCMakeSystemVariable();
- this->AddPrefixesSystemRegistry();
- this->AddPrefixesUserGuess();
+ if(!this->NoDefaultPath)
+ {
+ if(!this->NoCMakePath)
+ {
+ this->FillPrefixesCMakeVariable();
+ }
+ if(!this->NoCMakeEnvironmentPath)
+ {
+ this->FillPrefixesCMakeEnvironment();
+ }
+ if(!this->NoSystemEnvironmentPath)
+ {
+ this->FillPrefixesSystemEnvironment();
+ }
+ if(!this->NoUserRegistry)
+ {
+ this->FillPrefixesUserRegistry();
+ }
+ if(!this->NoBuilds)
+ {
+ this->FillPrefixesBuilds();
+ }
+ if(!this->NoCMakeSystemPath)
+ {
+ this->FillPrefixesCMakeSystemVariable();
+ }
+ if(!this->NoSystemRegistry)
+ {
+ this->FillPrefixesSystemRegistry();
+ }
+ }
+ this->FillPrefixesUserHints();
+ this->FillPrefixesUserGuess();
+
this->ComputeFinalPaths();
}
//----------------------------------------------------------------------------
-void cmFindPackageCommand::AddPrefixesCMakeEnvironment()
+void cmFindPackageCommand::FillPrefixesCMakeEnvironment()
{
- if(!this->NoCMakeEnvironmentPath && !this->NoDefaultPath)
+ // Check the environment variable with the same name as the cache
+ // entry.
+ std::string env;
+ if(cmSystemTools::GetEnv(this->Variable.c_str(), env) && env.length() > 0)
{
- // Check the environment variable with the same name as the cache
- // entry.
- std::string env;
- if(cmSystemTools::GetEnv(this->Variable.c_str(), env) && env.length() > 0)
- {
- cmSystemTools::ConvertToUnixSlashes(env);
- this->AddPathInternal(env, EnvPath);
- }
-
- this->AddEnvPath("CMAKE_PREFIX_PATH");
- this->AddEnvPath("CMAKE_FRAMEWORK_PATH");
- this->AddEnvPath("CMAKE_APPBUNDLE_PATH");
+ cmSystemTools::ConvertToUnixSlashes(env);
+ this->AddPathInternal(MakeFullPath(env, EnvPath),
+ this->CMakeEnvironmentPaths);
}
+
+ this->AddEnvPath("CMAKE_PREFIX_PATH", this->CMakeEnvironmentPaths);
+ this->AddEnvPath("CMAKE_FRAMEWORK_PATH", this->CMakeEnvironmentPaths);
+ this->AddEnvPath("CMAKE_APPBUNDLE_PATH", this->CMakeEnvironmentPaths);
}
//----------------------------------------------------------------------------
-void cmFindPackageCommand::AddPrefixesCMakeVariable()
+void cmFindPackageCommand::FillPrefixesCMakeVariable()
{
- if(!this->NoCMakePath && !this->NoDefaultPath)
- {
- this->AddCMakePath("CMAKE_PREFIX_PATH");
- this->AddCMakePath("CMAKE_FRAMEWORK_PATH");
- this->AddCMakePath("CMAKE_APPBUNDLE_PATH");
- }
+ this->AddCMakePath("CMAKE_PREFIX_PATH", this->CMakeVariablePaths);
+ this->AddCMakePath("CMAKE_FRAMEWORK_PATH", this->CMakeVariablePaths);
+ this->AddCMakePath("CMAKE_APPBUNDLE_PATH", this->CMakeVariablePaths);
}
//----------------------------------------------------------------------------
-void cmFindPackageCommand::AddPrefixesSystemEnvironment()
+void cmFindPackageCommand::FillPrefixesSystemEnvironment()
{
- if(!this->NoSystemEnvironmentPath && !this->NoDefaultPath)
- {
- // 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)
+ // 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)
+ {
+ // If the path is a PREFIX/bin case then add its parent instead.
+ if((cmHasLiteralSuffix(*i, "/bin")) ||
+ (cmHasLiteralSuffix(*i, "/sbin")))
+ {
+ this->AddPathInternal(MakeFullPath(cmSystemTools::GetFilenamePath(*i),
+ EnvPath),
+ this->SystemEnvironmentPaths);
+ }
+ else
{
- std::string const& d = *i;
-
- // If the path is a PREFIX/bin case then add its parent instead.
- if((cmHasLiteralSuffix(d, "/bin")) ||
- (cmHasLiteralSuffix(d, "/sbin")))
- {
- this->AddPathInternal(cmSystemTools::GetFilenamePath(d), EnvPath);
- }
- else
- {
- this->AddPathInternal(d, EnvPath);
- }
+ this->AddPathInternal(MakeFullPath(*i, EnvPath),
+ this->SystemEnvironmentPaths);
}
}
}
//----------------------------------------------------------------------------
-void cmFindPackageCommand::AddPrefixesUserRegistry()
+void cmFindPackageCommand::FillPrefixesUserRegistry()
{
- if(this->NoUserRegistry || this->NoDefaultPath)
- {
- return;
- }
-
#if defined(_WIN32) && !defined(__CYGWIN__)
this->LoadPackageRegistryWinUser();
#elif defined(__HAIKU__)
@@ -1201,7 +1214,7 @@ void cmFindPackageCommand::AddPrefixesUserRegistry()
std::string fname = dir;
fname += "/cmake/packages/";
fname += Name;
- this->LoadPackageRegistryDir(fname);
+ this->LoadPackageRegistryDir(fname, this->UserRegistryPaths);
}
#else
if(const char* home = cmSystemTools::GetEnv("HOME"))
@@ -1209,13 +1222,13 @@ void cmFindPackageCommand::AddPrefixesUserRegistry()
std::string dir = home;
dir += "/.cmake/packages/";
dir += this->Name;
- this->LoadPackageRegistryDir(dir);
+ this->LoadPackageRegistryDir(dir, this->UserRegistryPaths);
}
#endif
}
//----------------------------------------------------------------------------
-void cmFindPackageCommand::AddPrefixesSystemRegistry()
+void cmFindPackageCommand::FillPrefixesSystemRegistry()
{
if(this->NoSystemRegistry || this->NoDefaultPath)
{
@@ -1241,7 +1254,7 @@ void cmFindPackageCommand::AddPrefixesSystemRegistry()
void cmFindPackageCommand::LoadPackageRegistryWinUser()
{
// HKEY_CURRENT_USER\\Software shares 32-bit and 64-bit views.
- this->LoadPackageRegistryWin(true, 0);
+ this->LoadPackageRegistryWin(true, 0, this->UserRegistryPaths);
}
//----------------------------------------------------------------------------
@@ -1251,19 +1264,23 @@ void cmFindPackageCommand::LoadPackageRegistryWinSystem()
// Prefer the target platform view first.
if(this->Makefile->PlatformIs64Bit())
{
- this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY);
- this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY);
+ this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY,
+ this->SystemRegistryPaths);
+ this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY,
+ this->SystemRegistryPaths);
}
else
{
- this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY);
- this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY);
+ this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY,
+ this->SystemRegistryPaths);
+ this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY,
+ this->SystemRegistryPaths);
}
}
//----------------------------------------------------------------------------
-void cmFindPackageCommand::LoadPackageRegistryWin(bool user,
- unsigned int view)
+void cmFindPackageCommand::LoadPackageRegistryWin(bool user, unsigned int view,
+ std::vector<std::string>& outPaths)
{
std::wstring key = L"Software\\Kitware\\CMake\\Packages\\";
key += cmsys::Encoding::ToWide(this->Name);
@@ -1289,8 +1306,8 @@ void cmFindPackageCommand::LoadPackageRegistryWin(bool user,
if(valueType == REG_SZ)
{
data[dataSize] = 0;
- cmsys_ios::stringstream ss(cmsys::Encoding::ToNarrow(&data[0]));
- if(!this->CheckPackageRegistryEntry(ss))
+ if(!this->CheckPackageRegistryEntry(
+ cmsys::Encoding::ToNarrow(&data[0]), outPaths))
{
// The entry is invalid.
bad.insert(name);
@@ -1332,7 +1349,8 @@ public:
};
//----------------------------------------------------------------------------
-void cmFindPackageCommand::LoadPackageRegistryDir(std::string const& dir)
+void cmFindPackageCommand::LoadPackageRegistryDir(std::string const& dir,
+ std::vector<std::string>& outPaths)
{
cmsys::Directory files;
if(!files.Load(dir))
@@ -1354,7 +1372,9 @@ void cmFindPackageCommand::LoadPackageRegistryDir(std::string const& dir)
// Load the file.
cmsys::ifstream fin(fname.c_str(), std::ios::in | cmsys_ios_binary);
- if(fin && this->CheckPackageRegistryEntry(fin))
+ std::string fentry;
+ if(fin && cmSystemTools::GetLineFromStream(fin, fentry) &&
+ this->CheckPackageRegistryEntry(fentry, outPaths))
{
// The file references an existing package, so release it.
holdFile.Release();
@@ -1367,12 +1387,11 @@ void cmFindPackageCommand::LoadPackageRegistryDir(std::string const& dir)
#endif
//----------------------------------------------------------------------------
-bool cmFindPackageCommand::CheckPackageRegistryEntry(std::istream& is)
+bool cmFindPackageCommand::CheckPackageRegistryEntry(const std::string& fname,
+ std::vector<std::string>& outPaths)
{
// Parse the content of one package registry entry.
- std::string fname;
- if(cmSystemTools::GetLineFromStream(is, fname) &&
- 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.
@@ -1381,9 +1400,14 @@ bool cmFindPackageCommand::CheckPackageRegistryEntry(std::istream& is)
// The path exists. Look for the package here.
if(!cmSystemTools::FileIsDirectory(fname))
{
- fname = cmSystemTools::GetFilenamePath(fname);
+ this->AddPathInternal(
+ MakeFullPath(cmSystemTools::GetFilenamePath(fname), FullPath),
+ outPaths);
+ }
+ else
+ {
+ this->AddPathInternal(MakeFullPath(fname, FullPath), outPaths);
}
- this->AddPathInternal(fname, FullPath);
return true;
}
else
@@ -1404,52 +1428,51 @@ bool cmFindPackageCommand::CheckPackageRegistryEntry(std::istream& is)
}
//----------------------------------------------------------------------------
-void cmFindPackageCommand::AddPrefixesBuilds()
+void cmFindPackageCommand::FillPrefixesBuilds()
{
- if(!this->NoBuilds && !this->NoDefaultPath)
- {
- // It is likely that CMake will have recently built the project.
- for(int i=0; i <= 10; ++i)
- {
- cmOStringStream r;
- r <<
- "[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\"
- "Settings\\StartPath;WhereBuild" << i << "]";
- std::string f = r.str();
- cmSystemTools::ExpandRegistryValues(f);
- cmSystemTools::ConvertToUnixSlashes(f);
- if(cmSystemTools::FileIsFullPath(f.c_str()) &&
- cmSystemTools::FileIsDirectory(f))
- {
- this->AddPathInternal(f, FullPath);
- }
+ // It is likely that CMake will have recently built the project.
+ for(int i=0; i <= 10; ++i)
+ {
+ cmOStringStream r;
+ r <<
+ "[HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\"
+ "Settings\\StartPath;WhereBuild" << i << "]";
+ std::string f = r.str();
+ cmSystemTools::ExpandRegistryValues(f);
+ cmSystemTools::ConvertToUnixSlashes(f);
+ if(cmSystemTools::FileIsFullPath(f.c_str()) &&
+ cmSystemTools::FileIsDirectory(f.c_str()))
+ {
+ this->AddPathInternal(MakeFullPath(f, FullPath), this->BuildPaths);
}
}
}
//----------------------------------------------------------------------------
-void cmFindPackageCommand::AddPrefixesCMakeSystemVariable()
+void cmFindPackageCommand::FillPrefixesCMakeSystemVariable()
{
- if(!this->NoCMakeSystemPath && !this->NoDefaultPath)
- {
- this->AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH");
- this->AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
- this->AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
- }
+ this->AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH",
+ this->CMakeSystemVariablePaths);
+ this->AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH",
+ this->CMakeSystemVariablePaths);
+ this->AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH",
+ this->CMakeSystemVariablePaths);
}
//----------------------------------------------------------------------------
-void cmFindPackageCommand::AddPrefixesUserGuess()
+void cmFindPackageCommand::FillPrefixesUserGuess()
{
- // Add guesses specified by the caller.
- this->AddPathsInternal(this->UserPaths, CMakePath);
+ std::vector<std::string> inPaths;
+ inPaths.swap(this->UserGuessPaths);
+ this->AddPathsInternal(inPaths, CMakePath, this->UserGuessPaths);
}
//----------------------------------------------------------------------------
-void cmFindPackageCommand::AddPrefixesUserHints()
+void cmFindPackageCommand::FillPrefixesUserHints()
{
- // Add hints specified by the caller.
- this->AddPathsInternal(this->UserHints, CMakePath);
+ std::vector<std::string> inPaths;
+ inPaths.swap(this->UserHintsPaths);
+ this->AddPathsInternal(inPaths, CMakePath, this->UserHintsPaths);
}
//----------------------------------------------------------------------------