#include "Component.h" #include "FileSystemUtilities.h" #include "Project.h" #include "ToolChain.h" #include /* CONFIGUREDCOMPONENT */ ConfiguredComponent::ConfiguredComponent(const Configurable& UseIn) : ToolName(UseIn.configuration().toolChain()), Debug(UseIn.configuration().includeDebugInformation()), Incomplete(false) { } bool ConfiguredComponent::isIncomplete() const { return Incomplete; } void ConfiguredComponent::markIncomplete() { Incomplete = true; } std::vector& ConfiguredComponent::includeDirectories() { return Includes; } std::vector& ConfiguredComponent::linkDirectories() { return Links; } std::vector& ConfiguredComponent::linkParts() { return Objects; } bool ConfiguredComponent::includeDebugInformation() const { return Debug; } std::string ConfiguredComponent::toolChain() const { return ToolName; } /* CREATECOMPONENTBYNAME */ class BoostLinkComponent : public LinkComponent { public: BoostLinkComponent(const std::string& Name); protected: virtual std::string uniqueString(const Configurable& UseIn); private: virtual std::string adornedStem(SharedPtr Tools, const Configurable& UseIn); virtual bool matches(SharedPtr CC, const Configurable& UseIn); }; class QtLinkComponent : public LinkComponent { public: QtLinkComponent(const std::string& Name, const std::string& Stem); protected: virtual std::string uniqueString(const Configurable& UseIn); private: virtual std::string adornedStem(SharedPtr Tools, const Configurable& UseIn); virtual bool matches(SharedPtr CC, const Configurable& UseIn); }; SharedPtr createNewComponent(const std::string& Name) { if (Name == "boost::lexical_cast") { HeaderOnlyComponent* Result = new HeaderOnlyComponent("boost_lexical_cast"); Result->addHeader("boost/lexical_cast.hpp"); return SharedPtr(Result); } else if (Name == "boost::date_time") { BoostLinkComponent* Result = new BoostLinkComponent("boost_date_time"); Result->addHeader("boost/date_time.hpp"); return SharedPtr(Result); } else if (Name == "qt::core") { LinkComponent* Result = new QtLinkComponent("qtcore","QtCore"); Result->addHeader("QtCore/QObject"); return Result; } else if (Name == "qt::gui") { LinkComponent* Result = new QtLinkComponent("qtgui","QtGui"); Result->addHeader("QtGui/QMessageBox"); return Result; } std::cout << "Don't know lib " << Name << std::endl; return SharedPtr(); } SharedPtr createComponentFromName(const std::string& Name) { static std::map > All; if (All[Name].isNull()) All[Name] = createNewComponent(Name); return All[Name]; } Component::~Component() { } SharedPtr Component::configuredFor(const Configurable& UseIn) { for (unsigned int i=0; i(); bool Failed = false; SharedPtr Result(readFromSystemConfiguration(UseIn)); if (Result.isNull()) Result = discoverFor(UseIn); if (Result.isNull()) Failures.push_back( (Failed=true,Result = new ConfiguredComponent(UseIn)) ); else if (Result->isIncomplete()) Failures.push_back( (Failed=true,Result) ); else Instances.push_back(Result); writeSystemConfiguration(Result, UseIn); if (Failed) { std::cout << "Missing configuration of " << userName() << " for use in " << UseIn.configuration().partName() << std::endl; return SharedPtr(); } return Result; } /* HEADERONLYCOMPONENT */ HeaderOnlyComponent::HeaderOnlyComponent(const std::string& aName) : Name(aName) { } void HeaderOnlyComponent::addHeader(const std::string& H) { Headers.push_back(H); } bool HeaderOnlyComponent::matches(SharedPtr, const Configurable&) { return true; } SharedPtr HeaderOnlyComponent::discoverFor(const Configurable& UseIn) { std::string IncludeDir; for (unsigned int i=0; i(); SharedPtr Result(new ConfiguredComponent(UseIn)); Result->includeDirectories().push_back(IncludeDir); return Result; } SharedPtr HeaderOnlyComponent::readFromSystemConfiguration(const Configurable& UseIn) { SharedPtr Result(new ConfiguredComponent(UseIn)); Result->includeDirectories() = Project::it().systemConfiguration().valueAsStringList( Name+uniqueString(UseIn)+".includedir"); if (!Result->includeDirectories().size()) Result->markIncomplete(); return Result; } void HeaderOnlyComponent::writeSystemConfiguration(SharedPtr CC, const Configurable& UseIn) { Project::it().systemConfiguration().configureComment("Configuration for lib "+Name); Project::it().systemConfiguration().configureKey(Name+uniqueString(UseIn)+".includedir",CC->includeDirectories()); } bool HeaderOnlyComponent::works(const std::string& IncludeDir) { for (unsigned int i=0; i CC, const Configurable& UseIn) { return UseIn.configuration().toolChain() == CC->toolChain(); } SharedPtr LinkComponent::discoverFor(const Configurable& UseIn) { SharedPtr Result = HeaderOnlyComponent::discoverFor(UseIn); if (Result.isNull()) return Result; SharedPtr Tools(ToolChain::createByName(UseIn.configuration().toolChain())); std::string LibDir; for (unsigned int i=0; imarkIncomplete(); return Result; } if (Result.isNull()) { Result = new ConfiguredComponent(UseIn); Result->markIncomplete(); } Result->linkDirectories().push_back(LibDir); Result->linkParts().push_back(adornedStem(Tools,UseIn)); return Result; } bool LinkComponent::linkWorks(SharedPtr Tools, const Configurable& UseIn, const std::string& LibDir) { std::string StaticLib(Tools->staticLibraryName(adornedStem(Tools,UseIn))); return fileExists(pathAppend(LibDir,StaticLib)); } SharedPtr LinkComponent::readFromSystemConfiguration(const Configurable& UseIn) { SharedPtr Result(HeaderOnlyComponent::readFromSystemConfiguration(UseIn)); Result->linkDirectories() = Project::it().systemConfiguration().valueAsStringList( name()+uniqueString(UseIn)+".librarydir"); Result->markIncomplete(); Result->linkParts() = Project::it().systemConfiguration().valueAsStringList( name()+uniqueString(UseIn)+".linkpart"); if (Result->isIncomplete() && !Result->linkDirectories().size() && !Result->linkParts().size()) return SharedPtr(); if (!Result->linkDirectories().size() || !Result->linkParts().size()) Result->markIncomplete(); return Result; } void LinkComponent::writeSystemConfiguration(SharedPtr CC, const Configurable& UseIn) { HeaderOnlyComponent::writeSystemConfiguration(CC, UseIn); Project::it().systemConfiguration().configureKey(name()+uniqueString(UseIn)+".librarydir",CC->linkDirectories()); Project::it().systemConfiguration().configureKey(name()+uniqueString(UseIn)+".linkpart",CC->linkParts()); } std::string LinkComponent::adornedStem(SharedPtr, const Configurable&) { return Stem; } std::string LinkComponent::uniqueString(const Configurable& UseIn) { return "."+UseIn.configuration().toolChain(); } /* BOOSTCOMPONENT */ BoostLinkComponent::BoostLinkComponent(const std::string& Name) : LinkComponent(Name,Name) { } std::string BoostLinkComponent::adornedStem(SharedPtr Tools, const Configurable& UseIn) { std::string Adorn, Debug; if (UseIn.configuration().includeDebugInformation()) Debug = "-gd"; std::string Version("-1_42"); // TODO find out real version if (Tools->type() == "msvc2005") Adorn = "-vc80-mt"+Debug+Version; else if (Tools->type() == "msvc2008") Adorn = "-vc90-mt"+Debug+Version; else if (Tools->type() == "msvc2010") Adorn = "-vc80-mt"+Debug+Version; // TODO find out the real naming scheme return stem()+Adorn; } bool BoostLinkComponent::matches(SharedPtr CC, const Configurable& UseIn) { return LinkComponent::matches(CC,UseIn) && UseIn.configuration().includeDebugInformation() == CC->includeDebugInformation(); } std::string BoostLinkComponent::uniqueString(const Configurable& UseIn) { return LinkComponent::uniqueString(UseIn)+ (UseIn.configuration().includeDebugInformation()?"_debug":""); } /* QTLINKCOMPONENT */ QtLinkComponent::QtLinkComponent(const std::string& Name, const std::string& Stem) : LinkComponent(Name, Stem) { } std::string QtLinkComponent::adornedStem(SharedPtr, const Configurable& UseIn) { if (UseIn.configuration().includeDebugInformation()) return stem()+"d4"; else return stem()+"4"; } bool QtLinkComponent::matches(SharedPtr CC, const Configurable& UseIn) { return LinkComponent::matches(CC,UseIn) && UseIn.configuration().includeDebugInformation() == CC->includeDebugInformation(); } std::string QtLinkComponent::uniqueString(const Configurable& UseIn) { return LinkComponent::uniqueString(UseIn)+ (UseIn.configuration().includeDebugInformation()?"_debug":""); }