summaryrefslogtreecommitdiffstats
path: root/Source/cmFindPathCommand.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2008-06-09 15:58:29 (GMT)
committerBrad King <brad.king@kitware.com>2008-06-09 15:58:29 (GMT)
commit6706f84cd997d39026080e47e4944072add7f925 (patch)
treee047d48fd75fbcb0a58f50fdffc3359226710c7e /Source/cmFindPathCommand.cxx
parentd53e5dec3748e1d800dae595dcb78f2c4d55f788 (diff)
downloadCMake-6706f84cd997d39026080e47e4944072add7f925.zip
CMake-6706f84cd997d39026080e47e4944072add7f925.tar.gz
CMake-6706f84cd997d39026080e47e4944072add7f925.tar.bz2
ENH: Refactor find_* command framework/appbundle search order impl.
- CMAKE_FIND_FRAMEWORK and CMAKE_FIND_APPBUNDLE are supposed to specify whether to find frameworks/appbundles FIRST, LAST, ONLY, or NEVER. - Previously this affected only the placement of CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH with respect to the other path specifiers. - Now it behaves as documented. The entire search path is inspected for each kind of program, library, or header before trying the next kind. - Additionally the ONLY mode is now honored for headers so that users do not end up with a library in framework and a header from elsewhere.
Diffstat (limited to 'Source/cmFindPathCommand.cxx')
-rw-r--r--Source/cmFindPathCommand.cxx131
1 files changed, 79 insertions, 52 deletions
diff --git a/Source/cmFindPathCommand.cxx b/Source/cmFindPathCommand.cxx
index e22b122..5e618c6 100644
--- a/Source/cmFindPathCommand.cxx
+++ b/Source/cmFindPathCommand.cxx
@@ -95,57 +95,16 @@ bool cmFindPathCommand
}
return true;
}
- std::string ff = this->Makefile->GetSafeDefinition("CMAKE_FIND_FRAMEWORK");
- bool supportFrameworks = true;
- if( ff.size() == 0 || ff == "NEVER" )
- {
- supportFrameworks = false;
- }
- std::string framework;
- // Use the search path to find the file.
- unsigned int k;
- std::string result;
- for(k=0; k < this->SearchPaths.size(); k++)
+
+ std::string result = this->FindHeader();
+ if(result.size() != 0)
{
- for(unsigned int j =0; j < this->Names.size(); ++j)
- {
- // if frameworks are supported try to find the header in a framework
- std::string tryPath;
- if(supportFrameworks)
- {
- tryPath = this->FindHeaderInFramework(this->Names[j],
- this->SearchPaths[k]);
- if(tryPath.size())
- {
- result = tryPath;
- }
- }
- if(result.size() == 0)
- {
- tryPath = this->SearchPaths[k];
- tryPath += this->Names[j];
- if(cmSystemTools::FileExists(tryPath.c_str()))
- {
- if(this->IncludeFileInPath)
- {
- result = tryPath;
- }
- else
- {
- result = this->SearchPaths[k];
- }
- }
- }
- if(result.size() != 0)
- {
- this->Makefile->AddCacheDefinition
- (this->VariableName.c_str(), result.c_str(),
- this->VariableDocumentation.c_str(),
- (this->IncludeFileInPath) ?
- cmCacheManager::FILEPATH :cmCacheManager::PATH);
- return true;
- }
- }
+ this->Makefile->AddCacheDefinition
+ (this->VariableName.c_str(), result.c_str(),
+ this->VariableDocumentation.c_str(),
+ (this->IncludeFileInPath) ?
+ cmCacheManager::FILEPATH :cmCacheManager::PATH);
+ return true;
}
this->Makefile->AddCacheDefinition
(this->VariableName.c_str(),
@@ -156,8 +115,28 @@ bool cmFindPathCommand
return true;
}
-std::string cmFindPathCommand::FindHeaderInFramework(std::string& file,
- std::string& dir)
+//----------------------------------------------------------------------------
+std::string cmFindPathCommand::FindHeader()
+{
+ std::string header;
+ if(this->SearchFrameworkFirst || this->SearchFrameworkOnly)
+ {
+ header = this->FindFrameworkHeader();
+ }
+ if(header.empty() && !this->SearchFrameworkOnly)
+ {
+ header = this->FindNormalHeader();
+ }
+ if(header.empty() && this->SearchFrameworkLast)
+ {
+ header = this->FindFrameworkHeader();
+ }
+ return header;
+}
+
+std::string
+cmFindPathCommand::FindHeaderInFramework(std::string const& file,
+ std::string const& dir)
{
cmStdString fileName = file;
cmStdString frameWorkName;
@@ -217,3 +196,51 @@ std::string cmFindPathCommand::FindHeaderInFramework(std::string& file,
return "";
}
+//----------------------------------------------------------------------------
+std::string cmFindPathCommand::FindNormalHeader()
+{
+ std::string tryPath;
+ for(std::vector<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end() ; ++ni)
+ {
+ for(std::vector<std::string>::const_iterator
+ p = this->SearchPaths.begin();
+ p != this->SearchPaths.end(); ++p)
+ {
+ tryPath = *p;
+ tryPath += *ni;
+ if(cmSystemTools::FileExists(tryPath.c_str()))
+ {
+ if(this->IncludeFileInPath)
+ {
+ return tryPath;
+ }
+ else
+ {
+ return *p;
+ }
+ }
+ }
+ }
+ return "";
+}
+
+//----------------------------------------------------------------------------
+std::string cmFindPathCommand::FindFrameworkHeader()
+{
+ for(std::vector<std::string>::const_iterator ni = this->Names.begin();
+ ni != this->Names.end() ; ++ni)
+ {
+ for(std::vector<std::string>::const_iterator
+ p = this->SearchPaths.begin();
+ p != this->SearchPaths.end(); ++p)
+ {
+ std::string fwPath = this->FindHeaderInFramework(*ni, *p);
+ if(!fwPath.empty())
+ {
+ return fwPath;
+ }
+ }
+ }
+ return "";
+}