ENH: add framework support to FIND_FILE

This commit is contained in:
Bill Hoffman 2005-12-27 14:56:56 -05:00
parent c04cbcac70
commit 82bb6fae0d
4 changed files with 127 additions and 4 deletions

View File

@ -16,6 +16,7 @@
=========================================================================*/
#include "cmFindFileCommand.h"
#include "cmCacheManager.h"
#include "cmGlob.h"
#include <stdlib.h>
@ -86,6 +87,17 @@ bool cmFindFileCommand::InitialPass(std::vector<std::string> const& argsIn)
return true;
}
}
#if defined (__APPLE__)
cmStdString fpath = this->FindHeaderInFrameworks(args[0].c_str(), args[1].c_str());
if(fpath.size())
{
m_Makefile->AddCacheDefinition(args[0].c_str(),
fpath.c_str(),
helpString.c_str(),
cmCacheManager::FILEPATH);
return true;
}
#endif
std::string s = args[0] + "-NOTFOUND";
m_Makefile->AddCacheDefinition(args[0].c_str(),
s.c_str(),
@ -94,3 +106,66 @@ bool cmFindFileCommand::InitialPass(std::vector<std::string> const& argsIn)
return true;
}
cmStdString cmFindFileCommand::FindHeaderInFrameworks(const char* defineVar,
const char* file)
{
#ifndef __APPLE__
return cmStdString("");
#else
cmStdString fileName = file;
cmStdString frameWorkName;
cmStdString::size_type pos = fileName.find("/");
std::cerr << "ff " << fileName << " " << pos << "\n";
if(pos != fileName.npos)
{
// remove the name from the slash;
fileName = fileName.substr(pos+1);
frameWorkName = file;
frameWorkName = frameWorkName.substr(0, frameWorkName.size()-fileName.size()-1);
// if the framework has a path in it then just use the filename
std::cerr << fileName << " " << frameWorkName << "\n";
if(frameWorkName.find("/") != frameWorkName.npos)
{
fileName = file;
frameWorkName = "";
}
}
std::vector<cmStdString> path;
path.push_back("~/Library/Frameworks");
path.push_back("/Library/Frameworks");
path.push_back("/System/Library/Frameworks");
path.push_back("/Network/Library/Frameworks");
for( std::vector<cmStdString>::iterator i = path.begin();
i != path.end(); ++i)
{
if(frameWorkName.size())
{
std::string fpath = *i;
fpath += "/";
fpath += frameWorkName;
fpath += ".framework";
std::string path = fpath;
path += "/Headers/";
path += fileName;
std::cerr << "try " << path << "\n";
if(cmSystemTools::FileExists(path.c_str()))
{
return fpath;
}
}
cmStdString glob = *i;
glob += "/*/Headers/";
glob += file;
cmGlob globIt;
globIt.FindFiles(glob);
std::vector<std::string> files = globIt.GetFiles();
if(files.size())
{
cmStdString fheader = cmSystemTools::CollapseFullPath(files[0].c_str());
fheader = cmSystemTools::GetFilenamePath(fheader);
return fheader;
}
}
return cmStdString("");
#endif
}

View File

@ -79,7 +79,7 @@ public:
"different extensions on different platforms, FIND_PROGRAM "
"should be used instead of FIND_FILE when looking for them.";
}
cmStdString FindHeaderInFrameworks(const char* var, const char* file);
cmTypeMacro(cmFindFileCommand, cmCommand);
};

View File

@ -1173,12 +1173,46 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
std::vector<std::string>& includes =
m_CurrentMakefile->GetIncludeDirectories();
std::vector<std::string>::iterator i = includes.begin();
std::string fdirs;
std::set<cmStdString> emitted;
for(;i != includes.end(); ++i)
{
if(cmSystemTools::IsPathToFramework(i->c_str()))
{
std::string frameworkDir = *i;
frameworkDir += "/../";
frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
if(emitted.insert(frameworkDir).second)
{
fdirs += this->XCodeEscapePath(frameworkDir.c_str());
fdirs += " ";
}
}
else
{
std::string incpath =
this->XCodeEscapePath(i->c_str());
dirs += incpath + " ";
}
}
std::vector<std::string>& frameworks = target.GetFrameworks();
if(frameworks.size())
{
for(std::vector<std::string>::iterator i = frameworks.begin();
i != frameworks.end(); ++i)
{
if(emitted.insert(*i).second)
{
fdirs += this->XCodeEscapePath(i->c_str());
fdirs += " ";
}
}
}
if(fdirs.size())
{
buildSettings->AddAttribute("FRAMEWORK_SEARCH_PATHS",
this->CreateString(fdirs.c_str()));
}
if(dirs.size())
{
buildSettings->AddAttribute("HEADER_SEARCH_PATHS",

View File

@ -1055,8 +1055,22 @@ const char* cmLocalGenerator::GetIncludeFlags(const char* lang)
repeatFlag = false;
}
bool flagUsed = false;
std::set<cmStdString> emitted;
for(i = includes.begin(); i != includes.end(); ++i)
{
#ifdef __APPLE__
if(cmSystemTools::IsPathToFramework(i->c_str()))
{
std::string frameworkDir = *i;
frameworkDir += "/../";
frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir.c_str());
if(emitted.insert(frameworkDir).second)
{
includeFlags << "-F" << this->ConvertToOutputForExisting(frameworkDir.c_str()) << " ";
}
continue;
}
#endif
std::string include = *i;
if(!flagUsed || repeatFlag)
{