summaryrefslogtreecommitdiffstats
path: root/Source/cmGeneratorTarget.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmGeneratorTarget.cxx')
-rw-r--r--Source/cmGeneratorTarget.cxx482
1 files changed, 348 insertions, 134 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index 175bb0e..a7b2fb6 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -25,7 +25,196 @@
#include "assert.h"
//----------------------------------------------------------------------------
-cmGeneratorTarget::cmGeneratorTarget(cmTarget* t): Target(t)
+void reportBadObjLib(std::vector<cmSourceFile*> const& badObjLib,
+ cmTarget *target, cmake *cm)
+{
+ if(!badObjLib.empty())
+ {
+ cmOStringStream e;
+ e << "OBJECT library \"" << target->GetName() << "\" contains:\n";
+ for(std::vector<cmSourceFile*>::const_iterator i = badObjLib.begin();
+ i != badObjLib.end(); ++i)
+ {
+ e << " " << (*i)->GetLocation().GetName() << "\n";
+ }
+ e << "but may contain only headers and sources that compile.";
+ cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ target->GetBacktrace());
+ }
+}
+
+struct ObjectSourcesTag {};
+struct CustomCommandsTag {};
+struct ExtraSourcesTag {};
+struct HeaderSourcesTag {};
+struct ExternalObjectsTag {};
+struct IDLSourcesTag {};
+struct ResxTag {};
+struct ModuleDefinitionFileTag {};
+
+#if !defined(_MSC_VER) || _MSC_VER >= 1310
+template<typename Tag, typename OtherTag>
+struct IsSameTag
+{
+ enum {
+ Result = false
+ };
+};
+
+template<typename Tag>
+struct IsSameTag<Tag, Tag>
+{
+ enum {
+ Result = true
+ };
+};
+#else
+struct IsSameTagBase
+{
+ typedef char (&no_type)[1];
+ typedef char (&yes_type)[2];
+ template<typename T> struct Check;
+ template<typename T> static yes_type check(Check<T>*, Check<T>*);
+ static no_type check(...);
+};
+template<typename Tag1, typename Tag2>
+struct IsSameTag: public IsSameTagBase
+{
+ enum {
+ Result = (sizeof(check(static_cast< Check<Tag1>* >(0),
+ static_cast< Check<Tag2>* >(0))) ==
+ sizeof(yes_type))
+ };
+};
+#endif
+
+template<bool>
+struct DoAccept
+{
+ template <typename T> static void Do(T&, cmSourceFile*) {}
+};
+
+template<>
+struct DoAccept<true>
+{
+ static void Do(std::vector<cmSourceFile*>& files, cmSourceFile* f)
+ {
+ files.push_back(f);
+ }
+ static void Do(cmGeneratorTarget::ResxData& data, cmSourceFile* f)
+ {
+ // Build and save the name of the corresponding .h file
+ // This relationship will be used later when building the project files.
+ // Both names would have been auto generated from Visual Studio
+ // where the user supplied the file name and Visual Studio
+ // appended the suffix.
+ std::string resx = f->GetFullPath();
+ std::string hFileName = resx.substr(0, resx.find_last_of(".")) + ".h";
+ data.ExpectedResxHeaders.insert(hFileName);
+ data.ResxSources.push_back(f);
+ }
+ static void Do(std::string& data, cmSourceFile* f)
+ {
+ data = f->GetFullPath();
+ }
+};
+
+//----------------------------------------------------------------------------
+template<typename Tag, typename DataType = std::vector<cmSourceFile*> >
+struct TagVisitor
+{
+ DataType& Data;
+ std::vector<cmSourceFile*> BadObjLibFiles;
+ cmTarget *Target;
+ cmGlobalGenerator *GlobalGenerator;
+ cmsys::RegularExpression Header;
+ bool IsObjLib;
+
+ TagVisitor(cmTarget *target, DataType& data)
+ : Data(data), Target(target),
+ GlobalGenerator(target->GetMakefile()
+ ->GetLocalGenerator()->GetGlobalGenerator()),
+ Header(CM_HEADER_REGEX),
+ IsObjLib(target->GetType() == cmTarget::OBJECT_LIBRARY)
+ {
+ }
+
+ ~TagVisitor()
+ {
+ reportBadObjLib(this->BadObjLibFiles, this->Target,
+ this->GlobalGenerator->GetCMakeInstance());
+ }
+
+ void Accept(cmSourceFile *sf)
+ {
+ std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
+ if(sf->GetCustomCommand())
+ {
+ DoAccept<IsSameTag<Tag, CustomCommandsTag>::Result>::Do(this->Data, sf);
+ }
+ else if(this->Target->GetType() == cmTarget::UTILITY)
+ {
+ DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
+ }
+ else if(sf->GetPropertyAsBool("HEADER_FILE_ONLY"))
+ {
+ DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
+ }
+ else if(sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
+ {
+ DoAccept<IsSameTag<Tag, ExternalObjectsTag>::Result>::Do(this->Data, sf);
+ if(this->IsObjLib)
+ {
+ this->BadObjLibFiles.push_back(sf);
+ }
+ }
+ else if(sf->GetLanguage())
+ {
+ DoAccept<IsSameTag<Tag, ObjectSourcesTag>::Result>::Do(this->Data, sf);
+ }
+ else if(ext == "def")
+ {
+ DoAccept<IsSameTag<Tag, ModuleDefinitionFileTag>::Result>::Do(this->Data,
+ sf);
+ if(this->IsObjLib)
+ {
+ this->BadObjLibFiles.push_back(sf);
+ }
+ }
+ else if(ext == "idl")
+ {
+ DoAccept<IsSameTag<Tag, IDLSourcesTag>::Result>::Do(this->Data, sf);
+ if(this->IsObjLib)
+ {
+ this->BadObjLibFiles.push_back(sf);
+ }
+ }
+ else if(ext == "resx")
+ {
+ DoAccept<IsSameTag<Tag, ResxTag>::Result>::Do(this->Data, sf);
+ }
+ else if(this->Header.find(sf->GetFullPath().c_str()))
+ {
+ DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
+ }
+ else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str()))
+ {
+ DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
+ }
+ else
+ {
+ DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
+ if(this->IsObjLib && ext != "txt")
+ {
+ this->BadObjLibFiles.push_back(sf);
+ }
+ }
+ }
+};
+
+//----------------------------------------------------------------------------
+cmGeneratorTarget::cmGeneratorTarget(cmTarget* t): Target(t),
+ SourceFileFlagsConstructed(false)
{
this->Makefile = this->Target->GetMakefile();
this->LocalGenerator = this->Makefile->GetLocalGenerator();
@@ -62,19 +251,12 @@ cmGeneratorTarget::GetSourceDepends(cmSourceFile* sf) const
return 0;
}
-static void handleSystemIncludesDep(cmMakefile *mf, const std::string &name,
+static void handleSystemIncludesDep(cmMakefile *mf, cmTarget* depTgt,
const char *config, cmTarget *headTarget,
cmGeneratorExpressionDAGChecker *dagChecker,
std::vector<std::string>& result,
bool excludeImported)
{
- cmTarget* depTgt = mf->FindTargetToUse(name);
-
- if (!depTgt)
- {
- return;
- }
-
cmListFileBacktrace lfbt;
if (const char* dirs =
@@ -102,11 +284,34 @@ static void handleSystemIncludesDep(cmMakefile *mf, const std::string &name,
}
}
+#define IMPLEMENT_VISIT_IMPL(DATA, DATATYPE) \
+ { \
+ std::vector<cmSourceFile*> sourceFiles; \
+ this->Target->GetSourceFiles(sourceFiles); \
+ TagVisitor<DATA ## Tag DATATYPE> visitor(this->Target, data); \
+ for(std::vector<cmSourceFile*>::const_iterator si = sourceFiles.begin(); \
+ si != sourceFiles.end(); ++si) \
+ { \
+ visitor.Accept(*si); \
+ } \
+ } \
+
+
+#define IMPLEMENT_VISIT(DATA) \
+ IMPLEMENT_VISIT_IMPL(DATA, EMPTY) \
+
+#define EMPTY
+#define COMMA ,
+
//----------------------------------------------------------------------------
void
-cmGeneratorTarget::GetObjectSources(std::vector<cmSourceFile*> &objs) const
+cmGeneratorTarget::GetObjectSources(std::vector<cmSourceFile*> &data) const
{
- objs = this->ObjectSources;
+ IMPLEMENT_VISIT(ObjectSources);
+ if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY)
+ {
+ this->ObjectSources = data;
+ }
}
//----------------------------------------------------------------------------
@@ -135,49 +340,53 @@ bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
}
//----------------------------------------------------------------------------
-void cmGeneratorTarget::GetResxSources(std::vector<cmSourceFile*>& srcs) const
+void cmGeneratorTarget::GetIDLSources(std::vector<cmSourceFile*>& data) const
{
- srcs = this->ResxSources;
+ IMPLEMENT_VISIT(IDLSources);
}
//----------------------------------------------------------------------------
-void cmGeneratorTarget::GetIDLSources(std::vector<cmSourceFile*>& srcs) const
+void
+cmGeneratorTarget::GetHeaderSources(std::vector<cmSourceFile*>& data) const
{
- srcs = this->IDLSources;
+ IMPLEMENT_VISIT(HeaderSources);
}
//----------------------------------------------------------------------------
-void
-cmGeneratorTarget::GetHeaderSources(std::vector<cmSourceFile*>& srcs) const
+void cmGeneratorTarget::GetExtraSources(std::vector<cmSourceFile*>& data) const
{
- srcs = this->HeaderSources;
+ IMPLEMENT_VISIT(ExtraSources);
}
//----------------------------------------------------------------------------
-void cmGeneratorTarget::GetExtraSources(std::vector<cmSourceFile*>& srcs) const
+void
+cmGeneratorTarget::GetCustomCommands(std::vector<cmSourceFile*>& data) const
{
- srcs = this->ExtraSources;
+ IMPLEMENT_VISIT(CustomCommands);
}
//----------------------------------------------------------------------------
void
-cmGeneratorTarget::GetCustomCommands(std::vector<cmSourceFile*>& srcs) const
+cmGeneratorTarget::GetExternalObjects(std::vector<cmSourceFile*>& data) const
{
- srcs = this->CustomCommands;
+ IMPLEMENT_VISIT(ExternalObjects);
}
//----------------------------------------------------------------------------
void
cmGeneratorTarget::GetExpectedResxHeaders(std::set<std::string>& srcs) const
{
- srcs = this->ExpectedResxHeaders;
+ ResxData data;
+ IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
+ srcs = data.ExpectedResxHeaders;
}
//----------------------------------------------------------------------------
-void
-cmGeneratorTarget::GetExternalObjects(std::vector<cmSourceFile*>& srcs) const
+void cmGeneratorTarget::GetResxSources(std::vector<cmSourceFile*>& srcs) const
{
- srcs = this->ExternalObjects;
+ ResxData data;
+ IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
+ srcs = data.ResxSources;
}
//----------------------------------------------------------------------------
@@ -224,26 +433,25 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory(const char *dir,
&dagChecker), result);
}
- std::set<cmStdString> uniqueDeps;
+ std::set<cmTarget*> uniqueDeps;
for(std::vector<std::string>::const_iterator li = impl->Libraries.begin();
li != impl->Libraries.end(); ++li)
{
- if (uniqueDeps.insert(*li).second)
+ cmTarget* tgt = this->Makefile->FindTargetToUse(*li);
+ if (!tgt)
{
- cmTarget* tgt = this->Makefile->FindTargetToUse(*li);
-
- if (!tgt)
- {
- continue;
- }
+ continue;
+ }
- handleSystemIncludesDep(this->Makefile, *li, config, this->Target,
+ if (uniqueDeps.insert(tgt).second)
+ {
+ handleSystemIncludesDep(this->Makefile, tgt, config, this->Target,
&dagChecker, result, excludeImported);
- std::vector<std::string> deps;
- tgt->GetTransitivePropertyLinkLibraries(config, this->Target, deps);
+ std::vector<cmTarget*> deps;
+ tgt->GetTransitivePropertyTargets(config, this->Target, deps);
- for(std::vector<std::string>::const_iterator di = deps.begin();
+ for(std::vector<cmTarget*>::const_iterator di = deps.begin();
di != deps.end(); ++di)
{
if (uniqueDeps.insert(*di).second)
@@ -290,102 +498,6 @@ void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*> &files) const
}
//----------------------------------------------------------------------------
-void cmGeneratorTarget::ClassifySources()
-{
- cmsys::RegularExpression header(CM_HEADER_REGEX);
-
- cmTarget::TargetType targetType = this->Target->GetType();
- bool isObjLib = targetType == cmTarget::OBJECT_LIBRARY;
-
- std::vector<cmSourceFile*> badObjLib;
- std::vector<cmSourceFile*> sources;
- this->Target->GetSourceFiles(sources);
- for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
- si != sources.end(); ++si)
- {
- cmSourceFile* sf = *si;
- std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
- if(sf->GetCustomCommand())
- {
- this->CustomCommands.push_back(sf);
- }
- else if(targetType == cmTarget::UTILITY)
- {
- this->ExtraSources.push_back(sf);
- }
- else if(sf->GetPropertyAsBool("HEADER_FILE_ONLY"))
- {
- this->HeaderSources.push_back(sf);
- }
- else if(sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
- {
- this->ExternalObjects.push_back(sf);
- if(isObjLib) { badObjLib.push_back(sf); }
- }
- else if(sf->GetLanguage())
- {
- this->ObjectSources.push_back(sf);
- }
- else if(ext == "def")
- {
- this->ModuleDefinitionFile = sf->GetFullPath();
- if(isObjLib) { badObjLib.push_back(sf); }
- }
- else if(ext == "idl")
- {
- this->IDLSources.push_back(sf);
- if(isObjLib) { badObjLib.push_back(sf); }
- }
- else if(ext == "resx")
- {
- // Build and save the name of the corresponding .h file
- // This relationship will be used later when building the project files.
- // Both names would have been auto generated from Visual Studio
- // where the user supplied the file name and Visual Studio
- // appended the suffix.
- std::string resx = sf->GetFullPath();
- std::string hFileName = resx.substr(0, resx.find_last_of(".")) + ".h";
- this->ExpectedResxHeaders.insert(hFileName);
- this->ResxSources.push_back(sf);
- }
- else if(header.find(sf->GetFullPath().c_str()))
- {
- this->HeaderSources.push_back(sf);
- }
- else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str()))
- {
- // We only get here if a source file is not an external object
- // and has an extension that is listed as an ignored file type.
- // No message or diagnosis should be given.
- this->ExtraSources.push_back(sf);
- }
- else
- {
- this->ExtraSources.push_back(sf);
- if(isObjLib && ext != "txt")
- {
- badObjLib.push_back(sf);
- }
- }
- }
-
- if(!badObjLib.empty())
- {
- cmOStringStream e;
- e << "OBJECT library \"" << this->Target->GetName() << "\" contains:\n";
- for(std::vector<cmSourceFile*>::iterator i = badObjLib.begin();
- i != badObjLib.end(); ++i)
- {
- e << " " << (*i)->GetLocation().GetName() << "\n";
- }
- e << "but may contain only headers and sources that compile.";
- this->GlobalGenerator->GetCMakeInstance()
- ->IssueMessage(cmake::FATAL_ERROR, e.str(),
- this->Target->GetBacktrace());
- }
-}
-
-//----------------------------------------------------------------------------
void cmGeneratorTarget::LookupObjectLibraries()
{
std::vector<std::string> const& objLibs =
@@ -438,6 +550,14 @@ void cmGeneratorTarget::LookupObjectLibraries()
}
//----------------------------------------------------------------------------
+std::string cmGeneratorTarget::GetModuleDefinitionFile() const
+{
+ std::string data;
+ IMPLEMENT_VISIT_IMPL(ModuleDefinitionFile, COMMA std::string)
+ return data;
+}
+
+//----------------------------------------------------------------------------
void
cmGeneratorTarget::UseObjectLibraries(std::vector<std::string>& objs) const
{
@@ -876,3 +996,97 @@ bool cmStrictTargetComparison::operator()(cmTarget const* t1,
}
return nameResult < 0;
}
+
+//----------------------------------------------------------------------------
+struct cmGeneratorTarget::SourceFileFlags
+cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
+{
+ struct SourceFileFlags flags;
+ this->ConstructSourceFileFlags();
+ std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
+ this->SourceFlagsMap.find(sf);
+ if(si != this->SourceFlagsMap.end())
+ {
+ flags = si->second;
+ }
+ else
+ {
+ // Handle the MACOSX_PACKAGE_LOCATION property on source files that
+ // were not listed in one of the other lists.
+ if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
+ {
+ flags.MacFolder = location;
+ if(strcmp(location, "Resources") == 0)
+ {
+ flags.Type = cmGeneratorTarget::SourceFileTypeResource;
+ }
+ else
+ {
+ flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
+ }
+ }
+ }
+ return flags;
+}
+
+//----------------------------------------------------------------------------
+void cmGeneratorTarget::ConstructSourceFileFlags() const
+{
+ if(this->SourceFileFlagsConstructed)
+ {
+ return;
+ }
+ this->SourceFileFlagsConstructed = true;
+
+ // Process public headers to mark the source files.
+ if(const char* files = this->Target->GetProperty("PUBLIC_HEADER"))
+ {
+ std::vector<std::string> relFiles;
+ cmSystemTools::ExpandListArgument(files, relFiles);
+ for(std::vector<std::string>::iterator it = relFiles.begin();
+ it != relFiles.end(); ++it)
+ {
+ if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
+ {
+ SourceFileFlags& flags = this->SourceFlagsMap[sf];
+ flags.MacFolder = "Headers";
+ flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
+ }
+ }
+ }
+
+ // Process private headers after public headers so that they take
+ // precedence if a file is listed in both.
+ if(const char* files = this->Target->GetProperty("PRIVATE_HEADER"))
+ {
+ std::vector<std::string> relFiles;
+ cmSystemTools::ExpandListArgument(files, relFiles);
+ for(std::vector<std::string>::iterator it = relFiles.begin();
+ it != relFiles.end(); ++it)
+ {
+ if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
+ {
+ SourceFileFlags& flags = this->SourceFlagsMap[sf];
+ flags.MacFolder = "PrivateHeaders";
+ flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
+ }
+ }
+ }
+
+ // Mark sources listed as resources.
+ if(const char* files = this->Target->GetProperty("RESOURCE"))
+ {
+ std::vector<std::string> relFiles;
+ cmSystemTools::ExpandListArgument(files, relFiles);
+ for(std::vector<std::string>::iterator it = relFiles.begin();
+ it != relFiles.end(); ++it)
+ {
+ if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
+ {
+ SourceFileFlags& flags = this->SourceFlagsMap[sf];
+ flags.MacFolder = "Resources";
+ flags.Type = cmGeneratorTarget::SourceFileTypeResource;
+ }
+ }
+ }
+}