mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
find_*: Add a new PackageRoot search path group
The new PackageRoot search path group allows the PackageName_ROOT cmake and environment variables to be used as search prefixes for all find_* commands called from within a find module
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
#include "cmFindBase.h"
|
||||
|
||||
#include "cmConfigure.h"
|
||||
#include <deque>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -158,6 +160,9 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
|
||||
void cmFindBase::ExpandPaths()
|
||||
{
|
||||
if (!this->NoDefaultPath) {
|
||||
if (!this->NoPackageRootPath) {
|
||||
this->FillPackageRootPath();
|
||||
}
|
||||
if (!this->NoCMakePath) {
|
||||
this->FillCMakeVariablePath();
|
||||
}
|
||||
@@ -196,6 +201,23 @@ void cmFindBase::FillCMakeEnvironmentPath()
|
||||
paths.AddSuffixes(this->SearchPathSuffixes);
|
||||
}
|
||||
|
||||
void cmFindBase::FillPackageRootPath()
|
||||
{
|
||||
cmSearchPath& paths = this->LabeledPaths[PathLabel::PackageRoot];
|
||||
|
||||
// Add package specific search prefixes
|
||||
// NOTE: This should be using const_reverse_iterator but HP aCC and
|
||||
// Oracle sunCC both currently have standard library issues
|
||||
// with the reverse iterator APIs.
|
||||
for (std::deque<std::string>::reverse_iterator pkg =
|
||||
this->Makefile->FindPackageModuleStack.rbegin();
|
||||
pkg != this->Makefile->FindPackageModuleStack.rend(); ++pkg) {
|
||||
std::string varName = *pkg + "_ROOT";
|
||||
paths.AddCMakePrefixPath(varName);
|
||||
paths.AddEnvPrefixPath(varName);
|
||||
}
|
||||
}
|
||||
|
||||
void cmFindBase::FillCMakeVariablePath()
|
||||
{
|
||||
cmSearchPath& paths = this->LabeledPaths[PathLabel::CMake];
|
||||
|
@@ -50,6 +50,7 @@ protected:
|
||||
|
||||
private:
|
||||
// Add pieces of the search.
|
||||
void FillPackageRootPath();
|
||||
void FillCMakeVariablePath();
|
||||
void FillCMakeEnvironmentPath();
|
||||
void FillUserHintsPath();
|
||||
|
@@ -10,6 +10,8 @@
|
||||
#include "cmSystemTools.h"
|
||||
|
||||
cmFindCommon::PathGroup cmFindCommon::PathGroup::All("ALL");
|
||||
cmFindCommon::PathLabel cmFindCommon::PathLabel::PackageRoot(
|
||||
"PacakgeName_ROOT");
|
||||
cmFindCommon::PathLabel cmFindCommon::PathLabel::CMake("CMAKE");
|
||||
cmFindCommon::PathLabel cmFindCommon::PathLabel::CMakeEnvironment(
|
||||
"CMAKE_ENVIRONMENT");
|
||||
@@ -23,6 +25,7 @@ cmFindCommon::cmFindCommon()
|
||||
{
|
||||
this->FindRootPathMode = RootPathModeBoth;
|
||||
this->NoDefaultPath = false;
|
||||
this->NoPackageRootPath = false;
|
||||
this->NoCMakePath = false;
|
||||
this->NoCMakeEnvironmentPath = false;
|
||||
this->NoSystemEnvironmentPath = false;
|
||||
@@ -57,6 +60,7 @@ void cmFindCommon::InitializeSearchPathGroups()
|
||||
|
||||
// All search paths
|
||||
labels = &this->PathGroupLabelMap[PathGroup::All];
|
||||
labels->push_back(PathLabel::PackageRoot);
|
||||
labels->push_back(PathLabel::CMake);
|
||||
labels->push_back(PathLabel::CMakeEnvironment);
|
||||
labels->push_back(PathLabel::Hints);
|
||||
@@ -68,6 +72,8 @@ void cmFindCommon::InitializeSearchPathGroups()
|
||||
this->PathGroupOrder.push_back(PathGroup::All);
|
||||
|
||||
// Create the idividual labeld search paths
|
||||
this->LabeledPaths.insert(
|
||||
std::make_pair(PathLabel::PackageRoot, cmSearchPath(this)));
|
||||
this->LabeledPaths.insert(
|
||||
std::make_pair(PathLabel::CMake, cmSearchPath(this)));
|
||||
this->LabeledPaths.insert(
|
||||
@@ -271,10 +277,12 @@ bool cmFindCommon::CheckCommonArgument(std::string const& arg)
|
||||
{
|
||||
if (arg == "NO_DEFAULT_PATH") {
|
||||
this->NoDefaultPath = true;
|
||||
} else if (arg == "NO_CMAKE_ENVIRONMENT_PATH") {
|
||||
this->NoCMakeEnvironmentPath = true;
|
||||
} else if (arg == "NO_PACKAGE_ROOT_PATH") {
|
||||
this->NoPackageRootPath = true;
|
||||
} else if (arg == "NO_CMAKE_PATH") {
|
||||
this->NoCMakePath = true;
|
||||
} else if (arg == "NO_CMAKE_ENVIRONMENT_PATH") {
|
||||
this->NoCMakeEnvironmentPath = true;
|
||||
} else if (arg == "NO_SYSTEM_ENVIRONMENT_PATH") {
|
||||
this->NoSystemEnvironmentPath = true;
|
||||
} else if (arg == "NO_CMAKE_SYSTEM_PATH") {
|
||||
|
@@ -55,6 +55,7 @@ protected:
|
||||
: cmPathLabel(label)
|
||||
{
|
||||
}
|
||||
static PathLabel PackageRoot;
|
||||
static PathLabel CMake;
|
||||
static PathLabel CMakeEnvironment;
|
||||
static PathLabel Hints;
|
||||
@@ -105,6 +106,7 @@ protected:
|
||||
void AddPathSuffix(std::string const& arg);
|
||||
|
||||
bool NoDefaultPath;
|
||||
bool NoPackageRootPath;
|
||||
bool NoCMakePath;
|
||||
bool NoCMakeEnvironmentPath;
|
||||
bool NoSystemEnvironmentPath;
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "cmsys/String.h"
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
@@ -585,6 +586,9 @@ void cmFindPackageCommand::SetModuleVariables(const std::string& components)
|
||||
exact += "_FIND_VERSION_EXACT";
|
||||
this->AddFindDefinition(exact, this->VersionExact ? "1" : "0");
|
||||
}
|
||||
|
||||
// Push on to the pacakge stack
|
||||
this->Makefile->FindPackageModuleStack.push_back(this->Name);
|
||||
}
|
||||
|
||||
void cmFindPackageCommand::AddFindDefinition(const std::string& var,
|
||||
@@ -1059,6 +1063,9 @@ void cmFindPackageCommand::AppendSuccessInformation()
|
||||
|
||||
// Restore original state of "_FIND_" variables we set.
|
||||
this->RestoreFindDefinitions();
|
||||
|
||||
// Pop the package stack
|
||||
this->Makefile->FindPackageModuleStack.pop_back();
|
||||
}
|
||||
|
||||
void cmFindPackageCommand::ComputePrefixes()
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include "cmConfigure.h"
|
||||
|
||||
#include "cmsys/RegularExpression.hxx"
|
||||
#include <deque>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <stack>
|
||||
@@ -786,6 +787,10 @@ public:
|
||||
void RemoveExportBuildFileGeneratorCMP0024(cmExportBuildFileGenerator* gen);
|
||||
void AddExportBuildFileGenerator(cmExportBuildFileGenerator* gen);
|
||||
|
||||
// Maintain a stack of pacakge names to determine the depth of find modules
|
||||
// we are currently being called with
|
||||
std::deque<std::string> FindPackageModuleStack;
|
||||
|
||||
protected:
|
||||
// add link libraries and directories to the target
|
||||
void AddGlobalLinkInformation(cmTarget& target);
|
||||
|
Reference in New Issue
Block a user