Use containers of labeled search paths instead of individual members

Manage classes of search paths in labeled containers.  This removes the
need to have a seperate member variable for each type of search path, but
also allows path types to be grouped togethor in various different ways
and manipulated as subsets of the full set of search paths.
This commit is contained in:
Chuck Atkins 2014-10-17 13:07:26 -04:00
parent 2a9ac4bd83
commit 1abd7cd930
10 changed files with 339 additions and 106 deletions

View File

@ -43,7 +43,6 @@
#include "cmExecuteProcessCommand.cxx"
#include "cmExternalMakefileProjectGenerator.cxx"
#include "cmFindBase.cxx"
#include "cmSearchPath.cxx"
#include "cmFindCommon.cxx"
#include "cmFileCommand.cxx"
#include "cmFindFileCommand.cxx"
@ -53,6 +52,8 @@
#include "cmFindProgramCommand.cxx"
#include "cmForEachCommand.cxx"
#include "cmFunctionCommand.cxx"
#include "cmPathLabel.cxx"
#include "cmSearchPath.cxx"
void GetBootstrapCommands1(std::list<cmCommand*>& commands)
{

View File

@ -225,102 +225,112 @@ void cmFindBase::ExpandPaths()
//----------------------------------------------------------------------------
void cmFindBase::FillCMakeEnvironmentPath()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::CMakeEnvironment];
// Add CMAKE_*_PATH environment variables
std::string var = "CMAKE_";
var += this->CMakePathName;
var += "_PATH";
this->CMakeEnvironmentPaths.AddEnvPrefixPath("CMAKE_PREFIX_PATH");
this->CMakeEnvironmentPaths.AddEnvPath(var);
paths.AddEnvPrefixPath("CMAKE_PREFIX_PATH");
paths.AddEnvPath(var);
if(this->CMakePathName == "PROGRAM")
{
this->CMakeEnvironmentPaths.AddEnvPath("CMAKE_APPBUNDLE_PATH");
paths.AddEnvPath("CMAKE_APPBUNDLE_PATH");
}
else
{
this->CMakeEnvironmentPaths.AddEnvPath("CMAKE_FRAMEWORK_PATH");
paths.AddEnvPath("CMAKE_FRAMEWORK_PATH");
}
this->CMakeEnvironmentPaths.AddSuffixes(this->SearchPathSuffixes);
paths.AddSuffixes(this->SearchPathSuffixes);
}
//----------------------------------------------------------------------------
void cmFindBase::FillCMakeVariablePath()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::CMake];
// 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->CMakeVariablePaths.AddCMakePrefixPath("CMAKE_PREFIX_PATH");
this->CMakeVariablePaths.AddCMakePath(var);
paths.AddCMakePrefixPath("CMAKE_PREFIX_PATH");
paths.AddCMakePath(var);
if(this->CMakePathName == "PROGRAM")
{
this->CMakeVariablePaths.AddCMakePath("CMAKE_APPBUNDLE_PATH");
paths.AddCMakePath("CMAKE_APPBUNDLE_PATH");
}
else
{
this->CMakeVariablePaths.AddCMakePath("CMAKE_FRAMEWORK_PATH");
paths.AddCMakePath("CMAKE_FRAMEWORK_PATH");
}
this->CMakeVariablePaths.AddSuffixes(this->SearchPathSuffixes);
paths.AddSuffixes(this->SearchPathSuffixes);
}
//----------------------------------------------------------------------------
void cmFindBase::FillSystemEnvironmentPath()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::SystemEnvironment];
// Add LIB or INCLUDE
if(!this->EnvironmentPath.empty())
{
this->SystemEnvironmentPaths.AddEnvPath(this->EnvironmentPath);
paths.AddEnvPath(this->EnvironmentPath);
}
// Add PATH
this->SystemEnvironmentPaths.AddEnvPath("PATH");
this->SystemEnvironmentPaths.AddSuffixes(this->SearchPathSuffixes);
paths.AddEnvPath("PATH");
paths.AddSuffixes(this->SearchPathSuffixes);
}
//----------------------------------------------------------------------------
void cmFindBase::FillCMakeSystemVariablePath()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::CMakeSystem];
std::string var = "CMAKE_SYSTEM_";
var += this->CMakePathName;
var += "_PATH";
this->CMakeSystemVariablePaths.AddCMakePrefixPath(
"CMAKE_SYSTEM_PREFIX_PATH");
this->CMakeSystemVariablePaths.AddCMakePath(var);
paths.AddCMakePrefixPath("CMAKE_SYSTEM_PREFIX_PATH");
paths.AddCMakePath(var);
if(this->CMakePathName == "PROGRAM")
{
this->CMakeSystemVariablePaths.AddCMakePath(
"CMAKE_SYSTEM_APPBUNDLE_PATH");
paths.AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
}
else
{
this->CMakeSystemVariablePaths.AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
paths.AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
}
this->CMakeSystemVariablePaths.AddSuffixes(this->SearchPathSuffixes);
paths.AddSuffixes(this->SearchPathSuffixes);
}
//----------------------------------------------------------------------------
void cmFindBase::FillUserHintsPath()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::Hints];
for(std::vector<std::string>::const_iterator p = this->UserHintsArgs.begin();
p != this->UserHintsArgs.end(); ++p)
{
this->UserHintsPaths.AddUserPath(*p);
paths.AddUserPath(*p);
}
this->UserHintsPaths.AddSuffixes(this->SearchPathSuffixes);
paths.AddSuffixes(this->SearchPathSuffixes);
}
//----------------------------------------------------------------------------
void cmFindBase::FillUserGuessPath()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::Guess];
for(std::vector<std::string>::const_iterator p = this->UserGuessArgs.begin();
p != this->UserGuessArgs.end(); ++p)
{
this->UserGuessPaths.AddUserPath(*p);
paths.AddUserPath(*p);
}
this->UserGuessPaths.AddSuffixes(this->SearchPathSuffixes);
paths.AddSuffixes(this->SearchPathSuffixes);
}
//----------------------------------------------------------------------------

View File

@ -13,17 +13,19 @@
#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()
: CMakeVariablePaths(this, "CMAKE"),
CMakeEnvironmentPaths(this, "CMAKE_ENVIRONMENT"),
UserHintsPaths(this, "HINTS"),
SystemEnvironmentPaths(this, "SYSTEM_ENVIRONMENT"),
UserRegistryPaths(this, "USER_REGISTRY"),
BuildPaths(this, "BUILD"),
CMakeSystemVariablePaths(this, "CMAKE_SYSTEM_VARIABLE"),
SystemRegistryPaths(this, "SYSTEM_REGISTRY"),
UserGuessPaths(this, "GUESS")
{
this->FindRootPathMode = RootPathModeBoth;
this->NoDefaultPath = false;
@ -45,6 +47,8 @@ cmFindCommon::cmFindCommon()
this->SearchFrameworkLast = false;
this->SearchAppBundleOnly = false;
this->SearchAppBundleLast = false;
this->InitializeSearchPathGroups();
}
//----------------------------------------------------------------------------
@ -52,6 +56,40 @@ cmFindCommon::~cmFindCommon()
{
}
//----------------------------------------------------------------------------
void cmFindCommon::InitializeSearchPathGroups()
{
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()
{
@ -140,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 == RootPathModeNever)
{
return;
}
const char* sysroot =
this->Makefile->GetDefinition("CMAKE_SYSROOT");
const char* rootPath =
@ -361,15 +399,13 @@ void cmFindCommon::ComputeFinalPaths()
this->GetIgnoredPaths(ignored);
// Combine the seperate path types, filtering out ignores
this->CMakeVariablePaths.ExtractWithout(ignored, this->SearchPaths, true);
this->CMakeEnvironmentPaths.ExtractWithout(ignored, this->SearchPaths);
this->UserHintsPaths.ExtractWithout(ignored, this->SearchPaths);
this->SystemEnvironmentPaths.ExtractWithout(ignored, this->SearchPaths);
this->UserRegistryPaths.ExtractWithout(ignored, this->SearchPaths);
this->BuildPaths.ExtractWithout(ignored, this->SearchPaths);
this->CMakeSystemVariablePaths.ExtractWithout(ignored, this->SearchPaths);
this->SystemRegistryPaths.ExtractWithout(ignored, this->SearchPaths);
this->UserGuessPaths.ExtractWithout(ignored, this->SearchPaths);
this->SearchPaths.clear();
std::vector<PathLabel>& allLabels = this->PathGroupLabelMap[PathGroup::All];
for(std::vector<PathLabel>::const_iterator l = allLabels.begin();
l != allLabels.end(); ++l)
{
this->LabeledPaths[*l].ExtractWithout(ignored, this->SearchPaths);
}
// Expand list of paths inside all search roots.
this->RerootPaths(this->SearchPaths);

View File

@ -14,6 +14,7 @@
#include "cmCommand.h"
#include "cmSearchPath.h"
#include "cmPathLabel.h"
/** \class cmFindCommon
* \brief Base class for FIND_XXX implementations.
@ -32,10 +33,45 @@ public:
protected:
friend class cmSearchPath;
/* VS6 is broken and can't pass protected class definitions to child classes */
#if defined(_MSC_VER) && (_MSC_VER < 1300)
public:
#endif
/** Used to define groups of path labels */
class PathGroup : public cmPathLabel
{
protected:
PathGroup();
public:
PathGroup(const std::string& label) : cmPathLabel(label) { }
static PathGroup All;
};
/* Individual path types */
class PathLabel : public cmPathLabel
{
protected:
PathLabel();
public:
PathLabel(const std::string& label) : cmPathLabel(label) { }
static PathLabel CMake;
static PathLabel CMakeEnvironment;
static PathLabel Hints;
static PathLabel SystemEnvironment;
static PathLabel CMakeSystem;
static PathLabel Guess;
};
#if defined(_MSC_VER) && (_MSC_VER < 1300)
protected:
#endif
enum RootPathMode { RootPathModeNever,
RootPathModeOnly,
RootPathModeBoth };
/** Construct the various path groups and labels */
void InitializeSearchPathGroups();
/** Place a set of search paths under the search roots. */
void RerootPaths(std::vector<std::string>& paths);
@ -75,15 +111,11 @@ protected:
bool NoCMakeSystemPath;
std::vector<std::string> SearchPathSuffixes;
cmSearchPath CMakeVariablePaths;
cmSearchPath CMakeEnvironmentPaths;
cmSearchPath UserHintsPaths;
cmSearchPath SystemEnvironmentPaths;
cmSearchPath UserRegistryPaths;
cmSearchPath BuildPaths;
cmSearchPath CMakeSystemVariablePaths;
cmSearchPath SystemRegistryPaths;
cmSearchPath UserGuessPaths;
std::map<PathGroup, std::vector<PathLabel> > PathGroupLabelMap;
std::vector<PathGroup> PathGroupOrder;
std::map<std::string, PathLabel> PathLabelStringMap;
std::map<PathLabel, cmSearchPath> LabeledPaths;
std::vector<std::string> SearchPaths;
std::set<std::string> SearchPathsEmitted;

View File

@ -25,6 +25,14 @@
#include <StorageDefs.h>
#endif
//----------------------------------------------------------------------------
cmFindPackageCommand::PathLabel
cmFindPackageCommand::PathLabel::UserRegistry("PACKAGE_REGISTRY");
cmFindPackageCommand::PathLabel
cmFindPackageCommand::PathLabel::Builds("BUILDS");
cmFindPackageCommand::PathLabel
cmFindPackageCommand::PathLabel::SystemRegistry("SYSTEM_PACKAGE_REGISTRY");
//----------------------------------------------------------------------------
cmFindPackageCommand::cmFindPackageCommand()
{
@ -51,6 +59,33 @@ cmFindPackageCommand::cmFindPackageCommand()
this->VersionFoundTweak = 0;
this->VersionFoundCount = 0;
this->RequiredCMakeVersion = 0;
this->AppendSearchPathGroups();
}
//----------------------------------------------------------------------------
void cmFindPackageCommand::AppendSearchPathGroups()
{
std::vector<cmFindCommon::PathLabel>* labels;
// Update the All group with new paths
labels = &this->PathGroupLabelMap[PathGroup::All];
labels->insert(std::find(labels->begin(), labels->end(),
PathLabel::CMakeSystem),
PathLabel::UserRegistry);
labels->insert(std::find(labels->begin(), labels->end(),
PathLabel::CMakeSystem),
PathLabel::Builds);
labels->insert(std::find(labels->begin(), labels->end(), PathLabel::Guess),
PathLabel::SystemRegistry);
// Create the new path objects
this->LabeledPaths.insert(std::make_pair(PathLabel::UserRegistry,
cmSearchPath(this)));
this->LabeledPaths.insert(std::make_pair(PathLabel::Builds,
cmSearchPath(this)));
this->LabeledPaths.insert(std::make_pair(PathLabel::SystemRegistry,
cmSearchPath(this)));
}
//----------------------------------------------------------------------------
@ -1151,27 +1186,33 @@ void cmFindPackageCommand::ComputePrefixes()
//----------------------------------------------------------------------------
void cmFindPackageCommand::FillPrefixesCMakeEnvironment()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::CMakeEnvironment];
// Check the environment variable with the same name as the cache
// entry.
this->CMakeEnvironmentPaths.AddEnvPath(this->Variable);
paths.AddEnvPath(this->Variable);
// And now the general CMake environment variables
this->CMakeEnvironmentPaths.AddEnvPath("CMAKE_PREFIX_PATH");
this->CMakeEnvironmentPaths.AddEnvPath("CMAKE_FRAMEWORK_PATH");
this->CMakeEnvironmentPaths.AddEnvPath("CMAKE_APPBUNDLE_PATH");
paths.AddEnvPath("CMAKE_PREFIX_PATH");
paths.AddEnvPath("CMAKE_FRAMEWORK_PATH");
paths.AddEnvPath("CMAKE_APPBUNDLE_PATH");
}
//----------------------------------------------------------------------------
void cmFindPackageCommand::FillPrefixesCMakeVariable()
{
this->CMakeVariablePaths.AddCMakePath("CMAKE_PREFIX_PATH");
this->CMakeVariablePaths.AddCMakePath("CMAKE_FRAMEWORK_PATH");
this->CMakeVariablePaths.AddCMakePath("CMAKE_APPBUNDLE_PATH");
cmSearchPath &paths = this->LabeledPaths[PathLabel::CMake];
paths.AddCMakePath("CMAKE_PREFIX_PATH");
paths.AddCMakePath("CMAKE_FRAMEWORK_PATH");
paths.AddCMakePath("CMAKE_APPBUNDLE_PATH");
}
//----------------------------------------------------------------------------
void cmFindPackageCommand::FillPrefixesSystemEnvironment()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::SystemEnvironment];
// Use the system search path to generate prefixes.
// Relative paths are interpreted with respect to the current
// working directory.
@ -1184,12 +1225,11 @@ void cmFindPackageCommand::FillPrefixesSystemEnvironment()
if((cmHasLiteralSuffix(*i, "/bin")) ||
(cmHasLiteralSuffix(*i, "/sbin")))
{
this->SystemEnvironmentPaths.AddPath(
cmSystemTools::GetFilenamePath(*i));
paths.AddPath(cmSystemTools::GetFilenamePath(*i));
}
else
{
this->SystemEnvironmentPaths.AddPath(*i);
paths.AddPath(*i);
}
}
}
@ -1207,7 +1247,8 @@ void cmFindPackageCommand::FillPrefixesUserRegistry()
std::string fname = dir;
fname += "/cmake/packages/";
fname += Name;
this->LoadPackageRegistryDir(fname, this->UserRegistryPaths);
this->LoadPackageRegistryDir(fname,
this->LabeledPaths[PathLabel::UserRegistry]);
}
#else
if(const char* home = cmSystemTools::GetEnv("HOME"))
@ -1215,7 +1256,8 @@ void cmFindPackageCommand::FillPrefixesUserRegistry()
std::string dir = home;
dir += "/.cmake/packages/";
dir += this->Name;
this->LoadPackageRegistryDir(dir, this->UserRegistryPaths);
this->LoadPackageRegistryDir(dir,
this->LabeledPaths[PathLabel::UserRegistry]);
}
#endif
}
@ -1247,27 +1289,26 @@ void cmFindPackageCommand::FillPrefixesSystemRegistry()
void cmFindPackageCommand::LoadPackageRegistryWinUser()
{
// HKEY_CURRENT_USER\\Software shares 32-bit and 64-bit views.
this->LoadPackageRegistryWin(true, 0, this->UserRegistryPaths);
this->LoadPackageRegistryWin(true, 0,
this->LabeledPaths[PathLabel::UserRegistry]);
}
//----------------------------------------------------------------------------
void cmFindPackageCommand::LoadPackageRegistryWinSystem()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::SystemRegistry];
// HKEY_LOCAL_MACHINE\\SOFTWARE has separate 32-bit and 64-bit views.
// Prefer the target platform view first.
if(this->Makefile->PlatformIs64Bit())
{
this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY,
this->SystemRegistryPaths);
this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY,
this->SystemRegistryPaths);
this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY, paths);
this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY, paths);
}
else
{
this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY,
this->SystemRegistryPaths);
this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY,
this->SystemRegistryPaths);
this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY, paths);
this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY, paths);
}
}
@ -1421,6 +1462,8 @@ bool cmFindPackageCommand::CheckPackageRegistryEntry(const std::string& fname,
//----------------------------------------------------------------------------
void cmFindPackageCommand::FillPrefixesBuilds()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::Builds];
// It is likely that CMake will have recently built the project.
for(int i=0; i <= 10; ++i)
{
@ -1434,7 +1477,7 @@ void cmFindPackageCommand::FillPrefixesBuilds()
if(cmSystemTools::FileIsFullPath(f.c_str()) &&
cmSystemTools::FileIsDirectory(f.c_str()))
{
this->BuildPaths.AddPath(f);
paths.AddPath(f);
}
}
}
@ -1442,28 +1485,34 @@ void cmFindPackageCommand::FillPrefixesBuilds()
//----------------------------------------------------------------------------
void cmFindPackageCommand::FillPrefixesCMakeSystemVariable()
{
this->CMakeSystemVariablePaths.AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH");
this->CMakeSystemVariablePaths.AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
this->CMakeSystemVariablePaths.AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
cmSearchPath &paths = this->LabeledPaths[PathLabel::CMakeSystem];
paths.AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH");
paths.AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
paths.AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
}
//----------------------------------------------------------------------------
void cmFindPackageCommand::FillPrefixesUserGuess()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::Guess];
for(std::vector<std::string>::const_iterator p = this->UserGuessArgs.begin();
p != this->UserGuessArgs.end(); ++p)
{
this->UserGuessPaths.AddUserPath(*p);
paths.AddUserPath(*p);
}
}
//----------------------------------------------------------------------------
void cmFindPackageCommand::FillPrefixesUserHints()
{
cmSearchPath &paths = this->LabeledPaths[PathLabel::Hints];
for(std::vector<std::string>::const_iterator p = this->UserHintsArgs.begin();
p != this->UserHintsArgs.end(); ++p)
{
this->UserHintsPaths.AddUserPath(*p);
paths.AddUserPath(*p);
}
}

View File

@ -53,6 +53,21 @@ public:
cmTypeMacro(cmFindPackageCommand, cmFindCommon);
private:
class PathLabel : public cmFindCommon::PathLabel
{
protected:
PathLabel();
public:
PathLabel(const std::string& label) : cmFindCommon::PathLabel(label) { }
static PathLabel UserRegistry;
static PathLabel Builds;
static PathLabel SystemRegistry;
};
// Add additional search path labels and groups not present in the
// parent class
void AppendSearchPathGroups();
void AppendSuccessInformation();
void AppendToFoundProperty(bool found);
void SetModuleVariables(const std::string& components);

41
Source/cmPathLabel.cxx Normal file
View File

@ -0,0 +1,41 @@
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#include "cmPathLabel.h"
//----------------------------------------------------------------------------
cmPathLabel::cmPathLabel(const std::string& label)
: Label(label), Hash(0)
{
// Use a Jenkins one-at-a-time hash with under/over-flow protection
for(size_t i = 0; i < this->Label.size(); ++i)
{
this->Hash += this->Label[i];
this->Hash += ((this->Hash & 0x003FFFFF) << 10);
this->Hash ^= ((this->Hash & 0xFFFFFFC0) >> 6);
}
this->Hash += ((this->Hash & 0x1FFFFFFF) << 3);
this->Hash ^= ((this->Hash & 0xFFFFF800) >> 11);
this->Hash += ((this->Hash & 0x0001FFFF) << 15);
}
//----------------------------------------------------------------------------
bool cmPathLabel::operator < (const cmPathLabel& l) const
{
return this->Hash < l.Hash;
}
//----------------------------------------------------------------------------
bool cmPathLabel::operator == (const cmPathLabel& l) const
{
return this->Hash == l.Hash;
}

44
Source/cmPathLabel.h Normal file
View File

@ -0,0 +1,44 @@
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#ifndef cmPathLabel_h
#define cmPathLabel_h
#include "cmStandardIncludes.h"
/** \class cmPathLabel
* \brief Helper class for text based labels
*
* cmPathLabel is extended in different classes to act as an inheritable
* enum. Comparisons are done on a precomputed Jenkins hash of the string
* label for indexing and searchig.
*/
class cmPathLabel
{
public:
cmPathLabel(const std::string& label);
// The comparison operators are only for quick sorting and searching and
// in no way imply any lexicographical order of the label
bool operator < (const cmPathLabel& l) const;
bool operator == (const cmPathLabel& l) const;
const std::string& GetLabel() const { return this->Label; }
const unsigned int& GetHash() const { return this->Hash; }
protected:
cmPathLabel();
std::string Label;
unsigned int Hash;
};
#endif

View File

@ -14,10 +14,8 @@
#include "cmFindCommon.h"
//----------------------------------------------------------------------------
cmSearchPath::cmSearchPath(cmFindCommon* findCmd,
const std::string& groupLabel)
: FindName(findCmd->CMakePathName), Makefile(findCmd->Makefile),
Emitted(findCmd->SearchPathsEmitted), Label(groupLabel)
cmSearchPath::cmSearchPath(cmFindCommon* findCmd)
: FC(findCmd)
{
}
@ -55,13 +53,15 @@ void cmSearchPath::AddPath(const std::string& path)
//----------------------------------------------------------------------------
void cmSearchPath::AddUserPath(const std::string& path)
{
assert(this->FC != NULL);
std::vector<std::string> outPaths;
// 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())
if(this->FC->Makefile->PlatformIs64Bit())
{
view = cmSystemTools::KeyWOW64_64;
other_view = cmSystemTools::KeyWOW64_32;
@ -74,7 +74,7 @@ void cmSearchPath::AddUserPath(const std::string& path)
// Executables can be either 32-bit or 64-bit, so expand using the
// alternative view.
if(expanded != path && this->FindName == "PROGRAM")
if(expanded != path && this->FC->CMakePathName == "PROGRAM")
{
expanded = path;
cmSystemTools::ExpandRegistryValues(expanded, other_view);
@ -85,15 +85,17 @@ void cmSearchPath::AddUserPath(const std::string& path)
for(std::vector<std::string>::const_iterator p = outPaths.begin();
p != outPaths.end(); ++p)
{
this->AddPathInternal(*p, this->Makefile->GetCurrentDirectory());
this->AddPathInternal(*p, this->FC->Makefile->GetCurrentDirectory());
}
}
//----------------------------------------------------------------------------
void cmSearchPath::AddCMakePath(const std::string& variable)
{
assert(this->FC != NULL);
// Get a path from a CMake variable.
if(const char* value = this->Makefile->GetDefinition(variable))
if(const char* value = this->FC->Makefile->GetDefinition(variable))
{
std::vector<std::string> expanded;
cmSystemTools::ExpandListArgument(value, expanded);
@ -101,7 +103,7 @@ void cmSearchPath::AddCMakePath(const std::string& variable)
for(std::vector<std::string>::const_iterator p = expanded.begin();
p!= expanded.end(); ++p)
{
this->AddPathInternal(*p, this->Makefile->GetCurrentDirectory());
this->AddPathInternal(*p, this->FC->Makefile->GetCurrentDirectory());
}
}
}
@ -121,13 +123,15 @@ void cmSearchPath::AddEnvPath(const std::string& variable)
//----------------------------------------------------------------------------
void cmSearchPath::AddCMakePrefixPath(const std::string& variable)
{
assert(this->FC != NULL);
// Get a path from a CMake variable.
if(const char* value = this->Makefile->GetDefinition(variable))
if(const char* value = this->FC->Makefile->GetDefinition(variable))
{
std::vector<std::string> expanded;
cmSystemTools::ExpandListArgument(value, expanded);
this->AddPrefixPaths(expanded, this->Makefile->GetCurrentDirectory());
this->AddPrefixPaths(expanded, this->FC->Makefile->GetCurrentDirectory());
}
}
@ -176,18 +180,20 @@ void cmSearchPath::AddSuffixes(const std::vector<std::string>& suffixes)
void cmSearchPath::AddPrefixPaths(const std::vector<std::string>& paths,
const char *base)
{
assert(this->FC != NULL);
// default for programs
std::string subdir = "bin";
if (this->FindName == "INCLUDE")
if (this->FC->CMakePathName == "INCLUDE")
{
subdir = "include";
}
else if (this->FindName == "LIBRARY")
else if (this->FC->CMakePathName == "LIBRARY")
{
subdir = "lib";
}
else if (this->FindName == "FRAMEWORK")
else if (this->FC->CMakePathName == "FRAMEWORK")
{
subdir = ""; // ? what to do for frameworks ?
}
@ -203,7 +209,7 @@ void cmSearchPath::AddPrefixPaths(const std::vector<std::string>& paths,
if(subdir == "include" || subdir == "lib")
{
const char* arch =
this->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE");
this->FC->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE");
if(arch && *arch)
{
this->AddPathInternal(dir+subdir+"/"+arch, base);
@ -228,6 +234,8 @@ void cmSearchPath::AddPrefixPaths(const std::vector<std::string>& paths,
//----------------------------------------------------------------------------
void cmSearchPath::AddPathInternal(const std::string& path, const char *base)
{
assert(this->FC != NULL);
std::string collapsed = cmSystemTools::CollapseFullPath(path, base);
if(collapsed.empty())
@ -236,7 +244,7 @@ void cmSearchPath::AddPathInternal(const std::string& path, const char *base)
}
// Insert the path if has not already been emitted.
if(this->Emitted.insert(collapsed).second)
if(this->FC->SearchPathsEmitted.insert(collapsed).second)
{
this->Paths.push_back(collapsed);
}

View File

@ -17,7 +17,7 @@
class cmFindCommon;
/** \class cmSearchPath
* \brief Base class for FIND_XXX implementations.
* \brief Container for encapsulating a set of search paths
*
* cmSearchPath is a container that encapsulates search path construction and
* management
@ -25,10 +25,12 @@ class cmFindCommon;
class cmSearchPath
{
public:
cmSearchPath(cmFindCommon* findCmd, const std::string& groupLabel);
// cmSearchPath must be initialized from a valid pointer. The only reason
// for teh default is to allow it to be easily used in stl containers.
// Attempting to initialize with a NULL value will fail an assertion
cmSearchPath(cmFindCommon* findCmd = 0);
~cmSearchPath();
const std::string& GetLabel() const { return this->Label; }
const std::vector<std::string>& GetPaths() const { return this->Paths; }
void ExtractWithout(const std::set<std::string>& ignore,
@ -48,12 +50,7 @@ protected:
const char *base = 0);
void AddPathInternal(const std::string& path, const char *base = 0);
// Members collected from the calling find command
const std::string& FindName;
cmMakefile* const& Makefile;
std::set<std::string>& Emitted;
std::string Label;
cmFindCommon *FC;
std::vector<std::string> Paths;
};