summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2010-08-12 15:20:47 -0700
committerBrad King <brad.king@kitware.com>2010-08-13 11:53:28 -0400
commit1221581aa8de2b4bb06e09894940dba6ff90caa1 (patch)
tree0b2559f8f54e203d189056464c48e8d096ab73da /Source
parent7b632e5ac62cb2af74025b71660a1c5822fcfc39 (diff)
downloadcmake-1221581aa8de2b4bb06e09894940dba6ff90caa1.tar.gz
Teach find_* commands to ignore some paths
Add platform configuration variable CMAKE_SYSTEM_IGNORE_PATH and user configuration variable CMAKE_IGNORE_PATH. These specify a set of directories that will be ignored by all the find commands. Update FindPackageTest so that several cases will fail without a functioning CMAKE_IGNORE_PATH.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmDocumentVariables.cxx34
-rw-r--r--Source/cmFindBase.cxx5
-rw-r--r--Source/cmFindCommon.cxx57
-rw-r--r--Source/cmFindCommon.h8
-rw-r--r--Source/cmFindPackageCommand.cxx14
-rw-r--r--Source/cmFindPackageCommand.h1
6 files changed, 118 insertions, 1 deletions
diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx
index 2ed959f421..9617355516 100644
--- a/Source/cmDocumentVariables.cxx
+++ b/Source/cmDocumentVariables.cxx
@@ -587,7 +587,39 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
"directories for the current system. It is NOT intended "
"to be modified by the project, use CMAKE_PREFIX_PATH for this. See also "
"CMAKE_SYSTEM_INCLUDE_PATH, CMAKE_SYSTEM_LIBRARY_PATH, "
- "CMAKE_SYSTEM_PROGRAM_PATH.", false,
+ "CMAKE_SYSTEM_PROGRAM_PATH, and CMAKE_SYSTEM_IGNORE_PATH.", false,
+ "Variables That Change Behavior");
+
+ cm->DefineProperty
+ ("CMAKE_SYSTEM_IGNORE_PATH", cmProperty::VARIABLE,
+ "Path to be ignored by FIND_XXX() commands.",
+ "Specifies directories to be ignored by searches in FIND_XXX() commands "
+ "This is useful in cross-compiled environments where some system "
+ "directories contain incompatible but possibly linkable libraries. For "
+ "example, on cross-compiled cluster environments, this allows a user to "
+ "ignore directories containing libraries meant for the front-end "
+ "machine that modules like FindX11 (and others) would normally search. "
+ "By default this contains a list of directories containing incompatible "
+ "binaries for the host system. "
+ "See also CMAKE_SYSTEM_PREFIX_PATH, CMAKE_SYSTEM_LIBRARY_PATH, "
+ "CMAKE_SYSTEM_INCLUDE_PATH, and CMAKE_SYSTEM_PROGRAM_PATH.", false,
+ "Variables That Change Behavior");
+
+ cm->DefineProperty
+ ("CMAKE_IGNORE_PATH", cmProperty::VARIABLE,
+ "Path to be ignored by FIND_XXX() commands.",
+ "Specifies directories to be ignored by searches in FIND_XXX() commands "
+ "This is useful in cross-compiled environments where some system "
+ "directories contain incompatible but possibly linkable libraries. For "
+ "example, on cross-compiled cluster environments, this allows a user to "
+ "ignore directories containing libraries meant for the front-end "
+ "machine that modules like FindX11 (and others) would normally search. "
+ "By default this is empty; it is intended to be set by the project. "
+ "Note that CMAKE_IGNORE_PATH takes a list of directory names, NOT a "
+ "list of prefixes. If you want to ignore paths under prefixes (bin, "
+ "include, lib, etc.), you'll need to specify them explicitly. "
+ "See also CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_INCLUDE_PATH, "
+ "CMAKE_PROGRAM_PATH.", false,
"Variables That Change Behavior");
cm->DefineProperty
diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx
index a54ad7a902..e1188d5bb5 100644
--- a/Source/cmFindBase.cxx
+++ b/Source/cmFindBase.cxx
@@ -269,6 +269,11 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
}
this->ExpandPaths();
+ // Filter out ignored paths from the prefix list
+ std::set<std::string> ignored;
+ this->GetIgnoredPaths(ignored);
+ this->FilterPaths(this->SearchPaths, ignored);
+
// Handle search root stuff.
this->RerootPaths(this->SearchPaths);
diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx
index f352172626..b7d3e52f94 100644
--- a/Source/cmFindCommon.cxx
+++ b/Source/cmFindCommon.cxx
@@ -241,6 +241,63 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths)
}
//----------------------------------------------------------------------------
+void cmFindCommon::FilterPaths(std::vector<std::string>& paths,
+ const std::set<std::string>& ignore)
+{
+ // 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)
+ {
+ if (ignore.count(*pi) == 0)
+ {
+ paths.push_back(*pi);
+ }
+ }
+}
+
+
+//----------------------------------------------------------------------------
+void cmFindCommon::GetIgnoredPaths(std::vector<std::string>& ignore)
+{
+ // null-terminated list of paths.
+ static const char *paths[] =
+ { "CMAKE_SYSTEM_IGNORE_PATH", "CMAKE_IGNORE_PATH", 0 };
+
+ // Construct the list of path roots with no trailing slashes.
+ for(const char **pathName = paths; *pathName; ++pathName)
+ {
+ // Get the list of paths to ignore from the variable.
+ const char* ignorePath = this->Makefile->GetDefinition(*pathName);
+ if((ignorePath == 0) || (strlen(ignorePath) == 0))
+ {
+ continue;
+ }
+
+ cmSystemTools::ExpandListArgument(ignorePath, ignore);
+ }
+
+ for(std::vector<std::string>::iterator i = ignore.begin();
+ i != ignore.end(); ++i)
+ {
+ cmSystemTools::ConvertToUnixSlashes(*i);
+ }
+}
+
+
+//----------------------------------------------------------------------------
+void cmFindCommon::GetIgnoredPaths(std::set<std::string>& ignore)
+{
+ std::vector<std::string> ignoreVec;
+ GetIgnoredPaths(ignoreVec);
+ ignore.insert(ignoreVec.begin(), ignoreVec.end());
+}
+
+
+
+//----------------------------------------------------------------------------
bool cmFindCommon::CheckCommonArgument(std::string const& arg)
{
if(arg == "NO_DEFAULT_PATH")
diff --git a/Source/cmFindCommon.h b/Source/cmFindCommon.h
index 2ffbd0053b..a4866ba6f9 100644
--- a/Source/cmFindCommon.h
+++ b/Source/cmFindCommon.h
@@ -39,6 +39,14 @@ protected:
/** Place a set of search paths under the search roots. */
void RerootPaths(std::vector<std::string>& paths);
+ /** Get ignored paths from CMAKE_[SYSTEM_]IGNORE_path variables. */
+ void GetIgnoredPaths(std::vector<std::string>& ignore);
+ void GetIgnoredPaths(std::set<std::string>& ignore);
+
+ /** Remove paths in the ignore set from the supplied vector. */
+ void FilterPaths(std::vector<std::string>& paths,
+ const std::set<std::string>& ignore);
+
/** Add trailing slashes to all search paths. */
void AddTrailingSlashes(std::vector<std::string>& paths);
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index bd58f566a9..eb860143e5 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -596,6 +596,15 @@ bool cmFindPackageCommand
}
}
+ // get igonored paths from vars and reroot them.
+ std::vector<std::string> ignored;
+ this->GetIgnoredPaths(ignored);
+ this->RerootPaths(ignored);
+
+ // Construct a set of ignored paths
+ this->IgnoredPaths.clear();
+ this->IgnoredPaths.insert(ignored.begin(), ignored.end());
+
// Find and load the package.
bool result = this->HandlePackageMode();
this->AppendSuccessInformation();
@@ -1431,6 +1440,11 @@ bool cmFindPackageCommand::CheckDirectory(std::string const& dir)
bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
std::string& file)
{
+ if (this->IgnoredPaths.count(dir))
+ {
+ return false;
+ }
+
for(std::vector<std::string>::const_iterator ci = this->Configs.begin();
ci != this->Configs.end(); ++ci)
{
diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h
index 63f4111618..53ea4fc091 100644
--- a/Source/cmFindPackageCommand.h
+++ b/Source/cmFindPackageCommand.h
@@ -136,6 +136,7 @@ private:
bool PolicyScope;
std::vector<std::string> Names;
std::vector<std::string> Configs;
+ std::set<std::string> IgnoredPaths;
};
#endif