diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 696b89bd0..81b4b3323 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -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; } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index d3e983570..44d4d61a3 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -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& GetSubdirDepends(const char* subdir) - { - return m_SubdirDepends[subdir]; - } - /** * Get a list of include directories in the build. */ @@ -571,8 +558,6 @@ protected: { }; - std::map m_SubdirDepends; - // The include and link-library paths. These may have order // dependency, so they must be vectors (not set). std::vector m_IncludeDirectories; diff --git a/Source/cmSubdirDependsCommand.cxx b/Source/cmSubdirDependsCommand.cxx index 9d92da44d..3fbcc55d4 100644 --- a/Source/cmSubdirDependsCommand.cxx +++ b/Source/cmSubdirDependsCommand.cxx @@ -43,18 +43,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // cmSubdirDependsCommand bool cmSubdirDependsCommand::InitialPass(std::vector const& args) { - if(args.size() < 2) - { - this->SetError("called with incorrect number of arguments"); - return false; - } - std::vector::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; } diff --git a/Source/cmSubdirDependsCommand.h b/Source/cmSubdirDependsCommand.h index 523a47bd4..a3fbd26d7 100644 --- a/Source/cmSubdirDependsCommand.h +++ b/Source/cmSubdirDependsCommand.h @@ -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); diff --git a/Source/cmUnixMakefileGenerator.cxx b/Source/cmUnixMakefileGenerator.cxx index 1a1c48f33..046172370 100644 --- a/Source/cmUnixMakefileGenerator.cxx +++ b/Source/cmUnixMakefileGenerator.cxx @@ -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& subdirDepends = m_Makefile->GetSubdirDepends(SubDirectories[i].c_str()); - for(std::set::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); }