cmCommonTargetGenerator: Adopt GetFrameworkFlags

Move the member up from cmMakefileTargetGenerator.
This commit is contained in:
Brad King 2015-07-08 16:38:49 -04:00
parent ab8240189d
commit 058074d499
4 changed files with 65 additions and 64 deletions

View File

@ -11,6 +11,7 @@
============================================================================*/ ============================================================================*/
#include "cmCommonTargetGenerator.h" #include "cmCommonTargetGenerator.h"
#include "cmComputeLinkInformation.h"
#include "cmGeneratorTarget.h" #include "cmGeneratorTarget.h"
#include "cmGlobalCommonGenerator.h" #include "cmGlobalCommonGenerator.h"
#include "cmLocalCommonGenerator.h" #include "cmLocalCommonGenerator.h"
@ -222,3 +223,64 @@ cmCommonTargetGenerator
flags, this->Makefile->GetDefinition(var)); flags, this->Makefile->GetDefinition(var));
} }
} }
//----------------------------------------------------------------------------
std::string cmCommonTargetGenerator::GetFrameworkFlags(std::string const& l)
{
if(!this->Makefile->IsOn("APPLE"))
{
return std::string();
}
std::string fwSearchFlagVar = "CMAKE_" + l + "_FRAMEWORK_SEARCH_FLAG";
const char* fwSearchFlag =
this->Makefile->GetDefinition(fwSearchFlagVar);
if(!(fwSearchFlag && *fwSearchFlag))
{
return std::string();
}
std::set<std::string> emitted;
#ifdef __APPLE__ /* don't insert this when crosscompiling e.g. to iphone */
emitted.insert("/System/Library/Frameworks");
#endif
std::vector<std::string> includes;
const std::string& config =
this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
this->LocalGenerator->GetIncludeDirectories(includes,
this->GeneratorTarget,
"C", config);
// check all include directories for frameworks as this
// will already have added a -F for the framework
for(std::vector<std::string>::iterator i = includes.begin();
i != includes.end(); ++i)
{
if(this->Target->NameResolvesToFramework(*i))
{
std::string frameworkDir = *i;
frameworkDir += "/../";
frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
emitted.insert(frameworkDir);
}
}
std::string flags;
const char* cfg = this->LocalGenerator->GetConfigName().c_str();
if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(cfg))
{
std::vector<std::string> const& frameworks = cli->GetFrameworkPaths();
for(std::vector<std::string>::const_iterator i = frameworks.begin();
i != frameworks.end(); ++i)
{
if(emitted.insert(*i).second)
{
flags += fwSearchFlag;
flags += this->LocalGenerator
->ConvertToOutputFormat(*i, cmLocalGenerator::SHELL);
flags += " ";
}
}
}
return flags;
}

View File

@ -71,6 +71,9 @@ protected:
void AppendFortranFormatFlags(std::string& flags, void AppendFortranFormatFlags(std::string& flags,
cmSourceFile const& source); cmSourceFile const& source);
// Return the a string with -F flags on apple
std::string GetFrameworkFlags(std::string const& l);
}; };
#endif #endif

View File

@ -1524,67 +1524,6 @@ void cmMakefileTargetGenerator::WriteTargetDriverRule(
depends, no_commands, true); depends, no_commands, true);
} }
//----------------------------------------------------------------------------
std::string cmMakefileTargetGenerator::GetFrameworkFlags(std::string const& l)
{
if(!this->Makefile->IsOn("APPLE"))
{
return std::string();
}
std::string fwSearchFlagVar = "CMAKE_" + l + "_FRAMEWORK_SEARCH_FLAG";
const char* fwSearchFlag =
this->Makefile->GetDefinition(fwSearchFlagVar);
if(!(fwSearchFlag && *fwSearchFlag))
{
return std::string();
}
std::set<std::string> emitted;
#ifdef __APPLE__ /* don't insert this when crosscompiling e.g. to iphone */
emitted.insert("/System/Library/Frameworks");
#endif
std::vector<std::string> includes;
const std::string& config =
this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
this->LocalGenerator->GetIncludeDirectories(includes,
this->GeneratorTarget,
"C", config);
// check all include directories for frameworks as this
// will already have added a -F for the framework
for(std::vector<std::string>::iterator i = includes.begin();
i != includes.end(); ++i)
{
if(this->Target->NameResolvesToFramework(*i))
{
std::string frameworkDir = *i;
frameworkDir += "/../";
frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
emitted.insert(frameworkDir);
}
}
std::string flags;
const char* cfg = this->LocalGenerator->GetConfigName().c_str();
if(cmComputeLinkInformation* cli = this->Target->GetLinkInformation(cfg))
{
std::vector<std::string> const& frameworks = cli->GetFrameworkPaths();
for(std::vector<std::string>::const_iterator i = frameworks.begin();
i != frameworks.end(); ++i)
{
if(emitted.insert(*i).second)
{
flags += fwSearchFlag;
flags += this->LocalGenerator
->ConvertToOutputFormat(*i, cmLocalGenerator::SHELL);
flags += " ";
}
}
}
return flags;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmMakefileTargetGenerator void cmMakefileTargetGenerator
::AppendTargetDepends(std::vector<std::string>& depends) ::AppendTargetDepends(std::vector<std::string>& depends)

View File

@ -126,9 +126,6 @@ protected:
void DriveCustomCommands(std::vector<std::string>& depends); void DriveCustomCommands(std::vector<std::string>& depends);
// Return the a string with -F flags on apple
std::string GetFrameworkFlags(std::string const& l);
// append intertarget dependencies // append intertarget dependencies
void AppendTargetDepends(std::vector<std::string>& depends); void AppendTargetDepends(std::vector<std::string>& depends);