diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2003-11-26 19:29:53 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2003-11-26 19:29:53 (GMT) |
commit | 5ccfaefb48758c7af0df011df160add1df1e1b53 (patch) | |
tree | ae6202ea94f7a18407752ead032cbe44aa5c7011 /Source/cmGlobalVisualStudio6Generator.cxx | |
parent | 945fcb581d2c8f21bd9bc077ccf505ee058fa81d (diff) | |
download | CMake-5ccfaefb48758c7af0df011df160add1df1e1b53.zip CMake-5ccfaefb48758c7af0df011df160add1df1e1b53.tar.gz CMake-5ccfaefb48758c7af0df011df160add1df1e1b53.tar.bz2 |
ENH: generate a sln and dsw file for each sub project in a project
Diffstat (limited to 'Source/cmGlobalVisualStudio6Generator.cxx')
-rw-r--r-- | Source/cmGlobalVisualStudio6Generator.cxx | 255 |
1 files changed, 164 insertions, 91 deletions
diff --git a/Source/cmGlobalVisualStudio6Generator.cxx b/Source/cmGlobalVisualStudio6Generator.cxx index 75b7467..5ff3f12 100644 --- a/Source/cmGlobalVisualStudio6Generator.cxx +++ b/Source/cmGlobalVisualStudio6Generator.cxx @@ -156,12 +156,24 @@ cmLocalGenerator *cmGlobalVisualStudio6Generator::CreateLocalGenerator() void cmGlobalVisualStudio6Generator::Generate() { + // collect sub-projects + this->CollectSubprojects(); + // add a special target that depends on ALL projects for easy build - // of Debug only + // of one configuration only. std::vector<std::string> srcs; - m_LocalGenerators[0]->GetMakefile()-> - AddUtilityCommand("ALL_BUILD", "echo","\"Build all projects\"",false,srcs); - + std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it; + for(it = m_SubProjectMap.begin(); it!= m_SubProjectMap.end(); ++it) + { + std::vector<cmLocalGenerator*>& gen = it->second; + // add the ALL_BUILD to the first local generator of each project + if(gen.size()) + { + gen[0]->GetMakefile()-> + AddUtilityCommand("ALL_BUILD", "echo","\"Build all projects\"",false,srcs); + } + } + // add the Run Tests command this->SetupTests(); @@ -172,104 +184,40 @@ void cmGlobalVisualStudio6Generator::Generate() this->OutputDSWFile(); } -// output the DSW file -void cmGlobalVisualStudio6Generator::OutputDSWFile() -{ - // create the dsw file name - std::string fname; - fname = m_CMakeInstance->GetStartOutputDirectory(); - fname += "/"; - if(strlen(m_LocalGenerators[0]->GetMakefile()->GetProjectName())) - { - fname += m_LocalGenerators[0]->GetMakefile()->GetProjectName(); - } - else - { - fname += "Project"; - } - fname += ".dsw"; - std::ofstream fout(fname.c_str()); - if(!fout) - { - cmSystemTools::Error("Error can not open DSW file for write: " - ,fname.c_str()); - return; - } - this->WriteDSWFile(fout); -} - - -inline std::string removeQuotes(const std::string& s) +// populate the m_SubProjectMap +void cmGlobalVisualStudio6Generator::CollectSubprojects() { - if(s[0] == '\"' && s[s.size()-1] == '\"') - { - return s.substr(1, s.size()-2); - } - return s; -} - - -void cmGlobalVisualStudio6Generator::SetupTests() -{ - std::string ctest = - m_LocalGenerators[0]->GetMakefile()->GetDefinition("CMAKE_COMMAND"); - ctest = removeQuotes(ctest); - ctest = cmSystemTools::GetFilenamePath(ctest.c_str()); - ctest += "/"; - ctest += "ctest"; - ctest += cmSystemTools::GetExecutableExtension(); - if(!cmSystemTools::FileExists(ctest.c_str())) - { - ctest = - m_LocalGenerators[0]->GetMakefile()->GetDefinition("CMAKE_COMMAND"); - ctest = cmSystemTools::GetFilenamePath(ctest.c_str()); - ctest += "/Debug/"; - ctest += "ctest"; - ctest += cmSystemTools::GetExecutableExtension(); - } - if(!cmSystemTools::FileExists(ctest.c_str())) - { - ctest = - m_LocalGenerators[0]->GetMakefile()->GetDefinition("CMAKE_COMMAND"); - ctest = cmSystemTools::GetFilenamePath(ctest.c_str()); - ctest += "/Release/"; - ctest += "ctest"; - ctest += cmSystemTools::GetExecutableExtension(); - } - // if we found ctest - if (cmSystemTools::FileExists(ctest.c_str())) + unsigned int i; + for(i = 0; i < m_LocalGenerators.size(); ++i) { - // Create a full path filename for output Testfile - std::string fname; - fname = m_CMakeInstance->GetStartOutputDirectory(); - fname += "/"; - fname += "DartTestfile.txt"; - - // If the file doesn't exist, then ENABLE_TESTING hasn't been run - if (cmSystemTools::FileExists(fname.c_str())) + std::string name = m_LocalGenerators[i]->GetMakefile()->GetProjectName(); + m_SubProjectMap[name].push_back(m_LocalGenerators[i]); + std::vector<std::string> const& pprojects + = m_LocalGenerators[i]->GetMakefile()->GetParentProjects(); + for(int k =0; k < pprojects.size(); ++k) { - std::vector<std::string> srcs; - m_LocalGenerators[0]->GetMakefile()-> - AddUtilityCommand("RUN_TESTS", ctest.c_str(), "-D $(IntDir)",false,srcs); + m_SubProjectMap[pprojects[k]].push_back(m_LocalGenerators[i]); } } } // Write a DSW file to the stream -void cmGlobalVisualStudio6Generator::WriteDSWFile(std::ostream& fout) +void cmGlobalVisualStudio6Generator::WriteDSWFile(std::ostream& fout, + std::vector<cmLocalGenerator*>& generators) { // Write out the header for a DSW file this->WriteDSWHeader(fout); - // Get the home directory with the trailing slash std::string homedir = m_CMakeInstance->GetHomeDirectory(); homedir += "/"; unsigned int i; - for(i = 0; i < m_LocalGenerators.size(); ++i) + bool doneAllBuild = false; + bool doneRunTests = false; + for(i = 0; i < generators.size(); ++i) { - cmMakefile* mf = m_LocalGenerators[i]->GetMakefile(); + cmMakefile* mf = generators[i]->GetMakefile(); // Get the source directory from the makefile std::string dir = mf->GetStartDirectory(); @@ -281,28 +229,28 @@ void cmGlobalVisualStudio6Generator::WriteDSWFile(std::ostream& fout) // than one dsp could have been created per input CMakeLists.txt file // for each target std::vector<std::string> dspnames = - static_cast<cmLocalVisualStudio6Generator *>(m_LocalGenerators[i]) + static_cast<cmLocalVisualStudio6Generator *>(generators[i]) ->GetCreatedProjectNames(); - cmTargets &tgts = m_LocalGenerators[i]->GetMakefile()->GetTargets(); + cmTargets &tgts = generators[i]->GetMakefile()->GetTargets(); cmTargets::iterator l = tgts.begin(); for(std::vector<std::string>::iterator si = dspnames.begin(); l != tgts.end(); ++l) { // special handling for the current makefile - if(mf == m_LocalGenerators[0]->GetMakefile()) + if(mf == generators[0]->GetMakefile()) { dir = "."; // no subdirectory for project generated // if this is the special ALL_BUILD utility, then // make it depend on every other non UTILITY project. // This is done by adding the names to the GetUtilities // vector on the makefile - if(l->first == "ALL_BUILD") + if(l->first == "ALL_BUILD" && !doneAllBuild) { unsigned int j; - for(j = 0; j < m_LocalGenerators.size(); ++j) + for(j = 0; j < generators.size(); ++j) { const cmTargets &atgts = - m_LocalGenerators[j]->GetMakefile()->GetTargets(); + generators[j]->GetMakefile()->GetTargets(); for(cmTargets::const_iterator al = atgts.begin(); al != atgts.end(); ++al) { @@ -339,7 +287,34 @@ void cmGlobalVisualStudio6Generator::WriteDSWFile(std::ostream& fout) if ((l->second.GetType() != cmTarget::INSTALL_FILES) && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)) { - this->WriteProject(fout, si->c_str(), dir.c_str(),l->second); + bool skip = false; + // skip ALL_BUILD and RUN_TESTS if they have already been added + if(l->first == "ALL_BUILD" ) + { + if(doneAllBuild) + { + skip = true; + } + else + { + doneAllBuild = true; + } + } + if(l->first == "RUN_TESTS") + { + if(doneRunTests) + { + skip = true; + } + else + { + doneRunTests = true; + } + } + if(!skip) + { + this->WriteProject(fout, si->c_str(), dir.c_str(),l->second); + } ++si; } } @@ -350,6 +325,104 @@ void cmGlobalVisualStudio6Generator::WriteDSWFile(std::ostream& fout) this->WriteDSWFooter(fout); } +void cmGlobalVisualStudio6Generator::OutputDSWFile(const char* projectName, + std::vector<cmLocalGenerator*>& generators) +{ + if(generators.size() == 0) + { + return; + } + std::string fname = generators[0]->GetMakefile()->GetStartOutputDirectory(); + fname += "/"; + fname += generators[0]->GetMakefile()->GetProjectName(); + fname += ".dsw"; + std::ofstream fout(fname.c_str()); + if(!fout) + { + cmSystemTools::Error("Error can not open DSW file for write: ", + fname.c_str()); + return; + } + this->WriteDSWFile(fout, generators); +} + +// output the DSW file +void cmGlobalVisualStudio6Generator::OutputDSWFile() +{ + std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it; + for(it = m_SubProjectMap.begin(); it!= m_SubProjectMap.end(); ++it) + { + std::vector<cmLocalGenerator*>& gen = it->second; + this->OutputDSWFile(it->first.c_str(), it->second); + } +} + + +inline std::string removeQuotes(const std::string& s) +{ + if(s[0] == '\"' && s[s.size()-1] == '\"') + { + return s.substr(1, s.size()-2); + } + return s; +} + + +void cmGlobalVisualStudio6Generator::SetupTests() +{ + std::string ctest = + m_LocalGenerators[0]->GetMakefile()->GetDefinition("CMAKE_COMMAND"); + ctest = removeQuotes(ctest); + ctest = cmSystemTools::GetFilenamePath(ctest.c_str()); + ctest += "/"; + ctest += "ctest"; + ctest += cmSystemTools::GetExecutableExtension(); + if(!cmSystemTools::FileExists(ctest.c_str())) + { + ctest = + m_LocalGenerators[0]->GetMakefile()->GetDefinition("CMAKE_COMMAND"); + ctest = cmSystemTools::GetFilenamePath(ctest.c_str()); + ctest += "/Debug/"; + ctest += "ctest"; + ctest += cmSystemTools::GetExecutableExtension(); + } + if(!cmSystemTools::FileExists(ctest.c_str())) + { + ctest = + m_LocalGenerators[0]->GetMakefile()->GetDefinition("CMAKE_COMMAND"); + ctest = cmSystemTools::GetFilenamePath(ctest.c_str()); + ctest += "/Release/"; + ctest += "ctest"; + ctest += cmSystemTools::GetExecutableExtension(); + } + // if we found ctest + if (cmSystemTools::FileExists(ctest.c_str())) + { + // Create a full path filename for output Testfile + std::string fname; + fname = m_CMakeInstance->GetStartOutputDirectory(); + fname += "/"; + fname += "DartTestfile.txt"; + + // If the file doesn't exist, then ENABLE_TESTING hasn't been run + if (cmSystemTools::FileExists(fname.c_str())) + { + std::vector<std::string> srcs; + std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it; + for(it = m_SubProjectMap.begin(); it!= m_SubProjectMap.end(); ++it) + { + std::vector<cmLocalGenerator*>& gen = it->second; + // add the ALL_BUILD to the first local generator of each project + if(gen.size()) + { + gen[0]->GetMakefile()-> + AddUtilityCommand("RUN_TESTS", ctest.c_str(), "-D $(IntDir)",false,srcs); + } + } + } + } +} + // Write a dsp file into the DSW file, // Note, that dependencies from executables to |