cmGeneratorTarget: Move compile options processing from cmTarget.

This commit is contained in:
Stephen Kelly 2015-08-04 23:43:56 +02:00
parent e6ccbf6f30
commit db4cb92bda
6 changed files with 154 additions and 88 deletions

View File

@ -261,7 +261,8 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
: Target(t),
SourceFileFlagsConstructed(false),
PolicyWarnedCMP0022(false),
DebugIncludesDone(false)
DebugIncludesDone(false),
DebugCompileOptionsDone(false)
{
this->Makefile = this->Target->GetMakefile();
this->LocalGenerator = lg;
@ -271,11 +272,17 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
t->GetIncludeDirectoriesEntries(),
t->GetIncludeDirectoriesBacktraces(),
this->IncludeDirectoriesEntries);
CreatePropertyGeneratorExpressions(
t->GetCompileOptionsEntries(),
t->GetCompileOptionsBacktraces(),
this->CompileOptionsEntries);
}
cmGeneratorTarget::~cmGeneratorTarget()
{
cmDeleteAll(this->IncludeDirectoriesEntries);
cmDeleteAll(this->CompileOptionsEntries);
cmDeleteAll(this->LinkInformation);
this->LinkInformation.clear();
}
@ -2244,6 +2251,125 @@ cmGeneratorTarget::GetIncludeDirectories(const std::string& config,
return includes;
}
//----------------------------------------------------------------------------
static void processCompileOptionsInternal(cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
std::vector<std::string> &options,
UNORDERED_SET<std::string> &uniqueOptions,
cmGeneratorExpressionDAGChecker *dagChecker,
const std::string& config, bool debugOptions, const char *logName,
std::string const& language)
{
cmMakefile *mf = tgt->Target->GetMakefile();
for (std::vector<cmGeneratorTarget::TargetPropertyEntry*>::const_iterator
it = entries.begin(), end = entries.end(); it != end; ++it)
{
std::vector<std::string> entryOptions;
cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
config,
false,
tgt->Target,
dagChecker,
language),
entryOptions);
std::string usedOptions;
for(std::vector<std::string>::iterator
li = entryOptions.begin(); li != entryOptions.end(); ++li)
{
std::string const& opt = *li;
if(uniqueOptions.insert(opt).second)
{
options.push_back(opt);
if (debugOptions)
{
usedOptions += " * " + opt + "\n";
}
}
}
if (!usedOptions.empty())
{
mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
std::string("Used compile ") + logName
+ std::string(" for target ")
+ tgt->GetName() + ":\n"
+ usedOptions, (*it)->ge->GetBacktrace());
}
}
}
//----------------------------------------------------------------------------
static void processCompileOptions(cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
std::vector<std::string> &options,
UNORDERED_SET<std::string> &uniqueOptions,
cmGeneratorExpressionDAGChecker *dagChecker,
const std::string& config, bool debugOptions,
std::string const& language)
{
processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
dagChecker, config, debugOptions, "options",
language);
}
//----------------------------------------------------------------------------
void cmGeneratorTarget::GetCompileOptions(std::vector<std::string> &result,
const std::string& config,
const std::string& language) const
{
UNORDERED_SET<std::string> uniqueOptions;
cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
"COMPILE_OPTIONS", 0, 0);
std::vector<std::string> debugProperties;
const char *debugProp =
this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
if (debugProp)
{
cmSystemTools::ExpandListArgument(debugProp, debugProperties);
}
bool debugOptions = !this->DebugCompileOptionsDone
&& std::find(debugProperties.begin(),
debugProperties.end(),
"COMPILE_OPTIONS")
!= debugProperties.end();
if (this->Makefile->IsConfigured())
{
this->DebugCompileOptionsDone = true;
}
processCompileOptions(this,
this->CompileOptionsEntries,
result,
uniqueOptions,
&dagChecker,
config,
debugOptions,
language);
std::vector<cmGeneratorTarget::TargetPropertyEntry*>
linkInterfaceCompileOptionsEntries;
AddInterfaceEntries(
this, config, "INTERFACE_COMPILE_OPTIONS",
linkInterfaceCompileOptionsEntries);
processCompileOptions(this,
linkInterfaceCompileOptionsEntries,
result,
uniqueOptions,
&dagChecker,
config,
debugOptions,
language);
cmDeleteAll(linkInterfaceCompileOptionsEntries);
}
//----------------------------------------------------------------------------
void cmGeneratorTarget::GenerateTargetManifest(
const std::string& config) const

View File

@ -217,6 +217,10 @@ public:
std::vector<std::string> GetIncludeDirectories(
const std::string& config, const std::string& lang) const;
void GetCompileOptions(std::vector<std::string> &result,
const std::string& config,
const std::string& language) const;
bool IsSystemIncludeDirectory(const std::string& dir,
const std::string& config) const;
@ -407,6 +411,7 @@ private:
bool usage_requirements_only) const;
std::vector<TargetPropertyEntry*> IncludeDirectoriesEntries;
std::vector<TargetPropertyEntry*> CompileOptionsEntries;
void ExpandLinkItems(std::string const& prop, std::string const& value,
std::string const& config, cmTarget const* headTarget,
@ -421,6 +426,7 @@ private:
mutable OutputNameMapType OutputNameMap;
mutable bool PolicyWarnedCMP0022;
mutable bool DebugIncludesDone;
mutable bool DebugCompileOptionsDone;
public:
std::vector<cmTarget const*> const&

View File

@ -558,7 +558,7 @@ bool cmGhsMultiTargetGenerator::IsNotKernel(std::string const &config,
{
bool output;
std::vector<std::string> options;
this->Target->GetCompileOptions(options, config, language);
this->GeneratorTarget->GetCompileOptions(options, config, language);
output =
options.end() == std::find(options.begin(), options.end(), "-kernel");
return output;
@ -587,7 +587,7 @@ bool cmGhsMultiTargetGenerator::DetermineIfDynamicDownload(
{
std::vector<std::string> options;
bool output = false;
this->Target->GetCompileOptions(options, config, language);
this->GeneratorTarget->GetCompileOptions(options, config, language);
for (std::vector<std::string>::const_iterator options_i = options.begin();
options_i != options.end(); ++options_i)
{

View File

@ -1094,6 +1094,10 @@ void cmLocalGenerator::AddCompileOptions(
)
{
std::string langFlagRegexVar = std::string("CMAKE_")+lang+"_FLAG_REGEX";
cmGeneratorTarget* gtgt =
this->GlobalGenerator->GetGeneratorTarget(target);
if(const char* langFlagRegexStr =
this->Makefile->GetDefinition(langFlagRegexVar))
{
@ -1104,7 +1108,7 @@ void cmLocalGenerator::AddCompileOptions(
{
cmSystemTools::ParseWindowsCommandLine(targetFlags, opts);
}
target->GetCompileOptions(opts, config, lang);
gtgt->GetCompileOptions(opts, config, lang);
for(std::vector<std::string>::const_iterator i = opts.begin();
i != opts.end(); ++i)
{
@ -1125,7 +1129,7 @@ void cmLocalGenerator::AddCompileOptions(
this->AppendFlags(flags, targetFlags);
}
std::vector<std::string> opts;
target->GetCompileOptions(opts, config, lang);
gtgt->GetCompileOptions(opts, config, lang);
for(std::vector<std::string>::const_iterator i = opts.begin();
i != opts.end(); ++i)
{

View File

@ -141,7 +141,6 @@ public:
std::vector<cmListFileBacktrace> IncludeDirectoriesBacktraces;
std::vector<std::string> CompileOptionsEntries;
std::vector<cmListFileBacktrace> CompileOptionsBacktraces;
std::vector<TargetPropertyEntry*> CompileOptionsItems;
std::vector<std::string> CompileFeaturesEntries;
std::vector<cmListFileBacktrace> CompileFeaturesBacktraces;
std::vector<TargetPropertyEntry*> CompileFeaturesItems;
@ -176,7 +175,6 @@ cmTarget::cmTarget()
this->IsApple = false;
this->IsImportedTarget = false;
this->BuildInterfaceIncludesAppended = false;
this->DebugCompileOptionsDone = false;
this->DebugCompileFeaturesDone = false;
this->DebugCompileDefinitionsDone = false;
this->DebugSourcesDone = false;
@ -423,11 +421,6 @@ void CreatePropertyGeneratorExpressions(
void cmTarget::Compute()
{
CreatePropertyGeneratorExpressions(
this->Internal->CompileOptionsEntries,
this->Internal->CompileOptionsBacktraces,
this->Internal->CompileOptionsItems);
CreatePropertyGeneratorExpressions(
this->Internal->CompileFeaturesEntries,
this->Internal->CompileFeaturesBacktraces,
@ -1322,6 +1315,16 @@ cmBacktraceRange cmTarget::GetIncludeDirectoriesBacktraces() const
return cmMakeRange(this->Internal->IncludeDirectoriesBacktraces);
}
cmStringRange cmTarget::GetCompileOptionsEntries() const
{
return cmMakeRange(this->Internal->CompileOptionsEntries);
}
cmBacktraceRange cmTarget::GetCompileOptionsBacktraces() const
{
return cmMakeRange(this->Internal->CompileOptionsBacktraces);
}
#if defined(_WIN32) && !defined(__CYGWIN__)
//----------------------------------------------------------------------------
void
@ -1966,77 +1969,6 @@ static void processCompileOptionsInternal(cmTarget const* tgt,
}
}
//----------------------------------------------------------------------------
static void processCompileOptions(cmTarget const* tgt,
const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
std::vector<std::string> &options,
UNORDERED_SET<std::string> &uniqueOptions,
cmGeneratorExpressionDAGChecker *dagChecker,
const std::string& config, bool debugOptions,
std::string const& language)
{
processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
dagChecker, config, debugOptions, "options",
language);
}
//----------------------------------------------------------------------------
void cmTarget::GetCompileOptions(std::vector<std::string> &result,
const std::string& config,
const std::string& language) const
{
UNORDERED_SET<std::string> uniqueOptions;
cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
"COMPILE_OPTIONS", 0, 0);
std::vector<std::string> debugProperties;
const char *debugProp =
this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
if (debugProp)
{
cmSystemTools::ExpandListArgument(debugProp, debugProperties);
}
bool debugOptions = !this->DebugCompileOptionsDone
&& std::find(debugProperties.begin(),
debugProperties.end(),
"COMPILE_OPTIONS")
!= debugProperties.end();
if (this->Makefile->IsConfigured())
{
this->DebugCompileOptionsDone = true;
}
processCompileOptions(this,
this->Internal->CompileOptionsItems,
result,
uniqueOptions,
&dagChecker,
config,
debugOptions,
language);
std::vector<cmTargetInternals::TargetPropertyEntry*>
linkInterfaceCompileOptionsEntries;
this->Internal->AddInterfaceEntries(
this, config, "INTERFACE_COMPILE_OPTIONS",
linkInterfaceCompileOptionsEntries);
processCompileOptions(this,
linkInterfaceCompileOptionsEntries,
result,
uniqueOptions,
&dagChecker,
config,
debugOptions,
language);
cmDeleteAll(linkInterfaceCompileOptionsEntries);
}
//----------------------------------------------------------------------------
static void processCompileDefinitions(cmTarget const* tgt,
const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
@ -4166,7 +4098,6 @@ cmTargetInternalPointer
//----------------------------------------------------------------------------
cmTargetInternalPointer::~cmTargetInternalPointer()
{
cmDeleteAll(this->Pointer->CompileOptionsItems);
cmDeleteAll(this->Pointer->CompileFeaturesItems);
cmDeleteAll(this->Pointer->CompileDefinitionsItems);
cmDeleteAll(this->Pointer->SourceEntries);

View File

@ -375,9 +375,6 @@ public:
void AppendBuildInterfaceIncludes();
void GetCompileOptions(std::vector<std::string> &result,
const std::string& config,
const std::string& language) const;
void GetCompileFeatures(std::vector<std::string> &features,
const std::string& config) const;
@ -402,6 +399,9 @@ public:
cmStringRange GetIncludeDirectoriesEntries() const;
cmBacktraceRange GetIncludeDirectoriesBacktraces() const;
cmStringRange GetCompileOptionsEntries() const;
cmBacktraceRange GetCompileOptionsBacktraces() const;
#if defined(_WIN32) && !defined(__CYGWIN__)
const LinkLibraryVectorType &GetLinkLibrariesForVS6() const {
return this->LinkLibrariesForVS6;}
@ -516,7 +516,6 @@ private:
bool IsApple;
bool IsImportedTarget;
bool BuildInterfaceIncludesAppended;
mutable bool DebugCompileOptionsDone;
mutable bool DebugCompileDefinitionsDone;
mutable bool DebugSourcesDone;
mutable bool DebugCompileFeaturesDone;