Commit 5fc83004 authored by Brad King's avatar Brad King
Browse files

ENH: Added utility dependency support. Now a project can depend on other...

ENH: Added utility dependency support.  Now a project can depend on other executables as well as link libraries.
parent 60507258
......@@ -130,7 +130,7 @@ void cmDSWMakefile::WriteProject(std::ostream& fout,
{
for(;i!= end; ++i)
{
if (strcmp(i->c_str(),dspname))
if(*i != dspname)
{
fout << "Begin Project Dependency\n";
fout << "Project_Dep_Name " << *i << "\n";
......@@ -138,6 +138,19 @@ void cmDSWMakefile::WriteProject(std::ostream& fout,
}
}
}
// write utility dependencies.
i = project->GetMakefile()->GetUtilities().begin();
end = project->GetMakefile()->GetUtilities().end();
for(;i!= end; ++i)
{
if(*i != dspname)
{
fout << "Begin Project Dependency\n";
fout << "Project_Dep_Name " << *i << "\n";
fout << "End Project Dependency\n";
}
}
fout << "}}}\n\n";
}
......
......@@ -130,7 +130,7 @@ void cmDSWMakefile::WriteProject(std::ostream& fout,
{
for(;i!= end; ++i)
{
if (strcmp(i->c_str(),dspname))
if(*i != dspname)
{
fout << "Begin Project Dependency\n";
fout << "Project_Dep_Name " << *i << "\n";
......@@ -138,6 +138,19 @@ void cmDSWMakefile::WriteProject(std::ostream& fout,
}
}
}
// write utility dependencies.
i = project->GetMakefile()->GetUtilities().begin();
end = project->GetMakefile()->GetUtilities().end();
for(;i!= end; ++i)
{
if(*i != dspname)
{
fout << "Begin Project Dependency\n";
fout << "Project_Dep_Name " << *i << "\n";
fout << "End Project Dependency\n";
}
}
fout << "}}}\n\n";
}
......
......@@ -106,6 +106,8 @@ void cmMakefile::Print()
this->PrintStringVector("m_LinkLibraries", m_LinkLibraries);
this->PrintStringVector("m_LinkLibrariesWin32", m_LinkLibrariesWin32);
this->PrintStringVector("m_LinkLibrariesUnix", m_LinkLibrariesUnix);
this->PrintStringVector("m_Utilities", m_Utilities);
this->PrintStringVector("m_UtilityDirectories", m_UtilityDirectories);
}
// Parse the given CMakeLists.txt file into a list of classes.
......@@ -285,6 +287,16 @@ bool cmMakefile::HasExecutables()
return false;
}
void cmMakefile::AddUtility(const char* util)
{
m_Utilities.push_back(util);
}
void cmMakefile::AddUtilityDirectory(const char* dir)
{
m_UtilityDirectories.push_back(dir);
}
void cmMakefile::AddLinkLibrary(const char* lib)
{
m_LinkLibraries.push_back(lib);
......
......@@ -87,6 +87,16 @@ public:
*/
void AddExecutable(cmClassFile&);
/**
* Add a utility on which this project depends.
*/
void AddUtility(const char*);
/**
* Add a directory in which a utility may be built.
*/
void AddUtilityDirectory(const char*);
/**
* Add a link library to the build.
*/
......@@ -273,6 +283,22 @@ public:
return m_LinkDirectories;
}
/**
* Get a list of utilities on which the project depends.
*/
std::vector<std::string>& GetUtilities()
{
return m_Utilities;
}
/**
* Get a list of directories that may contain the Utilities.
*/
std::vector<std::string>& GetUtilityDirectories()
{
return m_UtilityDirectories;
}
/**
* Get a list of link libraries in the build.
*/
......@@ -396,6 +422,8 @@ protected:
std::vector<std::string> m_MakeVerbatim; // lines copied from input file
std::vector<std::string> m_IncludeDirectories;
std::vector<std::string> m_LinkDirectories;
std::vector<std::string> m_Utilities;
std::vector<std::string> m_UtilityDirectories;
std::vector<std::string> m_LinkLibraries;
std::vector<std::string> m_LinkLibrariesWin32;
std::vector<std::string> m_LinkLibrariesUnix;
......
......@@ -58,7 +58,7 @@ void cmUnixMakefileGenerator::OutputMakefile(const char* file)
this->OutputVerbatim(fout);
this->OutputExecutableRules(fout);
this->OutputSubDirectoryRules(fout);
this->OutputDepends(fout);
this->OutputObjectDepends(fout);
this->OutputCustomRules(fout);
}
......@@ -102,7 +102,7 @@ void cmUnixMakefileGenerator::OutputSourceToObjectList(std::ostream& fout)
// output the list of libraries that the executables
// in this makefile will depend on.
void cmUnixMakefileGenerator::OutputDependLibraries(std::ostream& fout)
void cmUnixMakefileGenerator::OutputDependencies(std::ostream& fout)
{
std::vector<std::string>& libs = m_Makefile->GetLinkLibraries();
std::vector<std::string>& libdirs = m_Makefile->GetLinkDirectories();
......@@ -130,6 +130,29 @@ void cmUnixMakefileGenerator::OutputDependLibraries(std::ostream& fout)
}
}
}
std::vector<std::string>& utils = m_Makefile->GetUtilities();
std::vector<std::string>& utildirs = m_Makefile->GetUtilityDirectories();
std::vector<std::string>::iterator util;
// Search the list of utilities that may be used to generate code for
// this project.
for(util = utils.begin(); util != utils.end(); ++util)
{
bool found = false;
// loop over the list of directories that the utilities might
// be in, looking for an EXECUTABLES=(util) line.
for(dir = utildirs.begin(); dir != utildirs.end() && !found; ++dir)
{
std::string expression = "EXECUTABLES.*=.*";
expression += util->c_str();
if(cmSystemTools::Grep(dir->c_str(), "CMakeTargets.make",
expression.c_str()))
{
fout << *util << " ";
found = true;
}
}
}
fout << "\n";
}
......@@ -217,7 +240,7 @@ void cmUnixMakefileGenerator::OutputExecutableRules(std::ostream& fout)
// each executable will depend on. This will have all the
// libraries that the executable uses
fout << "CMAKE_DEPEND_LIBS = ";
this->OutputDependLibraries(fout);
this->OutputDependencies(fout);
// Now create rules for all of the executables to be built
std::vector<cmClassFile>& Classes = m_Makefile->GetClasses();
for(unsigned int i = 0; i < Classes.size(); i++)
......@@ -340,7 +363,7 @@ void cmUnixMakefileGenerator::OutputSubDirectoryRules(std::ostream& fout)
// Output the depend information for all the classes
// in the makefile. These would have been generated
// by the class cmMakeDepend GenerateMakefile
void cmUnixMakefileGenerator::OutputDepends(std::ostream& fout)
void cmUnixMakefileGenerator::OutputObjectDepends(std::ostream& fout)
{
std::vector<cmClassFile>& Classes = m_Makefile->GetClasses();
for(unsigned int i = 0; i < Classes.size(); i++)
......
......@@ -38,7 +38,7 @@ public:
* in the makefile. These would have been generated
* by the class cmMakeDepend.
*/
void OutputDepends(std::ostream&);
void OutputObjectDepends(std::ostream&);
protected:
void OutputMakefile(const char* file);
......@@ -48,7 +48,7 @@ protected:
void OutputExecutableRules(std::ostream&);
void OutputSubDirectoryRules(std::ostream&);
void OutputDependInformation(std::ostream&);
void OutputDependLibraries(std::ostream&);
void OutputDependencies(std::ostream&);
void OutputCustomRules(std::ostream&);
};
......
......@@ -60,13 +60,18 @@ bool cmUtilitySourceCommand::Invoke(std::vector<std::string>& args)
{ return true; }
}
// The source exists. Construct the cache entry for the executable's
// location.
// The source exists.
std::string cmakeCFGout = m_Makefile->GetDefinition("CMAKE_CFG_OUTDIR");
std::string utilityExecutable = m_Makefile->GetCurrentOutputDirectory();
utilityExecutable =
(utilityExecutable+"/"+relativeSource+"/"+cmakeCFGout+"/"
+utilityName+cmSystemTools::GetExecutableExtension());
std::string utilityDirectory = m_Makefile->GetCurrentOutputDirectory();
utilityDirectory += "/"+relativeSource;
// Tell the makefile where to look for this utility.
m_Makefile->AddUtilityDirectory(utilityDirectory.c_str());
// Construct the cache entry for the executable's location.
std::string utilityExecutable =
utilityDirectory+"/"+cmakeCFGout+"/"
+utilityName+cmSystemTools::GetExecutableExtension();
// Enter the value into the cache.
cmCacheManager::GetInstance()->AddCacheEntry(cacheEntry.c_str(),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment