ENH: SUBDIR_DEPENDS command now does nothing. The parallel build functionality is now automatic. Dependencies are setup to force the same build order as a single threaded build, but multiple files in the same directory can be built simultaneously. Also fixed bug with inheriting CMakeLists.txt files when a directory level is skipped.

This commit is contained in:
Brad King 2001-12-10 11:03:44 -05:00
parent a946931f91
commit ee31c3e0a4
5 changed files with 34 additions and 54 deletions

View File

@ -560,12 +560,6 @@ void cmMakefile::AddSubDirectory(const char* sub)
m_SubDirectories.push_back(sub);
}
void cmMakefile::AddSubdirDependency(const char* subdir,
const char* dependency)
{
m_SubdirDepends[subdir].insert(dependency);
}
void cmMakefile::AddIncludeDirectory(const char* inc, bool before)
{
// Don't add an include directory that is already present. Yes,
@ -812,12 +806,26 @@ std::string cmMakefile::GetParentListFileName(const char *currentFileName)
// is there a CMakeLists.txt file in the parent directory ?
parentFile = listsDir;
parentFile += "/CMakeLists.txt";
if(!cmSystemTools::FileExists(parentFile.c_str()))
while(!cmSystemTools::FileExists(parentFile.c_str()))
{
parentFile = "";
return parentFile;
// There is no CMakeLists.txt file in the parent directory. This
// can occur when coming out of a subdirectory resulting from a
// SUBDIRS(Foo/Bar) command (coming out of Bar into Foo). Try
// walking up until a CMakeLists.txt is found or the home
// directory is hit.
// if we are in the home directory then stop, return 0
if(m_cmHomeDirectory == listsDir) { return ""; }
// is there a parent directory we can check
pos = listsDir.rfind('/');
// if we could not find the directory return 0
if(pos == std::string::npos) { return ""; }
listsDir = listsDir.substr(0, pos);
parentFile = listsDir;
parentFile += "/CMakeLists.txt";
}
return parentFile;
}

View File

@ -210,11 +210,6 @@ public:
*/
void AddSubDirectory(const char*);
/**
* Add a subdirectory dependency.
*/
void AddSubdirDependency(const char* subdir, const char* dependency);
/**
* Add an include directory to the build.
*/
@ -404,14 +399,6 @@ public:
return m_SubDirectories;
}
/**
* Get the subdirectory dependencies for the given subdirectory.
*/
const std::set<cmStdString>& GetSubdirDepends(const char* subdir)
{
return m_SubdirDepends[subdir];
}
/**
* Get a list of include directories in the build.
*/
@ -571,8 +558,6 @@ protected:
{
};
std::map<cmStdString, StringSet > m_SubdirDepends;
// The include and link-library paths. These may have order
// dependency, so they must be vectors (not set).
std::vector<std::string> m_IncludeDirectories;

View File

@ -43,18 +43,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// cmSubdirDependsCommand
bool cmSubdirDependsCommand::InitialPass(std::vector<std::string> const& args)
{
if(args.size() < 2)
{
this->SetError("called with incorrect number of arguments");
return false;
}
std::vector<std::string>::const_iterator i = args.begin();
std::string subdir = *i;
for(++i; i != args.end(); ++i)
{
m_Makefile->AddSubdirDependency(subdir.c_str(), i->c_str());
}
return true;
}

View File

@ -45,15 +45,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "cmCommand.h"
/** \class cmSubdirDependsCommand
* \brief Specify a set of subdirectories which must be built before the
* given subdirectory.
* \brief Legacy command. Do not use.
*
* cmSubdirDependsCommand specifies for one entry of a SUBDIRS command
* a set of the other entries that must be built before it. CMake
* will still walk the subdirectories in the order in which they
* appear in a SUBDIRS command, but the generated makefiles will be
* setup to be sure one directory is finished before another begins.
* This allows parallel builds to work correctly.
* cmSubdirDependsCommand has been left in CMake for compatability with
* projects already using it. Its functionality in supporting parallel
* builds is now automatic. The command does not do anything.
*/
class cmSubdirDependsCommand : public cmCommand
{
@ -82,7 +78,7 @@ public:
*/
virtual const char* GetTerseDocumentation()
{
return "Add a set of subdirectories on which another subdirectory depends.";
return "Legacy command. Does nothing.";
}
/**
@ -92,9 +88,8 @@ public:
{
return
"SUBDIR_DEPENDS(subdir dep1 dep2 ...)\n"
"Add a set of subdirectories on which \"subdir\" depends.\n"
"This sets up the generated makefiles to build the subdirectries dep1, "
"dep2, ... before \"subdir\" itself.";
"Does not do anything. This command used to help projects order\n"
"parallel builds correctly. This functionality is now automatic.";
}
cmTypeMacro(cmSubdirDependsCommand, cmCommand);

View File

@ -1013,18 +1013,22 @@ OutputSubDirectoryVars(std::ostream& fout,
}
}
fout << "# Targets for making " << target << " in subdirectories.\n";
std::string last = "";
for(unsigned int i =0; i < SubDirectories.size(); i++)
{
std::string subdir = FixDirectoryName(SubDirectories[i].c_str());
fout << target << "_" << subdir.c_str() << ":";
const std::set<cmStdString>& subdirDepends = m_Makefile->GetSubdirDepends(SubDirectories[i].c_str());
for(std::set<cmStdString>::const_iterator d = subdirDepends.begin();
d != subdirDepends.end(); ++d)
// Make each subdirectory depend on previous one. This forces
// parallel builds (make -j 2) to build in same order as a single
// threaded build to avoid dependency problems.
if(i > 0)
{
std::string fixed_d = FixDirectoryName(d->c_str());
fout << " " << target << "_" << fixed_d.c_str();
fout << " " << target << "_" << last.c_str();
}
fout << "\n";
last = subdir;
this->BuildInSubDirectory(fout, SubDirectories[i].c_str(),
target1, target2);
}