summaryrefslogtreecommitdiffstats
path: root/Source/cmFindCommon.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmFindCommon.cxx')
-rw-r--r--Source/cmFindCommon.cxx206
1 files changed, 82 insertions, 124 deletions
diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx
index 10241f2..913985f 100644
--- a/Source/cmFindCommon.cxx
+++ b/Source/cmFindCommon.cxx
@@ -10,6 +10,19 @@
See the License for more information.
============================================================================*/
#include "cmFindCommon.h"
+#include <functional>
+#include <algorithm>
+
+//----------------------------------------------------------------------------
+cmFindCommon::PathGroup cmFindCommon::PathGroup::All("ALL");
+cmFindCommon::PathLabel cmFindCommon::PathLabel::CMake("CMAKE");
+cmFindCommon::PathLabel
+ cmFindCommon::PathLabel::CMakeEnvironment("CMAKE_ENVIRONMENT");
+cmFindCommon::PathLabel cmFindCommon::PathLabel::Hints("HINTS");
+cmFindCommon::PathLabel
+ cmFindCommon::PathLabel::SystemEnvironment("SYSTM_ENVIRONMENT");
+cmFindCommon::PathLabel cmFindCommon::PathLabel::CMakeSystem("CMAKE_SYSTEM");
+cmFindCommon::PathLabel cmFindCommon::PathLabel::Guess("GUESS");
//----------------------------------------------------------------------------
cmFindCommon::cmFindCommon()
@@ -34,6 +47,8 @@ cmFindCommon::cmFindCommon()
this->SearchFrameworkLast = false;
this->SearchAppBundleOnly = false;
this->SearchAppBundleLast = false;
+
+ this->InitializeSearchPathGroups();
}
//----------------------------------------------------------------------------
@@ -42,11 +57,42 @@ cmFindCommon::~cmFindCommon()
}
//----------------------------------------------------------------------------
-void cmFindCommon::SelectDefaultRootPathMode()
+void cmFindCommon::InitializeSearchPathGroups()
{
- // Use both by default.
- this->FindRootPathMode = RootPathModeBoth;
+ std::vector<PathLabel>* labels;
+
+ // Define the varoius different groups of path types
+
+ // All search paths
+ labels = &this->PathGroupLabelMap[PathGroup::All];
+ labels->push_back(PathLabel::CMake);
+ labels->push_back(PathLabel::CMakeEnvironment);
+ labels->push_back(PathLabel::Hints);
+ labels->push_back(PathLabel::SystemEnvironment);
+ labels->push_back(PathLabel::CMakeSystem);
+ labels->push_back(PathLabel::Guess);
+
+ // Define the search group order
+ this->PathGroupOrder.push_back(PathGroup::All);
+
+ // Create the idividual labeld search paths
+ this->LabeledPaths.insert(std::make_pair(PathLabel::CMake,
+ cmSearchPath(this)));
+ this->LabeledPaths.insert(std::make_pair(PathLabel::CMakeEnvironment,
+ cmSearchPath(this)));
+ this->LabeledPaths.insert(std::make_pair(PathLabel::Hints,
+ cmSearchPath(this)));
+ this->LabeledPaths.insert(std::make_pair(PathLabel::SystemEnvironment,
+ cmSearchPath(this)));
+ this->LabeledPaths.insert(std::make_pair(PathLabel::CMakeSystem,
+ cmSearchPath(this)));
+ this->LabeledPaths.insert(std::make_pair(PathLabel::Guess,
+ cmSearchPath(this)));
+}
+//----------------------------------------------------------------------------
+void cmFindCommon::SelectDefaultRootPathMode()
+{
// Check the policy variable for this find command type.
std::string findRootPathVar = "CMAKE_FIND_ROOT_PATH_MODE_";
findRootPathVar += this->CMakePathName;
@@ -54,11 +100,11 @@ void cmFindCommon::SelectDefaultRootPathMode()
this->Makefile->GetSafeDefinition(findRootPathVar);
if (rootPathMode=="NEVER")
{
- this->FindRootPathMode = RootPathModeNoRootPath;
+ this->FindRootPathMode = RootPathModeNever;
}
else if (rootPathMode=="ONLY")
{
- this->FindRootPathMode = RootPathModeOnlyRootPath;
+ this->FindRootPathMode = RootPathModeOnly;
}
else if (rootPathMode=="BOTH")
{
@@ -132,12 +178,12 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths)
fprintf(stderr, "[%s]\n", i->c_str());
}
#endif
-
// Short-circuit if there is nothing to do.
- if(this->FindRootPathMode == RootPathModeNoRootPath)
+ if(this->FindRootPathMode == RootPathModeNever)
{
return;
}
+
const char* sysroot =
this->Makefile->GetDefinition("CMAKE_SYSROOT");
const char* rootPath =
@@ -182,9 +228,9 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths)
// already inside. Skip the unrooted path if it is relative to
// a user home directory or is empty.
std::string rootedDir;
- if(cmSystemTools::IsSubDirectory(ui->c_str(), ri->c_str())
+ if(cmSystemTools::IsSubDirectory(*ui, *ri)
|| (stagePrefix
- && cmSystemTools::IsSubDirectory(ui->c_str(), stagePrefix)))
+ && cmSystemTools::IsSubDirectory(*ui, stagePrefix)))
{
rootedDir = *ui;
}
@@ -195,7 +241,7 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths)
rootedDir += "/";
// Append the original path with its old root removed.
- rootedDir += cmSystemTools::SplitPathRootComponent(ui->c_str());
+ rootedDir += cmSystemTools::SplitPathRootComponent(*ui);
}
// Store the new path.
@@ -212,24 +258,20 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths)
}
//----------------------------------------------------------------------------
-void cmFindCommon::FilterPaths(std::vector<std::string>& paths,
- const std::set<std::string>& ignore)
+void cmFindCommon::FilterPaths(const std::vector<std::string>& inPaths,
+ const std::set<std::string>& ignore,
+ std::vector<std::string>& outPaths)
{
- // Now filter out anything that's in the ignore set.
- std::vector<std::string> unfiltered;
- unfiltered.swap(paths);
-
- for(std::vector<std::string>::iterator pi = unfiltered.begin();
- pi != unfiltered.end(); ++pi)
+ for(std::vector<std::string>::const_iterator i = inPaths.begin();
+ i != inPaths.end(); ++i)
{
- if (ignore.count(*pi) == 0)
+ if(ignore.count(*i) == 0)
{
- paths.push_back(*pi);
+ outPaths.push_back(*i);
}
}
}
-
//----------------------------------------------------------------------------
void cmFindCommon::GetIgnoredPaths(std::vector<std::string>& ignore)
{
@@ -266,8 +308,6 @@ void cmFindCommon::GetIgnoredPaths(std::set<std::string>& ignore)
ignore.insert(ignoreVec.begin(), ignoreVec.end());
}
-
-
//----------------------------------------------------------------------------
bool cmFindCommon::CheckCommonArgument(std::string const& arg)
{
@@ -291,13 +331,13 @@ bool cmFindCommon::CheckCommonArgument(std::string const& arg)
{
this->NoCMakeSystemPath = true;
}
- else if(arg == "NO_CMAKE_FIND_ROOT_PATH")
+ else if(arg == "NO_CMAKE_FIND_ROOT_PATH")
{
- this->FindRootPathMode = RootPathModeNoRootPath;
+ this->FindRootPathMode = RootPathModeNever;
}
else if(arg == "ONLY_CMAKE_FIND_ROOT_PATH")
{
- this->FindRootPathMode = RootPathModeOnlyRootPath;
+ this->FindRootPathMode = RootPathModeOnly;
}
else if(arg == "CMAKE_FIND_ROOT_PATH_BOTH")
{
@@ -345,116 +385,34 @@ void cmFindCommon::AddPathSuffix(std::string const& arg)
}
//----------------------------------------------------------------------------
-void cmFindCommon::AddUserPath(std::string const& p,
- std::vector<std::string>& paths)
-{
- // 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(this->Makefile->PlatformIs64Bit())
- {
- view = cmSystemTools::KeyWOW64_64;
- other_view = cmSystemTools::KeyWOW64_32;
- }
-
- // Expand using the view of the target application.
- std::string expanded = p;
- cmSystemTools::ExpandRegistryValues(expanded, view);
- cmSystemTools::GlobDirs(expanded, paths);
-
- // Executables can be either 32-bit or 64-bit, so expand using the
- // alternative view.
- if(expanded != p && this->CMakePathName == "PROGRAM")
- {
- expanded = p;
- cmSystemTools::ExpandRegistryValues(expanded, other_view);
- cmSystemTools::GlobDirs(expanded, paths);
- }
-}
-
-//----------------------------------------------------------------------------
-void cmFindCommon::AddCMakePath(const std::string& variable)
-{
- // Get a path from a CMake variable.
- if(const char* varPath = this->Makefile->GetDefinition(variable))
- {
- std::vector<std::string> tmp;
- cmSystemTools::ExpandListArgument(varPath, tmp);
-
- // Relative paths are interpreted with respect to the current
- // source directory.
- this->AddPathsInternal(tmp, CMakePath);
- }
-}
-
-//----------------------------------------------------------------------------
-void cmFindCommon::AddEnvPath(const char* variable)
-{
- // Get a path from the environment.
- std::vector<std::string> tmp;
- cmSystemTools::GetPath(tmp, variable);
- // Relative paths are interpreted with respect to the current
- // working directory.
- this->AddPathsInternal(tmp, EnvPath);
-}
-
-//----------------------------------------------------------------------------
-void cmFindCommon::AddPathsInternal(std::vector<std::string> const& in_paths,
- PathType pathType)
+void AddTrailingSlash(std::string& s)
{
- for(std::vector<std::string>::const_iterator i = in_paths.begin();
- i != in_paths.end(); ++i)
+ if(!s.empty() && *s.rbegin() != '/')
{
- this->AddPathInternal(*i, pathType);
+ s += '/';
}
}
-
-//----------------------------------------------------------------------------
-void cmFindCommon::AddPathInternal(std::string const& in_path,
- PathType pathType)
+void cmFindCommon::ComputeFinalPaths()
{
- if(in_path.empty())
- {
- return;
- }
+ // Filter out ignored paths from the prefix list
+ std::set<std::string> ignored;
+ this->GetIgnoredPaths(ignored);
- // Select the base path with which to interpret relative paths.
- const char* relbase = 0;
- if(pathType == CMakePath)
+ // Combine the seperate path types, filtering out ignores
+ this->SearchPaths.clear();
+ std::vector<PathLabel>& allLabels = this->PathGroupLabelMap[PathGroup::All];
+ for(std::vector<PathLabel>::const_iterator l = allLabels.begin();
+ l != allLabels.end(); ++l)
{
- relbase = this->Makefile->GetCurrentDirectory();
+ this->LabeledPaths[*l].ExtractWithout(ignored, this->SearchPaths);
}
- // Convert to clean full path.
- std::string fullPath =
- cmSystemTools::CollapseFullPath(in_path.c_str(), relbase);
-
- // Insert the path if has not already been emitted.
- if(this->SearchPathsEmitted.insert(fullPath).second)
- {
- this->SearchPaths.push_back(fullPath);
- }
-}
-
-//----------------------------------------------------------------------------
-void cmFindCommon::ComputeFinalPaths()
-{
- std::vector<std::string>& paths = this->SearchPaths;
-
// Expand list of paths inside all search roots.
- this->RerootPaths(paths);
+ this->RerootPaths(this->SearchPaths);
// Add a trailing slash to all paths to aid the search process.
- for(std::vector<std::string>::iterator i = paths.begin();
- i != paths.end(); ++i)
- {
- std::string& p = *i;
- if(!p.empty() && p[p.size()-1] != '/')
- {
- p += "/";
- }
- }
+ std::for_each(this->SearchPaths.begin(), this->SearchPaths.end(),
+ &AddTrailingSlash);
}
//----------------------------------------------------------------------------