OS X: Encode -F framework search flag in per-language platform variable

Compilers for languages other than C and C++ on OS X may not understand
the -F framework search flag.  Create a new platform information
variable CMAKE_<LANG>_FRAMEWORK_SEARCH_FLAG to hold the flag, and set it
for C and CXX lanugages in the Platform/Darwin module.

Reported-by: Vittorio Giovara <vittorio.giovara@gmail.com>
This commit is contained in:
Brad King 2013-10-10 08:29:04 -04:00
parent 872db622d6
commit 2e13c36211
5 changed files with 42 additions and 13 deletions

View File

@ -268,6 +268,11 @@ set(CMAKE_C_CREATE_MACOSX_FRAMEWORK
set(CMAKE_CXX_CREATE_MACOSX_FRAMEWORK set(CMAKE_CXX_CREATE_MACOSX_FRAMEWORK
"<CMAKE_CXX_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <LINK_FLAGS> -o <TARGET> <SONAME_FLAG> <TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>") "<CMAKE_CXX_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <LINK_FLAGS> -o <TARGET> <SONAME_FLAG> <TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
# Set default framework search path flag for languages known to use a
# preprocessor that may find headers in frameworks.
set(CMAKE_C_FRAMEWORK_SEARCH_FLAG -F)
set(CMAKE_CXX_FRAMEWORK_SEARCH_FLAG -F)
set(CMAKE_Fortran_FRAMEWORK_SEARCH_FLAG -F)
# default to searching for frameworks first # default to searching for frameworks first
if(NOT DEFINED CMAKE_FIND_FRAMEWORK) if(NOT DEFINED CMAKE_FIND_FRAMEWORK)

View File

@ -1977,6 +1977,8 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
cmProperty::VARIABLE,0,0); cmProperty::VARIABLE,0,0);
cm->DefineProperty("CMAKE_<LANG>_FLAGS_RELWITHDEBINFO_INIT", cm->DefineProperty("CMAKE_<LANG>_FLAGS_RELWITHDEBINFO_INIT",
cmProperty::VARIABLE,0,0); cmProperty::VARIABLE,0,0);
cm->DefineProperty("CMAKE_<LANG>_FRAMEWORK_SEARCH_FLAG",
cmProperty::VARIABLE,0,0);
cm->DefineProperty("CMAKE_<LANG>_INFORMATION_LOADED", cm->DefineProperty("CMAKE_<LANG>_INFORMATION_LOADED",
cmProperty::VARIABLE,0,0); cmProperty::VARIABLE,0,0);
cm->DefineProperty("CMAKE_<LANG>_LINK_FLAGS", cm->DefineProperty("CMAKE_<LANG>_LINK_FLAGS",

View File

@ -1253,6 +1253,12 @@ std::string cmLocalGenerator::GetIncludeFlags(
sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar.c_str()); sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar.c_str());
} }
std::string fwSearchFlagVar = "CMAKE_";
fwSearchFlagVar += lang;
fwSearchFlagVar += "_FRAMEWORK_SEARCH_FLAG";
const char* fwSearchFlag =
this->Makefile->GetDefinition(fwSearchFlagVar.c_str());
bool flagUsed = false; bool flagUsed = false;
std::set<cmStdString> emitted; std::set<cmStdString> emitted;
#ifdef __APPLE__ #ifdef __APPLE__
@ -1261,7 +1267,7 @@ std::string cmLocalGenerator::GetIncludeFlags(
std::vector<std::string>::const_iterator i; std::vector<std::string>::const_iterator i;
for(i = includes.begin(); i != includes.end(); ++i) for(i = includes.begin(); i != includes.end(); ++i)
{ {
if(this->Makefile->IsOn("APPLE") if(fwSearchFlag && *fwSearchFlag && this->Makefile->IsOn("APPLE")
&& cmSystemTools::IsPathToFramework(i->c_str())) && cmSystemTools::IsPathToFramework(i->c_str()))
{ {
std::string frameworkDir = *i; std::string frameworkDir = *i;
@ -1271,7 +1277,7 @@ std::string cmLocalGenerator::GetIncludeFlags(
{ {
OutputFormat format = forResponseFile? RESPONSE : SHELL; OutputFormat format = forResponseFile? RESPONSE : SHELL;
includeFlags includeFlags
<< "-F" << this->Convert(frameworkDir.c_str(), << fwSearchFlag << this->Convert(frameworkDir.c_str(),
START_OUTPUT, format, true) START_OUTPUT, format, true)
<< " "; << " ";
} }
@ -1770,14 +1776,22 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
} }
// Append the framework search path flags. // Append the framework search path flags.
std::string fwSearchFlagVar = "CMAKE_";
fwSearchFlagVar += linkLanguage;
fwSearchFlagVar += "_FRAMEWORK_SEARCH_FLAG";
const char* fwSearchFlag =
this->Makefile->GetDefinition(fwSearchFlagVar.c_str());
if(fwSearchFlag && *fwSearchFlag)
{
std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths(); std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths();
for(std::vector<std::string>::const_iterator fdi = fwDirs.begin(); for(std::vector<std::string>::const_iterator fdi = fwDirs.begin();
fdi != fwDirs.end(); ++fdi) fdi != fwDirs.end(); ++fdi)
{ {
frameworkPath += "-F"; frameworkPath += fwSearchFlag;
frameworkPath += this->Convert(fdi->c_str(), NONE, SHELL, false); frameworkPath += this->Convert(fdi->c_str(), NONE, SHELL, false);
frameworkPath += " "; frameworkPath += " ";
} }
}
// Append the library search path flags. // Append the library search path flags.
std::vector<std::string> const& libDirs = cli.GetDirectories(); std::vector<std::string> const& libDirs = cli.GetDirectories();

View File

@ -291,7 +291,7 @@ std::string cmMakefileTargetGenerator::GetFlags(const std::string &l)
// Add include directory flags. // Add include directory flags.
this->LocalGenerator-> this->LocalGenerator->
AppendFlags(flags,this->GetFrameworkFlags().c_str()); AppendFlags(flags,this->GetFrameworkFlags(l).c_str());
// Add target-specific flags. // Add target-specific flags.
this->LocalGenerator->AddCompileOptions(flags, this->Target, this->LocalGenerator->AddCompileOptions(flags, this->Target,
@ -1518,13 +1518,21 @@ void cmMakefileTargetGenerator::WriteTargetDriverRule(const char* main_output,
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string cmMakefileTargetGenerator::GetFrameworkFlags() std::string cmMakefileTargetGenerator::GetFrameworkFlags(std::string const& l)
{ {
if(!this->Makefile->IsOn("APPLE")) if(!this->Makefile->IsOn("APPLE"))
{ {
return std::string(); return std::string();
} }
std::string fwSearchFlagVar = "CMAKE_" + l + "_FRAMEWORK_SEARCH_FLAG";
const char* fwSearchFlag =
this->Makefile->GetDefinition(fwSearchFlagVar.c_str());
if(!(fwSearchFlag && *fwSearchFlag))
{
return std::string();
}
std::set<cmStdString> emitted; std::set<cmStdString> emitted;
#ifdef __APPLE__ /* don't insert this when crosscompiling e.g. to iphone */ #ifdef __APPLE__ /* don't insert this when crosscompiling e.g. to iphone */
emitted.insert("/System/Library/Frameworks"); emitted.insert("/System/Library/Frameworks");
@ -1559,7 +1567,7 @@ std::string cmMakefileTargetGenerator::GetFrameworkFlags()
{ {
if(emitted.insert(*i).second) if(emitted.insert(*i).second)
{ {
flags += "-F"; flags += fwSearchFlag;
flags += this->Convert(i->c_str(), flags += this->Convert(i->c_str(),
cmLocalGenerator::START_OUTPUT, cmLocalGenerator::START_OUTPUT,
cmLocalGenerator::SHELL, true); cmLocalGenerator::SHELL, true);

View File

@ -124,7 +124,7 @@ protected:
void DriveCustomCommands(std::vector<std::string>& depends); void DriveCustomCommands(std::vector<std::string>& depends);
// Return the a string with -F flags on apple // Return the a string with -F flags on apple
std::string GetFrameworkFlags(); std::string GetFrameworkFlags(std::string const& l);
void AppendFortranFormatFlags(std::string& flags, cmSourceFile& source); void AppendFortranFormatFlags(std::string& flags, cmSourceFile& source);