From 82bb6fae0d127b2ffcaae5eaa8a5365093cfac5c Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Tue, 27 Dec 2005 14:56:56 -0500 Subject: ENH: add framework support to FIND_FILE --- Source/cmFindFileCommand.cxx | 75 +++++++++++++++++++++++++++++++++++++++ Source/cmFindFileCommand.h | 2 +- Source/cmGlobalXCodeGenerator.cxx | 40 +++++++++++++++++++-- Source/cmLocalGenerator.cxx | 14 ++++++++ 4 files changed, 127 insertions(+), 4 deletions(-) diff --git a/Source/cmFindFileCommand.cxx b/Source/cmFindFileCommand.cxx index d4f7221..82c0ff4 100644 --- a/Source/cmFindFileCommand.cxx +++ b/Source/cmFindFileCommand.cxx @@ -16,6 +16,7 @@ =========================================================================*/ #include "cmFindFileCommand.h" #include "cmCacheManager.h" +#include "cmGlob.h" #include @@ -86,6 +87,17 @@ bool cmFindFileCommand::InitialPass(std::vector 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 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 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::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 files = globIt.GetFiles(); + if(files.size()) + { + cmStdString fheader = cmSystemTools::CollapseFullPath(files[0].c_str()); + fheader = cmSystemTools::GetFilenamePath(fheader); + return fheader; + } + } + return cmStdString(""); +#endif +} diff --git a/Source/cmFindFileCommand.h b/Source/cmFindFileCommand.h index 12d1f75..1e44be5 100644 --- a/Source/cmFindFileCommand.h +++ b/Source/cmFindFileCommand.h @@ -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); }; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 43c47f8..fc37952 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1173,11 +1173,45 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, std::vector& includes = m_CurrentMakefile->GetIncludeDirectories(); std::vector::iterator i = includes.begin(); + std::string fdirs; + std::set emitted; for(;i != includes.end(); ++i) { - std::string incpath = - this->XCodeEscapePath(i->c_str()); - dirs += incpath + " "; + 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& frameworks = target.GetFrameworks(); + if(frameworks.size()) + { + for(std::vector::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()) { diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index b0066b0..214ab6b 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1055,8 +1055,22 @@ const char* cmLocalGenerator::GetIncludeFlags(const char* lang) repeatFlag = false; } bool flagUsed = false; + std::set 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) { -- cgit v0.12