ENH: Refactor cmFindCommon, cmFindBase, and cmFindPackageCommand
- Add each part of the search order in a separate method. - Collect added paths in an ivar in cmFindCommon. - Move user path storage up to cmFindCommon and share between cmFindBase and cmFindPackageCommand. - Expand user path registry values up in cmFindCommon - Enables 32-/64-bit registry view for find_package - Disables registry expansion for paths not specified with the PATHS argument, which is not expected.
This commit is contained in:
parent
3ecfb5f7e8
commit
789c167b6f
|
@ -161,7 +161,6 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
|
|||
// Find the current bundle/framework search policy.
|
||||
this->SelectDefaultMacMode();
|
||||
|
||||
std::vector<std::string> userPaths;
|
||||
std::string doc;
|
||||
bool doingNames = true; // assume it starts with a name
|
||||
bool doingPaths = false;
|
||||
|
@ -214,7 +213,7 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
|
|||
}
|
||||
else if(doingPaths)
|
||||
{
|
||||
userPaths.push_back(args[j]);
|
||||
this->AddUserPath(args[j]);
|
||||
}
|
||||
else if(doingPathSuf)
|
||||
{
|
||||
|
@ -266,17 +265,17 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
|
|||
this->Names.push_back(args[1]);
|
||||
for(unsigned int j = 2; j < args.size(); ++j)
|
||||
{
|
||||
userPaths.push_back(args[j]);
|
||||
this->AddUserPath(args[j]);
|
||||
}
|
||||
}
|
||||
this->ExpandPaths(userPaths);
|
||||
this->ExpandPaths();
|
||||
|
||||
// Handle search root stuff.
|
||||
this->RerootPaths(this->SearchPaths);
|
||||
return true;
|
||||
}
|
||||
|
||||
void cmFindBase::ExpandPaths(std::vector<std::string> userPaths)
|
||||
void cmFindBase::ExpandPaths()
|
||||
{
|
||||
// if NO Default paths was not specified add the
|
||||
// standard search paths.
|
||||
|
@ -284,74 +283,36 @@ void cmFindBase::ExpandPaths(std::vector<std::string> userPaths)
|
|||
{
|
||||
if(this->SearchFrameworkFirst || this->SearchFrameworkOnly)
|
||||
{
|
||||
this->AddFrameWorkPaths();
|
||||
this->AddFrameworkPath();
|
||||
}
|
||||
if(this->SearchAppBundleFirst || this->SearchAppBundleOnly)
|
||||
{
|
||||
this->AddAppBundlePaths();
|
||||
}
|
||||
if(!this->NoCMakeEnvironmentPath &&
|
||||
!(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
|
||||
{
|
||||
// Add CMAKE_*_PATH environment variables
|
||||
this->AddEnvironmentVariables();
|
||||
}
|
||||
if(!this->NoCMakePath &&
|
||||
!(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
|
||||
{
|
||||
// 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
|
||||
this->AddCMakeVariables();
|
||||
}
|
||||
if(!this->NoSystemEnvironmentPath &&
|
||||
!(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
|
||||
{
|
||||
// add System environment PATH and (LIB or INCLUDE)
|
||||
this->AddSystemEnvironmentVariables();
|
||||
}
|
||||
if(!this->NoCMakeSystemPath &&
|
||||
!(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
|
||||
{
|
||||
// Add CMAKE_SYSTEM_*_PATH variables which are defined in platform files
|
||||
this->AddCMakeSystemVariables();
|
||||
this->AddAppBundlePath();
|
||||
}
|
||||
this->AddCMakeEnvironmentPath();
|
||||
this->AddCMakeVariablePath();
|
||||
this->AddSystemEnvironmentPath();
|
||||
this->AddCMakeSystemVariablePath();
|
||||
if(this->SearchAppBundleLast)
|
||||
{
|
||||
this->AddAppBundlePaths();
|
||||
this->AddAppBundlePath();
|
||||
}
|
||||
if(this->SearchFrameworkLast)
|
||||
{
|
||||
this->AddFrameWorkPaths();
|
||||
this->AddFrameworkPath();
|
||||
}
|
||||
}
|
||||
std::vector<std::string> paths;
|
||||
// add the paths specified in the FIND_* call
|
||||
for(unsigned int i =0; i < userPaths.size(); ++i)
|
||||
{
|
||||
paths.push_back(userPaths[i]);
|
||||
}
|
||||
this->AddPaths(paths);
|
||||
|
||||
// Add paths specified by the caller.
|
||||
this->AddPathsInternal(this->UserPaths, CMakePath);
|
||||
|
||||
// Add suffixes and clean up paths.
|
||||
this->AddPathSuffixes();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindBase::AddEnvironmentVariables()
|
||||
{
|
||||
std::vector<std::string> paths;
|
||||
|
||||
std::vector<std::string> prefixPaths;
|
||||
cmSystemTools::GetPath(prefixPaths, "CMAKE_PREFIX_PATH");
|
||||
this->AddFindPrefix(paths, prefixPaths);
|
||||
|
||||
std::string var = "CMAKE_";
|
||||
var += this->CMakePathName;
|
||||
var += "_PATH";
|
||||
cmSystemTools::GetPath(paths, var.c_str());
|
||||
this->AddPaths(paths);
|
||||
}
|
||||
|
||||
void cmFindBase::AddFindPrefix(std::vector<std::string>& dest,
|
||||
const std::vector<std::string>& src)
|
||||
void cmFindBase::AddPrefixPaths(std::vector<std::string> const& in_paths,
|
||||
PathType pathType)
|
||||
{
|
||||
// default for programs
|
||||
std::string subdir = "bin";
|
||||
|
@ -369,9 +330,8 @@ void cmFindBase::AddFindPrefix(std::vector<std::string>& dest,
|
|||
subdir = ""; // ? what to do for frameworks ?
|
||||
}
|
||||
|
||||
for (std::vector<std::string>::const_iterator it = src.begin();
|
||||
it != src.end();
|
||||
++it)
|
||||
for(std::vector<std::string>::const_iterator it = in_paths.begin();
|
||||
it != in_paths.end(); ++it)
|
||||
{
|
||||
std::string dir = it->c_str();
|
||||
if(!subdir.empty() && !dir.empty() && dir[dir.size()-1] != '/')
|
||||
|
@ -381,131 +341,147 @@ void cmFindBase::AddFindPrefix(std::vector<std::string>& dest,
|
|||
std::string add = dir + subdir;
|
||||
if(add != "/")
|
||||
{
|
||||
dest.push_back(add);
|
||||
this->AddPathInternal(add, pathType);
|
||||
}
|
||||
if (subdir == "bin")
|
||||
{
|
||||
dest.push_back(dir + "sbin");
|
||||
this->AddPathInternal(dir+"sbin", pathType);
|
||||
}
|
||||
if(!subdir.empty() && *it != "/")
|
||||
{
|
||||
dest.push_back(*it);
|
||||
this->AddPathInternal(*it, pathType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmFindBase::AddFrameWorkPaths()
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindBase::AddCMakePrefixPath(const char* variable)
|
||||
{
|
||||
std::vector<std::string> paths;
|
||||
this->GetFrameworkPaths(paths);
|
||||
this->AddPaths(paths);
|
||||
}
|
||||
|
||||
void cmFindBase::AddPaths(std::vector<std::string> & paths)
|
||||
{
|
||||
// add suffixes and clean up paths
|
||||
this->ExpandRegistryAndCleanPath(paths);
|
||||
// add the paths to the search paths
|
||||
this->SearchPaths.insert(this->SearchPaths.end(),
|
||||
paths.begin(),
|
||||
paths.end());
|
||||
}
|
||||
|
||||
void cmFindBase::AddAppBundlePaths()
|
||||
{
|
||||
std::vector<std::string> paths;
|
||||
this->GetAppBundlePaths(paths);
|
||||
this->AddPaths(paths);
|
||||
}
|
||||
|
||||
void cmFindBase::AddCMakeVariables()
|
||||
{
|
||||
std::string var = "CMAKE_";
|
||||
var += this->CMakePathName;
|
||||
var += "_PATH";
|
||||
std::vector<std::string> paths;
|
||||
|
||||
if(const char* prefixPath =
|
||||
this->Makefile->GetDefinition("CMAKE_PREFIX_PATH"))
|
||||
// Get a path from a CMake variable.
|
||||
if(const char* varPath = this->Makefile->GetDefinition(variable))
|
||||
{
|
||||
std::vector<std::string> prefixPaths;
|
||||
cmSystemTools::ExpandListArgument(prefixPath, prefixPaths);
|
||||
this->AddFindPrefix(paths, prefixPaths);
|
||||
std::vector<std::string> tmp;
|
||||
cmSystemTools::ExpandListArgument(varPath, tmp);
|
||||
this->AddPrefixPaths(tmp, CMakePath);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindBase::AddEnvPrefixPath(const char* variable)
|
||||
{
|
||||
// Get a path from the environment.
|
||||
std::vector<std::string> tmp;
|
||||
cmSystemTools::GetPath(tmp, variable);
|
||||
this->AddPrefixPaths(tmp, EnvPath);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindBase::AddMacPath(const char* var, const char* sysvar)
|
||||
{
|
||||
if(this->NoDefaultPath)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(const char* path = this->Makefile->GetDefinition(var.c_str()))
|
||||
// first environment variables
|
||||
if(!this->NoCMakeEnvironmentPath)
|
||||
{
|
||||
cmSystemTools::ExpandListArgument(path, paths);
|
||||
this->AddEnvPath("CMAKE_FRAMEWORK_PATH");
|
||||
}
|
||||
|
||||
// add cmake variables
|
||||
if(!this->NoCMakePath)
|
||||
{
|
||||
this->AddCMakePath("CMAKE_FRAMEWORK_PATH");
|
||||
}
|
||||
|
||||
// add cmake system variables
|
||||
if(!this->NoCMakeSystemPath)
|
||||
{
|
||||
this->AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
|
||||
}
|
||||
this->AddPaths(paths);
|
||||
}
|
||||
|
||||
void cmFindBase::AddSystemEnvironmentVariables()
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindBase::AddFrameworkPath()
|
||||
{
|
||||
// Add LIB or INCLUDE
|
||||
std::vector<std::string> paths;
|
||||
if(this->EnvironmentPath.size())
|
||||
{
|
||||
cmSystemTools::GetPath(paths, this->EnvironmentPath.c_str());
|
||||
}
|
||||
// Add PATH
|
||||
cmSystemTools::GetPath(paths);
|
||||
this->AddPaths(paths);
|
||||
this->AddMacPath("CMAKE_FRAMEWORK_PATH", "CMAKE_SYSTEM_FRAMEWORK_PATH");
|
||||
}
|
||||
|
||||
void cmFindBase::AddCMakeSystemVariables()
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindBase::AddAppBundlePath()
|
||||
{
|
||||
std::string var = "CMAKE_SYSTEM_";
|
||||
var += this->CMakePathName;
|
||||
var += "_PATH";
|
||||
std::vector<std::string> paths;
|
||||
if(const char* prefixPath =
|
||||
this->Makefile->GetDefinition("CMAKE_SYSTEM_PREFIX_PATH"))
|
||||
{
|
||||
std::vector<std::string> prefixPaths;
|
||||
cmSystemTools::ExpandListArgument(prefixPath, prefixPaths);
|
||||
this->AddFindPrefix(paths, prefixPaths);
|
||||
}
|
||||
if(const char* path = this->Makefile->GetDefinition(var.c_str()))
|
||||
{
|
||||
cmSystemTools::ExpandListArgument(path, paths);
|
||||
}
|
||||
this->AddPaths(paths);
|
||||
this->AddMacPath("CMAKE_APPBUNDLE_PATH", "CMAKE_SYSTEM_APPBUNDLE_PATH");
|
||||
}
|
||||
|
||||
void cmFindBase::ExpandRegistryAndCleanPath(std::vector<std::string>& paths)
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindBase::AddCMakeEnvironmentPath()
|
||||
{
|
||||
// We should view the registry as the target application would view
|
||||
// it.
|
||||
cmSystemTools::KeyWOW64 view = cmSystemTools::KeyWOW64_32;
|
||||
cmSystemTools::KeyWOW64 other_view = cmSystemTools::KeyWOW64_64;
|
||||
if(const char* psize =
|
||||
this->Makefile->GetDefinition("CMAKE_SIZEOF_VOID_P"))
|
||||
if(!this->NoCMakeEnvironmentPath &&
|
||||
!(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
|
||||
{
|
||||
if(atoi(psize) == 8)
|
||||
// Add CMAKE_*_PATH environment variables
|
||||
std::string var = "CMAKE_";
|
||||
var += this->CMakePathName;
|
||||
var += "_PATH";
|
||||
this->AddEnvPrefixPath("CMAKE_PREFIX_PATH");
|
||||
this->AddEnvPath(var.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindBase::AddCMakeVariablePath()
|
||||
{
|
||||
if(!this->NoCMakePath &&
|
||||
!(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
|
||||
{
|
||||
// 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.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindBase::AddSystemEnvironmentPath()
|
||||
{
|
||||
if(!this->NoSystemEnvironmentPath &&
|
||||
!(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
|
||||
{
|
||||
// Add LIB or INCLUDE
|
||||
if(!this->EnvironmentPath.empty())
|
||||
{
|
||||
view = cmSystemTools::KeyWOW64_64;
|
||||
other_view = cmSystemTools::KeyWOW64_32;
|
||||
this->AddEnvPath(this->EnvironmentPath.c_str());
|
||||
}
|
||||
// Add PATH
|
||||
this->AddEnvPath(0);
|
||||
}
|
||||
std::vector<std::string> finalPath;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindBase::AddCMakeSystemVariablePath()
|
||||
{
|
||||
if(!this->NoCMakeSystemPath &&
|
||||
!(this->SearchFrameworkOnly || this->SearchAppBundleOnly))
|
||||
{
|
||||
std::string var = "CMAKE_SYSTEM_";
|
||||
var += this->CMakePathName;
|
||||
var += "_PATH";
|
||||
this->AddCMakePrefixPath("CMAKE_SYSTEM_PREFIX_PATH");
|
||||
this->AddCMakePath(var.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindBase::AddPathSuffixes()
|
||||
{
|
||||
std::vector<std::string>& paths = this->SearchPaths;
|
||||
std::vector<std::string> finalPath = paths;
|
||||
std::vector<std::string>::iterator i;
|
||||
// glob and expand registry stuff from paths and put
|
||||
// into finalPath
|
||||
for(i = paths.begin();
|
||||
i != paths.end(); ++i)
|
||||
{
|
||||
std::string expanded = *i;
|
||||
cmSystemTools::ExpandRegistryValues(expanded, view);
|
||||
cmSystemTools::GlobDirs(expanded.c_str(), finalPath);
|
||||
if(expanded != *i && this->CMakePathName == "PROGRAM")
|
||||
{
|
||||
// Executables can be either 32-bit or 64-bit.
|
||||
expanded = *i;
|
||||
cmSystemTools::ExpandRegistryValues(expanded, other_view);
|
||||
cmSystemTools::GlobDirs(expanded.c_str(), finalPath);
|
||||
}
|
||||
}
|
||||
// clear the path
|
||||
paths.clear();
|
||||
// convert all paths to unix slashes and add search path suffixes
|
||||
|
|
|
@ -41,19 +41,9 @@ public:
|
|||
|
||||
protected:
|
||||
void PrintFindStuff();
|
||||
void ExpandPaths(std::vector<std::string> userPaths);
|
||||
void ExpandPaths();
|
||||
void AddPathSuffixes();
|
||||
|
||||
// add to the SearchPaths
|
||||
void AddPaths(std::vector<std::string>& paths);
|
||||
void AddFrameWorkPaths();
|
||||
void AddAppBundlePaths();
|
||||
void AddEnvironmentVariables();
|
||||
void AddFindPrefix(std::vector<std::string>& dest,
|
||||
const std::vector<std::string>& src);
|
||||
void AddCMakeVariables();
|
||||
void AddSystemEnvironmentVariables();
|
||||
void AddCMakeSystemVariables();
|
||||
void ExpandRegistryAndCleanPath(std::vector<std::string>& paths);
|
||||
// see if the VariableName is already set in the cache,
|
||||
// also copy the documentation from the cache to VariableDocumentation
|
||||
// if it has documentation in the cache
|
||||
|
@ -64,13 +54,27 @@ protected:
|
|||
cmStdString VariableDocumentation;
|
||||
cmStdString VariableName;
|
||||
std::vector<std::string> Names;
|
||||
std::vector<std::string> SearchPaths;
|
||||
|
||||
// CMAKE_*_PATH CMAKE_SYSTEM_*_PATH FRAMEWORK|LIBRARY|INCLUDE|PROGRAM
|
||||
cmStdString EnvironmentPath; // LIB,INCLUDE
|
||||
|
||||
bool AlreadyInCache;
|
||||
bool AlreadyInCacheWithoutMetaInfo;
|
||||
private:
|
||||
// Add pieces of the search.
|
||||
void AddFrameworkPath();
|
||||
void AddAppBundlePath();
|
||||
void AddCMakeEnvironmentPath();
|
||||
void AddCMakeVariablePath();
|
||||
void AddSystemEnvironmentPath();
|
||||
void AddCMakeSystemVariablePath();
|
||||
|
||||
// Helpers.
|
||||
void AddMacPath(const char* var, const char* sysvar);
|
||||
void AddCMakePrefixPath(const char* variable);
|
||||
void AddEnvPrefixPath(const char* variable);
|
||||
void AddPrefixPaths(std::vector<std::string> const& in_paths,
|
||||
PathType pathType);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -322,93 +322,39 @@ void cmFindCommon::AddPathSuffix(std::string const& arg)
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindCommon::GetAppBundlePaths(std::vector<std::string>& paths)
|
||||
void cmFindCommon::AddUserPath(std::string const& p)
|
||||
{
|
||||
if(this->NoDefaultPath)
|
||||
// We should view the registry as the target application would view
|
||||
// it.
|
||||
cmSystemTools::KeyWOW64 view = cmSystemTools::KeyWOW64_32;
|
||||
cmSystemTools::KeyWOW64 other_view = cmSystemTools::KeyWOW64_64;
|
||||
if(const char* psize =
|
||||
this->Makefile->GetDefinition("CMAKE_SIZEOF_VOID_P"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::vector<std::string> tmp;
|
||||
|
||||
// first environment variables
|
||||
if(!this->NoCMakeEnvironmentPath)
|
||||
{
|
||||
cmSystemTools::GetPath(tmp, "CMAKE_APPBUNDLE_PATH");
|
||||
this->AddPathsInternal(paths, tmp, EnvPath);
|
||||
tmp.clear();
|
||||
}
|
||||
|
||||
// add cmake variables
|
||||
if(!this->NoCMakePath)
|
||||
{
|
||||
if(const char* path =
|
||||
this->Makefile->GetDefinition("CMAKE_APPBUNDLE_PATH"))
|
||||
if(atoi(psize) == 8)
|
||||
{
|
||||
cmSystemTools::ExpandListArgument(path, tmp);
|
||||
this->AddPathsInternal(paths, tmp, CMakePath);
|
||||
tmp.clear();
|
||||
view = cmSystemTools::KeyWOW64_64;
|
||||
other_view = cmSystemTools::KeyWOW64_32;
|
||||
}
|
||||
}
|
||||
|
||||
// add cmake system variables
|
||||
if(!this->NoCMakeSystemPath)
|
||||
// Expand using the view of the target application.
|
||||
std::string expanded = p;
|
||||
cmSystemTools::ExpandRegistryValues(expanded, view);
|
||||
cmSystemTools::GlobDirs(expanded.c_str(), this->UserPaths);
|
||||
|
||||
// Executables can be either 32-bit or 64-bit, so expand using the
|
||||
// alternative view.
|
||||
if(expanded != p && this->CMakePathName == "PROGRAM")
|
||||
{
|
||||
if(const char* path =
|
||||
this->Makefile->GetDefinition("CMAKE_SYSTEM_APPBUNDLE_PATH"))
|
||||
{
|
||||
cmSystemTools::ExpandListArgument(path, tmp);
|
||||
this->AddPathsInternal(paths, tmp, CMakePath);
|
||||
tmp.clear();
|
||||
}
|
||||
expanded = p;
|
||||
cmSystemTools::ExpandRegistryValues(expanded, other_view);
|
||||
cmSystemTools::GlobDirs(expanded.c_str(), this->UserPaths);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindCommon::GetFrameworkPaths(std::vector<std::string>& paths)
|
||||
{
|
||||
if(this->NoDefaultPath)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::vector<std::string> tmp;
|
||||
|
||||
// first environment variables
|
||||
if(!this->NoCMakeEnvironmentPath)
|
||||
{
|
||||
cmSystemTools::GetPath(tmp, "CMAKE_FRAMEWORK_PATH");
|
||||
this->AddPathsInternal(paths, tmp, EnvPath);
|
||||
tmp.clear();
|
||||
}
|
||||
|
||||
// add cmake variables
|
||||
if(!this->NoCMakePath)
|
||||
{
|
||||
if(const char* path =
|
||||
this->Makefile->GetDefinition("CMAKE_FRAMEWORK_PATH"))
|
||||
{
|
||||
cmSystemTools::ExpandListArgument(path, tmp);
|
||||
this->AddPathsInternal(paths, tmp, CMakePath);
|
||||
tmp.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// add cmake system variables
|
||||
if(!this->NoCMakeSystemPath)
|
||||
{
|
||||
if(const char* path =
|
||||
this->Makefile->GetDefinition("CMAKE_SYSTEM_FRAMEWORK_PATH"))
|
||||
{
|
||||
cmSystemTools::ExpandListArgument(path, tmp);
|
||||
this->AddPathsInternal(paths, tmp, CMakePath);
|
||||
tmp.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindCommon::AddCMakePath(std::vector<std::string>& out_paths,
|
||||
const char* variable,
|
||||
std::set<cmStdString>* emmitted)
|
||||
void cmFindCommon::AddCMakePath(const char* variable)
|
||||
{
|
||||
// Get a path from a CMake variable.
|
||||
if(const char* varPath = this->Makefile->GetDefinition(variable))
|
||||
|
@ -418,14 +364,12 @@ void cmFindCommon::AddCMakePath(std::vector<std::string>& out_paths,
|
|||
|
||||
// Relative paths are interpreted with respect to the current
|
||||
// source directory.
|
||||
this->AddPathsInternal(out_paths, tmp, CMakePath, emmitted);
|
||||
this->AddPathsInternal(tmp, CMakePath);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindCommon::AddEnvPath(std::vector<std::string>& out_paths,
|
||||
const char* variable,
|
||||
std::set<cmStdString>* emmitted)
|
||||
void cmFindCommon::AddEnvPath(const char* variable)
|
||||
{
|
||||
// Get a path from the environment.
|
||||
std::vector<std::string> tmp;
|
||||
|
@ -433,27 +377,23 @@ void cmFindCommon::AddEnvPath(std::vector<std::string>& out_paths,
|
|||
|
||||
// Relative paths are interpreted with respect to the current
|
||||
// working directory.
|
||||
this->AddPathsInternal(out_paths, tmp, EnvPath, emmitted);
|
||||
this->AddPathsInternal(tmp, EnvPath);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindCommon::AddPathsInternal(std::vector<std::string>& out_paths,
|
||||
std::vector<std::string> const& in_paths,
|
||||
PathType pathType,
|
||||
std::set<cmStdString>* emmitted)
|
||||
void cmFindCommon::AddPathsInternal(std::vector<std::string> const& in_paths,
|
||||
PathType pathType)
|
||||
{
|
||||
for(std::vector<std::string>::const_iterator i = in_paths.begin();
|
||||
i != in_paths.end(); ++i)
|
||||
{
|
||||
this->AddPathInternal(out_paths, *i, pathType, emmitted);
|
||||
this->AddPathInternal(*i, pathType);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindCommon::AddPathInternal(std::vector<std::string>& out_paths,
|
||||
std::string const& in_path,
|
||||
PathType pathType,
|
||||
std::set<cmStdString>* emmitted)
|
||||
void cmFindCommon::AddPathInternal(std::string const& in_path,
|
||||
PathType pathType)
|
||||
{
|
||||
if(in_path.empty())
|
||||
{
|
||||
|
@ -471,9 +411,9 @@ void cmFindCommon::AddPathInternal(std::vector<std::string>& out_paths,
|
|||
std::string fullPath =
|
||||
cmSystemTools::CollapseFullPath(in_path.c_str(), relbase);
|
||||
|
||||
// Insert the path if has not already been emmitted.
|
||||
if(!emmitted || emmitted->insert(fullPath).second)
|
||||
// Insert the path if has not already been emitted.
|
||||
if(this->SearchPathsEmitted.insert(fullPath).second)
|
||||
{
|
||||
out_paths.push_back(fullPath.c_str());
|
||||
this->SearchPaths.push_back(fullPath.c_str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,21 +55,12 @@ protected:
|
|||
|
||||
bool CheckCommonArgument(std::string const& arg);
|
||||
void AddPathSuffix(std::string const& arg);
|
||||
void GetAppBundlePaths(std::vector<std::string>& paths);
|
||||
void GetFrameworkPaths(std::vector<std::string>& paths);
|
||||
|
||||
void AddCMakePath(std::vector<std::string>& out_paths,
|
||||
const char* variable, std::set<cmStdString>* emmitted = 0);
|
||||
void AddEnvPath(std::vector<std::string>& out_paths,
|
||||
const char* variable, std::set<cmStdString>* emmitted = 0);
|
||||
void AddPathsInternal(std::vector<std::string>& out_paths,
|
||||
std::vector<std::string> const& in_paths,
|
||||
PathType pathType,
|
||||
std::set<cmStdString>* emmitted = 0);
|
||||
void AddPathInternal(std::vector<std::string>& out_paths,
|
||||
std::string const& in_path,
|
||||
PathType pathType,
|
||||
std::set<cmStdString>* emmitted = 0);
|
||||
void AddUserPath(std::string const& p);
|
||||
void AddCMakePath(const char* variable);
|
||||
void AddEnvPath(const char* variable);
|
||||
void AddPathsInternal(std::vector<std::string> const& in_paths,
|
||||
PathType pathType);
|
||||
void AddPathInternal(std::string const& in_path, PathType pathType);
|
||||
|
||||
bool NoDefaultPath;
|
||||
bool NoCMakePath;
|
||||
|
@ -78,6 +69,9 @@ protected:
|
|||
bool NoCMakeSystemPath;
|
||||
|
||||
std::vector<std::string> SearchPathSuffixes;
|
||||
std::vector<std::string> UserPaths;
|
||||
std::vector<std::string> SearchPaths;
|
||||
std::set<cmStdString> SearchPathsEmitted;
|
||||
|
||||
std::string GenericDocumentationMacPolicy;
|
||||
std::string GenericDocumentationRootPath;
|
||||
|
|
|
@ -821,8 +821,9 @@ void cmFindPackageCommand::FindConfig()
|
|||
//----------------------------------------------------------------------------
|
||||
bool cmFindPackageCommand::FindPrefixedConfig()
|
||||
{
|
||||
for(std::vector<std::string>::const_iterator pi = this->Prefixes.begin();
|
||||
pi != this->Prefixes.end(); ++pi)
|
||||
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))
|
||||
{
|
||||
|
@ -835,8 +836,9 @@ bool cmFindPackageCommand::FindPrefixedConfig()
|
|||
//----------------------------------------------------------------------------
|
||||
bool cmFindPackageCommand::FindFrameworkConfig()
|
||||
{
|
||||
for(std::vector<std::string>::const_iterator i = this->Prefixes.begin();
|
||||
i != this->Prefixes.end(); ++i)
|
||||
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))
|
||||
{
|
||||
|
@ -849,8 +851,9 @@ bool cmFindPackageCommand::FindFrameworkConfig()
|
|||
//----------------------------------------------------------------------------
|
||||
bool cmFindPackageCommand::FindAppBundleConfig()
|
||||
{
|
||||
for(std::vector<std::string>::const_iterator i = this->Prefixes.begin();
|
||||
i != this->Prefixes.end(); ++i)
|
||||
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))
|
||||
{
|
||||
|
@ -939,19 +942,20 @@ void cmFindPackageCommand::AppendSuccessInformation()
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindPackageCommand::AddUserPath(std::string const& p)
|
||||
void cmFindPackageCommand::ComputePrefixes()
|
||||
{
|
||||
std::string userPath = p;
|
||||
cmSystemTools::ExpandRegistryValues(userPath);
|
||||
this->UserPaths.push_back(userPath);
|
||||
this->AddPrefixesCMakeEnvironment();
|
||||
this->AddPrefixesCMakeVariable();
|
||||
this->AddPrefixesSystemEnvironment();
|
||||
this->AddPrefixesBuilds();
|
||||
this->AddPrefixesCMakeSystemVariable();
|
||||
this->AddPrefixesUser();
|
||||
this->ComputeFinalPrefixes();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindPackageCommand::ComputePrefixes()
|
||||
void cmFindPackageCommand::AddPrefixesCMakeEnvironment()
|
||||
{
|
||||
std::vector<std::string>& prefixes = this->Prefixes;
|
||||
std::set<cmStdString> emmitted;
|
||||
|
||||
if(!this->NoCMakeEnvironmentPath && !this->NoDefaultPath)
|
||||
{
|
||||
// Check the environment variable with the same name as the cache
|
||||
|
@ -960,21 +964,29 @@ void cmFindPackageCommand::ComputePrefixes()
|
|||
if(cmSystemTools::GetEnv(this->Variable.c_str(), env) && env.length() > 0)
|
||||
{
|
||||
cmSystemTools::ConvertToUnixSlashes(env);
|
||||
this->AddPathInternal(prefixes, env, EnvPath, &emmitted);
|
||||
this->AddPathInternal(env, EnvPath);
|
||||
}
|
||||
|
||||
this->AddEnvPath(prefixes, "CMAKE_PREFIX_PATH", &emmitted);
|
||||
this->AddEnvPath(prefixes, "CMAKE_FRAMEWORK_PATH", &emmitted);
|
||||
this->AddEnvPath(prefixes, "CMAKE_APPBUNDLE_PATH", &emmitted);
|
||||
this->AddEnvPath("CMAKE_PREFIX_PATH");
|
||||
this->AddEnvPath("CMAKE_FRAMEWORK_PATH");
|
||||
this->AddEnvPath("CMAKE_APPBUNDLE_PATH");
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindPackageCommand::AddPrefixesCMakeVariable()
|
||||
{
|
||||
if(!this->NoCMakePath && !this->NoDefaultPath)
|
||||
{
|
||||
this->AddCMakePath(prefixes, "CMAKE_PREFIX_PATH", &emmitted);
|
||||
this->AddCMakePath(prefixes, "CMAKE_FRAMEWORK_PATH", &emmitted);
|
||||
this->AddCMakePath(prefixes, "CMAKE_APPBUNDLE_PATH", &emmitted);
|
||||
this->AddCMakePath("CMAKE_PREFIX_PATH");
|
||||
this->AddCMakePath("CMAKE_FRAMEWORK_PATH");
|
||||
this->AddCMakePath("CMAKE_APPBUNDLE_PATH");
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindPackageCommand::AddPrefixesSystemEnvironment()
|
||||
{
|
||||
if(!this->NoSystemEnvironmentPath && !this->NoDefaultPath)
|
||||
{
|
||||
// Use the system search path to generate prefixes.
|
||||
|
@ -991,17 +1003,19 @@ void cmFindPackageCommand::ComputePrefixes()
|
|||
if(d.size() >= 4 && strcmp(d.c_str()+d.size()-4, "/bin") == 0 ||
|
||||
d.size() >= 5 && strcmp(d.c_str()+d.size()-5, "/sbin") == 0)
|
||||
{
|
||||
this->AddPathInternal(prefixes,
|
||||
cmSystemTools::GetFilenamePath(d),
|
||||
EnvPath, &emmitted);
|
||||
this->AddPathInternal(cmSystemTools::GetFilenamePath(d), EnvPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->AddPathInternal(prefixes, d, EnvPath, &emmitted);
|
||||
this->AddPathInternal(d, EnvPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindPackageCommand::AddPrefixesBuilds()
|
||||
{
|
||||
if(!this->NoBuilds && !this->NoDefaultPath)
|
||||
{
|
||||
// It is likely that CMake will have recently built the project.
|
||||
|
@ -1017,23 +1031,37 @@ void cmFindPackageCommand::ComputePrefixes()
|
|||
if(cmSystemTools::FileIsFullPath(f.c_str()) &&
|
||||
cmSystemTools::FileIsDirectory(f.c_str()))
|
||||
{
|
||||
this->AddPathInternal(prefixes, f, FullPath, &emmitted);
|
||||
this->AddPathInternal(f, FullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindPackageCommand::AddPrefixesCMakeSystemVariable()
|
||||
{
|
||||
if(!this->NoCMakeSystemPath && !this->NoDefaultPath)
|
||||
{
|
||||
this->AddCMakePath(prefixes, "CMAKE_SYSTEM_PREFIX_PATH", &emmitted);
|
||||
this->AddCMakePath(prefixes, "CMAKE_SYSTEM_FRAMEWORK_PATH", &emmitted);
|
||||
this->AddCMakePath(prefixes, "CMAKE_SYSTEM_APPBUNDLE_PATH", &emmitted);
|
||||
this->AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH");
|
||||
this->AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
|
||||
this->AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindPackageCommand::AddPrefixesUser()
|
||||
{
|
||||
if(!this->UserPaths.empty())
|
||||
{
|
||||
// Add paths specified by the caller.
|
||||
this->AddPathsInternal(prefixes, this->UserPaths, CMakePath, &emmitted);
|
||||
this->AddPathsInternal(this->UserPaths, CMakePath);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindPackageCommand::ComputeFinalPrefixes()
|
||||
{
|
||||
std::vector<std::string>& prefixes = this->SearchPaths;
|
||||
|
||||
// Construct the final set of prefixes.
|
||||
this->RerootPaths(prefixes);
|
||||
|
|
|
@ -82,8 +82,14 @@ private:
|
|||
bool ReadListFile(const char* f);
|
||||
void StoreVersionFound();
|
||||
|
||||
void AddUserPath(std::string const& p);
|
||||
void ComputePrefixes();
|
||||
void AddPrefixesCMakeEnvironment();
|
||||
void AddPrefixesCMakeVariable();
|
||||
void AddPrefixesSystemEnvironment();
|
||||
void AddPrefixesBuilds();
|
||||
void AddPrefixesCMakeSystemVariable();
|
||||
void AddPrefixesUser();
|
||||
void ComputeFinalPrefixes();
|
||||
bool SearchDirectory(std::string const& dir);
|
||||
bool CheckDirectory(std::string const& dir);
|
||||
bool FindConfigFile(std::string const& dir, std::string& file);
|
||||
|
@ -119,8 +125,6 @@ private:
|
|||
bool DebugMode;
|
||||
std::vector<std::string> Names;
|
||||
std::vector<std::string> Configs;
|
||||
std::vector<std::string> Prefixes;
|
||||
std::vector<std::string> UserPaths;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue