From 49aebe6c99934dec634a3b497128465645db406c Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Wed, 4 Sep 2002 15:23:56 -0400 Subject: [PATCH] new arch --- Source/cmGlobalVisualStudio6Generator.cxx | 406 ++++++++++ Source/cmGlobalVisualStudio6Generator.h | 78 ++ Source/cmGlobalVisualStudio7Generator.cxx | 568 ++++++++++++++ Source/cmGlobalVisualStudio7Generator.h | 95 +++ Source/cmLocalVisualStudio6Generator.cxx | 844 ++++++++++++++++++++ Source/cmLocalVisualStudio6Generator.h | 106 +++ Source/cmLocalVisualStudio7Generator.cxx | 906 ++++++++++++++++++++++ Source/cmLocalVisualStudio7Generator.h | 151 ++++ 8 files changed, 3154 insertions(+) create mode 100644 Source/cmGlobalVisualStudio6Generator.cxx create mode 100644 Source/cmGlobalVisualStudio6Generator.h create mode 100644 Source/cmGlobalVisualStudio7Generator.cxx create mode 100644 Source/cmGlobalVisualStudio7Generator.h create mode 100644 Source/cmLocalVisualStudio6Generator.cxx create mode 100644 Source/cmLocalVisualStudio6Generator.h create mode 100644 Source/cmLocalVisualStudio7Generator.cxx create mode 100644 Source/cmLocalVisualStudio7Generator.h diff --git a/Source/cmGlobalVisualStudio6Generator.cxx b/Source/cmGlobalVisualStudio6Generator.cxx new file mode 100644 index 000000000..bd0a00a93 --- /dev/null +++ b/Source/cmGlobalVisualStudio6Generator.cxx @@ -0,0 +1,406 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "cmGlobalVisualStudio6Generator.h" +#include "cmLocalVisualStudio6Generator.h" +#include "cmMakefile.h" +#include "cmake.h" + +void cmGlobalVisualStudio6Generator::EnableLanguage(const char* lang, + cmMakefile *mf) +{ + if (!m_LanguagesEnabled) + { + m_LanguagesEnabled = true; + + // now load the settings + if(!mf->GetDefinition("CMAKE_ROOT")) + { + cmSystemTools::Error( + "CMAKE_ROOT has not been defined, bad GUI or driver program"); + return; + } + if(!this->GetLanguageEnabled("CXX")) + { + std::string fpath = + mf->GetDefinition("CMAKE_ROOT"); + fpath += "/Templates/CMakeWindowsSystemConfig.cmake"; + mf->ReadListFile(NULL,fpath.c_str()); + this->SetLanguageEnabled("CXX"); + } + } +} + +int cmGlobalVisualStudio6Generator::TryCompile(const char *, + const char *bindir, + const char *projectName) +{ + // now build the test + std::string makeCommand = + m_CMakeInstance->GetCacheManager()->GetCacheValue("CMAKE_MAKE_PROGRAM"); + if(makeCommand.size() == 0) + { + cmSystemTools::Error( + "Generator cannot find the appropriate make command."); + return 1; + } + makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str()); + std::string lowerCaseCommand = makeCommand; + cmSystemTools::LowerCase(lowerCaseCommand); + + /** + * Run an executable command and put the stdout in output. + */ + std::string output; + + std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); + cmSystemTools::ChangeDirectory(bindir); + + // if there are spaces in the makeCommand, assume a full path + // and convert it to a path with no spaces in it as the + // RunCommand does not like spaces +#if defined(_WIN32) && !defined(__CYGWIN__) + if(makeCommand.find(' ') != std::string::npos) + { + cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand); + } +#endif + makeCommand += " "; + makeCommand += projectName; + makeCommand += ".dsw /MAKE \"ALL_BUILD - Debug\" /REBUILD"; + + if (!cmSystemTools::RunCommand(makeCommand.c_str(), output)) + { + cmSystemTools::Error("Generator: execution of msdev failed."); + // return to the original directory + cmSystemTools::ChangeDirectory(cwd.c_str()); + return 1; + } + cmSystemTools::ChangeDirectory(cwd.c_str()); + return 0; +} + +///! Create a local generator appropriate to this Global Generator +cmLocalGenerator *cmGlobalVisualStudio6Generator::CreateLocalGenerator() +{ + cmLocalGenerator *lg = new cmLocalVisualStudio6Generator; + lg->SetGlobalGenerator(this); + return lg; +} + + +void cmGlobalVisualStudio6Generator::Generate() +{ + // add a special target that depends on ALL projects for easy build + // of Debug only + m_LocalGenerators[0]->GetMakefile()-> + AddUtilityCommand("ALL_BUILD", "echo","\"Build all projects\"",false); + + // add the Run Tests command + this->SetupTests(); + + // first do the superclass method + this->cmGlobalGenerator::Generate(); + + // Now write out the DSW + 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) +{ + 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())) + { + m_LocalGenerators[0]->GetMakefile()-> + AddUtilityCommand("RUN_TESTS", ctest.c_str(), "-D $(IntDir)",false); + } + } +} + +// Write a DSW file to the stream +void cmGlobalVisualStudio6Generator::WriteDSWFile(std::ostream& fout) +{ + // 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 += "/"; + + int i; + for(i = 0; i < m_LocalGenerators.size(); ++i) + { + cmMakefile* mf = m_LocalGenerators[i]->GetMakefile(); + + // Get the source directory from the makefile + std::string dir = mf->GetStartDirectory(); + // remove the home directory and / from the source directory + // this gives a relative path + cmSystemTools::ReplaceString(dir, homedir.c_str(), ""); + + // Get the list of create dsp files names from the LocalGenerator, more + // than one dsp could have been created per input CMakeLists.txt file + // for each target + std::vector dspnames = + static_cast(m_LocalGenerators[i]) + ->GetCreatedProjectNames(); + cmTargets &tgts = m_LocalGenerators[i]->GetMakefile()->GetTargets(); + cmTargets::iterator l = tgts.begin(); + for(std::vector::iterator si = dspnames.begin(); + l != tgts.end(); ++l) + { + // special handling for the current makefile + if(mf == m_LocalGenerators[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") + { + int j; + for(j = 0; j < m_LocalGenerators.size(); ++j) + { + const cmTargets &atgts = + m_LocalGenerators[j]->GetMakefile()->GetTargets(); + for(cmTargets::const_iterator al = atgts.begin(); + al != atgts.end(); ++al) + { + if (al->second.IsInAll()) + { + if (al->second.GetType() == cmTarget::UTILITY) + { + l->second.AddUtility(al->first.c_str()); + } + else + { + l->second.AddLinkLibrary(al->first, cmTarget::GENERAL); + } + } + } + } + } + } + // Write the project into the DSW file + if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0) + { + cmCustomCommand cc = l->second.GetCustomCommands()[0]; + + // dodgy use of the cmCustomCommand's members to store the + // arguments from the INCLUDE_EXTERNAL_MSPROJECT command + std::vector stuff = cc.GetDepends(); + std::vector depends = cc.GetOutputs(); + this->WriteExternalProject(fout, stuff[0].c_str(), stuff[1].c_str(), depends); + ++si; + } + else + { + if ((l->second.GetType() != cmTarget::INSTALL_FILES) + && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)) + { + this->WriteProject(fout, si->c_str(), dir.c_str(),l->second); + ++si; + } + } + } + } + + // Write the footer for the DSW file + this->WriteDSWFooter(fout); +} + + +// Write a dsp file into the DSW file, +// Note, that dependencies from executables to +// the libraries it uses are also done here +void cmGlobalVisualStudio6Generator::WriteProject(std::ostream& fout, + const char* dspname, + const char* dir, + const cmTarget& target) +{ + fout << "#########################################################" + "######################\n\n"; + fout << "Project: \"" << dspname << "\"=" + << dir << "\\" << dspname << ".dsp - Package Owner=<4>\n\n"; + fout << "Package=<5>\n{{{\n}}}\n\n"; + fout << "Package=<4>\n"; + fout << "{{{\n"; + + // insert Begin Project Dependency Project_Dep_Name project stuff here + if (target.GetType() != cmTarget::STATIC_LIBRARY) + { + cmTarget::LinkLibraries::const_iterator j, jend; + j = target.GetLinkLibraries().begin(); + jend = target.GetLinkLibraries().end(); + for(;j!= jend; ++j) + { + if(j->first != dspname) + { + // is the library part of this DSW ? If so add dependency + std::string libPath = j->first + "_CMAKE_PATH"; + const char* cacheValue + = m_CMakeInstance->GetCacheDefinition(libPath.c_str()); + if(cacheValue) + { + fout << "Begin Project Dependency\n"; + fout << "Project_Dep_Name " << j->first << "\n"; + fout << "End Project Dependency\n"; + } + } + } + } + + std::set::const_iterator i, end; + // write utility dependencies. + i = target.GetUtilities().begin(); + end = target.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"; +} + + +// Write a dsp file into the DSW file, +// Note, that dependencies from executables to +// the libraries it uses are also done here +void cmGlobalVisualStudio6Generator::WriteExternalProject(std::ostream& fout, + const char* name, + const char* location, + const std::vector& dependencies) +{ + fout << "#########################################################" + "######################\n\n"; + fout << "Project: \"" << name << "\"=" + << location << " - Package Owner=<4>\n\n"; + fout << "Package=<5>\n{{{\n}}}\n\n"; + fout << "Package=<4>\n"; + fout << "{{{\n"; + + + std::vector::const_iterator i, end; + // write dependencies. + i = dependencies.begin(); + end = dependencies.end(); + for(;i!= end; ++i) + { + fout << "Begin Project Dependency\n"; + fout << "Project_Dep_Name " << *i << "\n"; + fout << "End Project Dependency\n"; + } + fout << "}}}\n\n"; +} + + + +// Standard end of dsw file +void cmGlobalVisualStudio6Generator::WriteDSWFooter(std::ostream& fout) +{ + fout << "######################################################" + "#########################\n\n"; + fout << "Global:\n\n"; + fout << "Package=<5>\n{{{\n}}}\n\n"; + fout << "Package=<3>\n{{{\n}}}\n\n"; + fout << "#####################################################" + "##########################\n\n"; +} + + +// ouput standard header for dsw file +void cmGlobalVisualStudio6Generator::WriteDSWHeader(std::ostream& fout) +{ + fout << "Microsoft Developer Studio Workspace File, Format Version 6.00\n"; + fout << "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\n\n"; +} diff --git a/Source/cmGlobalVisualStudio6Generator.h b/Source/cmGlobalVisualStudio6Generator.h new file mode 100644 index 000000000..63905b041 --- /dev/null +++ b/Source/cmGlobalVisualStudio6Generator.h @@ -0,0 +1,78 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef cmGlobalVisualStudio6Generator_h +#define cmGlobalVisualStudio6Generator_h + +#include "cmGlobalGenerator.h" + +class cmTarget; + +/** \class cmGlobalVisualStudio6Generator + * \brief Write a Unix makefiles. + * + * cmGlobalVisualStudio6Generator manages UNIX build process for a tree + */ +class cmGlobalVisualStudio6Generator : public cmGlobalGenerator +{ +public: + ///! Get the name for the generator. + virtual const char* GetName() { + return cmGlobalVisualStudio6Generator::GetActualName();} + static const char* GetActualName() {return "Visual Studio 6";} + + ///! Create a local generator appropriate to this Global Generator + virtual cmLocalGenerator *CreateLocalGenerator(); + + /** + * Try to determine system infomation such as shared library + * extension, pthreads, byte order etc. + */ + virtual void EnableLanguage(const char*, cmMakefile *mf); + + /** + * Try running cmake and building a file. This is used for dynalically + * loaded commands, not as part of the usual build process. + */ + virtual int TryCompile(const char *srcdir, const char *bindir, + const char *projectName); + + /** + * Generate the all required files for building this project/tree. This + * basically creates a series of LocalGenerators for each directory and + * requests that they Generate. + */ + virtual void Generate(); + + /** + * Generate the DSW workspace file. + */ + virtual void OutputDSWFile(); + +private: + void SetupTests(); + void WriteDSWFile(std::ostream& fout); + void WriteDSWHeader(std::ostream& fout); + void WriteProject(std::ostream& fout, + const char* name, const char* path, + const cmTarget &t); + void WriteExternalProject(std::ostream& fout, + const char* name, const char* path, + const std::vector& dependencies); + void WriteDSWFooter(std::ostream& fout); +}; + +#endif diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx new file mode 100644 index 000000000..75ce6d58b --- /dev/null +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -0,0 +1,568 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "cmGlobalVisualStudio7Generator.h" +#include "cmLocalVisualStudio7Generator.h" +#include "cmMakefile.h" +#include "cmake.h" +#include "windows.h" + +void cmGlobalVisualStudio7Generator::EnableLanguage(const char* lang, + cmMakefile *mf) +{ + if (!m_LanguagesEnabled) + { + m_LanguagesEnabled = true; + + // now load the settings + if(!mf->GetDefinition("CMAKE_ROOT")) + { + cmSystemTools::Error( + "CMAKE_ROOT has not been defined, bad GUI or driver program"); + return; + } + if(!this->GetLanguageEnabled("CXX")) + { + std::string fpath = + mf->GetDefinition("CMAKE_ROOT"); + fpath += "/Templates/CMakeDotNetSystemConfig.cmake"; + mf->ReadListFile(NULL,fpath.c_str()); + this->SetLanguageEnabled("CXX"); + } + } +} + +int cmGlobalVisualStudio7Generator::TryCompile(const char *, + const char *bindir, + const char *projectName) +{ + // now build the test + std::string makeCommand = + m_CMakeInstance->GetCacheManager()->GetCacheValue("CMAKE_MAKE_PROGRAM"); + if(makeCommand.size() == 0) + { + cmSystemTools::Error( + "Generator cannot find the appropriate make command."); + return 1; + } + makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str()); + std::string lowerCaseCommand = makeCommand; + cmSystemTools::LowerCase(lowerCaseCommand); + + /** + * Run an executable command and put the stdout in output. + */ + std::string output; + + std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); + cmSystemTools::ChangeDirectory(bindir); + + // if there are spaces in the makeCommand, assume a full path + // and convert it to a path with no spaces in it as the + // RunCommand does not like spaces +#if defined(_WIN32) && !defined(__CYGWIN__) + if(makeCommand.find(' ') != std::string::npos) + { + cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand); + } +#endif + makeCommand += " "; + makeCommand += projectName; + makeCommand += ".sln /rebuild Debug /project ALL_BUILD"; + + if (!cmSystemTools::RunCommand(makeCommand.c_str(), output)) + { + cmSystemTools::Error("Generator: execution of devenv failed."); + // return to the original directory + cmSystemTools::ChangeDirectory(cwd.c_str()); + return 1; + } + cmSystemTools::ChangeDirectory(cwd.c_str()); + return 0; +} + +///! Create a local generator appropriate to this Global Generator +cmLocalGenerator *cmGlobalVisualStudio7Generator::CreateLocalGenerator() +{ + cmLocalGenerator *lg = new cmLocalVisualStudio7Generator; + lg->SetGlobalGenerator(this); + return lg; +} + + +void cmGlobalVisualStudio7Generator::SetupTests() +{ + std::string ctest = + m_LocalGenerators[0]->GetMakefile()->GetDefinition("CMAKE_COMMAND"); + 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())) + { + m_LocalGenerators[0]->GetMakefile()-> + AddUtilityCommand("RUN_TESTS", ctest.c_str(), "-D $(IntDir)",false); + } + } +} + +void cmGlobalVisualStudio7Generator::GenerateConfigurations() +{ + // process the configurations + std::string configTypes = + m_CMakeInstance->GetCacheDefinition("CMAKE_CONFIGURATION_TYPES"); + std::string::size_type start = 0; + std::string::size_type endpos = 0; + while(endpos != std::string::npos) + { + endpos = configTypes.find(' ', start); + std::string config; + std::string::size_type len; + if(endpos != std::string::npos) + { + len = endpos - start; + } + else + { + len = configTypes.size() - start; + } + config = configTypes.substr(start, len); + if(config == "Debug" || config == "Release" || + config == "MinSizeRel" || config == "RelWithDebInfo") + { + // only add unique configurations + if(std::find(m_Configurations.begin(), + m_Configurations.end(), config) == m_Configurations.end()) + { + m_Configurations.push_back(config); + } + } + else + { + cmSystemTools::Error( + "Invalid configuration type in CMAKE_CONFIGURATION_TYPES: ", + config.c_str(), + " (Valid types are Debug,Release,MinSizeRel,RelWithDebInfo)"); + } + start = endpos+1; + } + if(m_Configurations.size() == 0) + { + m_Configurations.push_back("Debug"); + m_Configurations.push_back("Release"); + } +} + +void cmGlobalVisualStudio7Generator::Generate() +{ + // Generate the possible configuraitons + this->GenerateConfigurations(); + + // add a special target that depends on ALL projects for easy build + // of Debug only + m_LocalGenerators[0]->GetMakefile()-> + AddUtilityCommand("ALL_BUILD", "echo","\"Build all projects\"",false); + + // add the Run Tests command + this->SetupTests(); + + // first do the superclass method + this->cmGlobalGenerator::Generate(); + + // Now write out the DSW + this->OutputSLNFile(); +} + +// output the SLN file +void cmGlobalVisualStudio7Generator::OutputSLNFile() +{ + // if this is an out of source build, create the output directory + if(strcmp(m_CMakeInstance->GetStartOutputDirectory(), + m_CMakeInstance->GetHomeDirectory()) != 0) + { + if(!cmSystemTools::MakeDirectory(m_CMakeInstance->GetStartOutputDirectory())) + { + cmSystemTools::Error("Error creating output directory for SLN file", + m_CMakeInstance->GetStartOutputDirectory()); + } + } + // create the dsw file name + std::string fname; + fname = m_CMakeInstance->GetStartOutputDirectory(); + fname += "/"; + if(strlen(m_LocalGenerators[0]->GetMakefile()->GetProjectName()) == 0) + { + m_LocalGenerators[0]->GetMakefile()->SetProjectName("Project"); + } + fname += m_LocalGenerators[0]->GetMakefile()->GetProjectName(); + fname += ".sln"; + std::ofstream fout(fname.c_str()); + if(!fout) + { + cmSystemTools::Error("Error can not open SLN file for write: " + ,fname.c_str()); + return; + } + this->WriteSLNFile(fout); +} + + +// Write a SLN file to the stream +void cmGlobalVisualStudio7Generator::WriteSLNFile(std::ostream& fout) +{ + // Write out the header for a SLN file + this->WriteSLNHeader(fout); + + // Get the home directory with the trailing slash + std::string homedir = m_CMakeInstance->GetHomeDirectory(); + homedir += "/"; + + // For each cmMakefile, create a VCProj for it, and + // add it to this SLN file + int i; + for(i = 0; i < m_LocalGenerators.size(); ++i) + { + cmMakefile* mf = m_LocalGenerators[i]->GetMakefile(); + + // Get the source directory from the makefile + std::string dir = mf->GetStartDirectory(); + // remove the home directory and / from the source directory + // this gives a relative path + cmSystemTools::ReplaceString(dir, homedir.c_str(), ""); + + // Get the list of create dsp files names from the cmVCProjWriter, more + // than one dsp could have been created per input CMakeLists.txt file + // for each target + std::vector dspnames = + static_cast(m_LocalGenerators[i]) + ->GetCreatedProjectNames(); + cmTargets &tgts = m_LocalGenerators[i]->GetMakefile()->GetTargets(); + cmTargets::iterator l = tgts.begin(); + for(std::vector::iterator si = dspnames.begin(); + l != tgts.end(); ++l) + { + // special handling for the current makefile + if(mf == m_LocalGenerators[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") + { + int j; + for(j = 0; j < m_LocalGenerators.size(); ++j) + { + const cmTargets &atgts = + m_LocalGenerators[j]->GetMakefile()->GetTargets(); + for(cmTargets::const_iterator al = atgts.begin(); + al != atgts.end(); ++al) + { + if (al->second.IsInAll()) + { + if (al->second.GetType() == cmTarget::UTILITY) + { + l->second.AddUtility(al->first.c_str()); + } + else + { + l->second.AddLinkLibrary(al->first,cmTarget::GENERAL); + } + } + } + } + } + } + // Write the project into the SLN file + if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0) + { + cmCustomCommand cc = l->second.GetCustomCommands()[0]; + + // dodgy use of the cmCustomCommand's members to store the + // arguments from the INCLUDE_EXTERNAL_MSPROJECT command + std::vector stuff = cc.GetDepends(); + std::vector depends = cc.GetOutputs(); + this->WriteExternalProject(fout, stuff[0].c_str(), + stuff[1].c_str(), depends); + ++si; + } + else + { + if ((l->second.GetType() != cmTarget::INSTALL_FILES) + && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)) + { + this->WriteProject(fout, si->c_str(), dir.c_str(),l->second); + ++si; + } + } + } + } + fout << "Global\n" + << "\tGlobalSection(SolutionConfiguration) = preSolution\n"; + + int c = 0; + for(std::vector::iterator i = m_Configurations.begin(); + i != m_Configurations.end(); ++i) + { + fout << "\t\tConfigName." << c << " = " << *i << "\n"; + c++; + } + fout << "\tEndGlobalSection\n" + << "\tGlobalSection(ProjectDependencies) = postSolution\n"; + + // loop over again and compute the depends + for(i = 0; i < m_LocalGenerators.size(); ++i) + { + cmMakefile* mf = m_LocalGenerators[i]->GetMakefile(); + cmLocalVisualStudio7Generator* pg = + static_cast(m_LocalGenerators[i]); + // Get the list of create dsp files names from the cmVCProjWriter, more + // than one dsp could have been created per input CMakeLists.txt file + // for each target + std::vector dspnames = + pg->GetCreatedProjectNames(); + cmTargets &tgts = pg->GetMakefile()->GetTargets(); + cmTargets::iterator l = tgts.begin(); + std::string dir = mf->GetStartDirectory(); + for(std::vector::iterator si = dspnames.begin(); + l != tgts.end(); ++l) + { + if ((l->second.GetType() != cmTarget::INSTALL_FILES) + && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)) + { + this->WriteProjectDepends(fout, si->c_str(), dir.c_str(),l->second); + ++si; + } + } + } + fout << "\tEndGlobalSection\n"; + fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n"; + // loop over again and compute the depends + for(i = 0; i < m_LocalGenerators.size(); ++i) + { + cmMakefile* mf = m_LocalGenerators[i]->GetMakefile(); + cmLocalVisualStudio7Generator* pg = + static_cast(m_LocalGenerators[i]); + // Get the list of create dsp files names from the cmVCProjWriter, more + // than one dsp could have been created per input CMakeLists.txt file + // for each target + std::vector dspnames = + pg->GetCreatedProjectNames(); + cmTargets &tgts = pg->GetMakefile()->GetTargets(); + cmTargets::iterator l = tgts.begin(); + std::string dir = mf->GetStartDirectory(); + for(std::vector::iterator si = dspnames.begin(); + l != tgts.end(); ++l) + { + if ((l->second.GetType() != cmTarget::INSTALL_FILES) + && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS)) + { + this->WriteProjectConfigurations(fout, si->c_str()); + ++si; + } + } + } + fout << "\tEndGlobalSection\n"; + + // Write the footer for the SLN file + this->WriteSLNFooter(fout); +} + + +// Write a dsp file into the SLN file, +// Note, that dependencies from executables to +// the libraries it uses are also done here +void cmGlobalVisualStudio7Generator::WriteProject(std::ostream& fout, + const char* dspname, + const char* dir, + const cmTarget&) +{ + std::string d = cmSystemTools::ConvertToOutputPath(dir); + fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\" = \"" + << dspname << "\", \"" + << d << "\\" << dspname << ".vcproj\", \"{" + << this->CreateGUID(dspname) << "}\"\nEndProject\n"; +} + + + +// Write a dsp file into the SLN file, +// Note, that dependencies from executables to +// the libraries it uses are also done here +void cmGlobalVisualStudio7Generator::WriteProjectDepends(std::ostream& fout, + const char* dspname, + const char* , + const cmTarget& target + ) +{ + int depcount = 0; + // insert Begin Project Dependency Project_Dep_Name project stuff here + if (target.GetType() != cmTarget::STATIC_LIBRARY) + { + cmTarget::LinkLibraries::const_iterator j, jend; + j = target.GetLinkLibraries().begin(); + jend = target.GetLinkLibraries().end(); + for(;j!= jend; ++j) + { + if(j->first != dspname) + { + // is the library part of this SLN ? If so add dependency + std::string libPath = j->first + "_CMAKE_PATH"; + const char* cacheValue + = m_CMakeInstance->GetCacheDefinition(libPath.c_str()); + if(cacheValue) + { + fout << "\t\t{" << this->CreateGUID(dspname) << "}." << depcount << " = {" + << this->CreateGUID(j->first.c_str()) << "}\n"; + depcount++; + } + } + } + } + + std::set::const_iterator i, end; + // write utility dependencies. + i = target.GetUtilities().begin(); + end = target.GetUtilities().end(); + for(;i!= end; ++i) + { + if(*i != dspname) + { + fout << "\t\t{" << this->CreateGUID(dspname) << "}." << depcount << " = {" + << this->CreateGUID(i->c_str()) << "}\n"; + depcount++; + } + } +} + + +// Write a dsp file into the SLN file, +// Note, that dependencies from executables to +// the libraries it uses are also done here +void +cmGlobalVisualStudio7Generator::WriteProjectConfigurations(std::ostream& fout, + const char* name) +{ + std::string guid = this->CreateGUID(name); + for(std::vector::iterator i = m_Configurations.begin(); + i != m_Configurations.end(); ++i) + { + fout << "\t\t{" << guid << "}." << *i << ".ActiveCfg = " << *i << "|Win32\n" + << "\t\t{" << guid << "}." << *i << ".Build.0 = " << *i << "|Win32\n"; + } +} + + + +// Write a dsp file into the SLN file, +// Note, that dependencies from executables to +// the libraries it uses are also done here +void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& , + const char* , + const char* , + const std::vector& ) +{ + cmSystemTools::Error("WriteExternalProject not implemented"); +// fout << "#########################################################" +// "######################\n\n"; +// fout << "Project: \"" << name << "\"=" +// << location << " - Package Owner=<4>\n\n"; +// fout << "Package=<5>\n{{{\n}}}\n\n"; +// fout << "Package=<4>\n"; +// fout << "{{{\n"; + + +// std::vector::const_iterator i, end; +// // write dependencies. +// i = dependencies.begin(); +// end = dependencies.end(); +// for(;i!= end; ++i) +// { +// fout << "Begin Project Dependency\n"; +// fout << "Project_Dep_Name " << *i << "\n"; +// fout << "End Project Dependency\n"; +// } +// fout << "}}}\n\n"; +} + + + +// Standard end of dsw file +void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout) +{ + fout << "\tGlobalSection(ExtensibilityGlobals) = postSolution\n" + << "\tEndGlobalSection\n" + << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n" + << "\tEndGlobalSection\n" + << "EndGlobal\n"; +} + + +// ouput standard header for dsw file +void cmGlobalVisualStudio7Generator::WriteSLNHeader(std::ostream& fout) +{ + fout << "Microsoft Visual Studio Solution File, Format Version 7.00\n"; +} + + +std::string cmGlobalVisualStudio7Generator::CreateGUID(const char* name) +{ + std::map::iterator i = m_GUIDMap.find(name); + if(i != m_GUIDMap.end()) + { + return i->second; + } + std::string ret; + UUID uid; + unsigned char *uidstr; + UuidCreate(&uid); + UuidToString(&uid,&uidstr); + ret = reinterpret_cast(uidstr); + RpcStringFree(&uidstr); + ret = cmSystemTools::UpperCase(ret); + m_GUIDMap[name] = ret; + return ret; +} + diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h new file mode 100644 index 000000000..37c6586d1 --- /dev/null +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -0,0 +1,95 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef cmGlobalVisualStudio7Generator_h +#define cmGlobalVisualStudio7Generator_h + +#include "cmGlobalGenerator.h" + +class cmTarget; + +/** \class cmGlobalVisualStudio7Generator + * \brief Write a Unix makefiles. + * + * cmGlobalVisualStudio7Generator manages UNIX build process for a tree + */ +class cmGlobalVisualStudio7Generator : public cmGlobalGenerator +{ +public: + ///! Get the name for the generator. + virtual const char* GetName() { + return cmGlobalVisualStudio7Generator::GetActualName();} + static const char* GetActualName() {return "Visual Studio 7";} + + ///! Create a local generator appropriate to this Global Generator + virtual cmLocalGenerator *CreateLocalGenerator(); + + /** + * Try to determine system infomation such as shared library + * extension, pthreads, byte order etc. + */ + virtual void EnableLanguage(const char*, cmMakefile *mf); + + /** + * Try running cmake and building a file. This is used for dynalically + * loaded commands, not as part of the usual build process. + */ + virtual int TryCompile(const char *srcdir, const char *bindir, + const char *projectName); + + /** + * Generate the all required files for building this project/tree. This + * basically creates a series of LocalGenerators for each directory and + * requests that they Generate. + */ + virtual void Generate(); + + /** + * Generate the DSW workspace file. + */ + virtual void OutputSLNFile(); + + /** + * Get the list of configurations + */ + std::vector *GetConfigurations() + { + return &m_Configurations; + }; + +private: + void SetupTests(); + void GenerateConfigurations(); + void WriteSLNFile(std::ostream& fout); + void WriteSLNHeader(std::ostream& fout); + void WriteProject(std::ostream& fout, + const char* name, const char* path, + const cmTarget &t); + void WriteProjectDepends(std::ostream& fout, + const char* name, const char* path, + const cmTarget &t); + void WriteProjectConfigurations(std::ostream& fout, const char* name); + void WriteExternalProject(std::ostream& fout, + const char* name, const char* path, + const std::vector& dependencies); + void WriteSLNFooter(std::ostream& fout); + std::string CreateGUID(const char* name); + + std::vector m_Configurations; + std::map m_GUIDMap; +}; + +#endif diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx new file mode 100644 index 000000000..dad9798ef --- /dev/null +++ b/Source/cmLocalVisualStudio6Generator.cxx @@ -0,0 +1,844 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "cmGlobalGenerator.h" +#include "cmLocalVisualStudio6Generator.h" +#include "cmMakefile.h" +#include "cmSystemTools.h" +#include "cmSourceFile.h" +#include "cmCacheManager.h" + +cmLocalVisualStudio6Generator::cmLocalVisualStudio6Generator() +{ +} + +cmLocalVisualStudio6Generator::~cmLocalVisualStudio6Generator() +{ +} + + +void cmLocalVisualStudio6Generator::Generate(bool fromTheTop) +{ + // this is misnammed right now, it doesn't really generate the makefile but + // instead sets up the Makefile for generation + this->m_Makefile->GenerateMakefile(); + this->OutputDSPFile(); +} + +void cmLocalVisualStudio6Generator::OutputDSPFile() +{ + // If not an in source build, then create the output directory + if(strcmp(m_Makefile->GetStartOutputDirectory(), + m_Makefile->GetHomeDirectory()) != 0) + { + if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory())) + { + cmSystemTools::Error("Error creating directory ", + m_Makefile->GetStartOutputDirectory()); + } + } + + // Setup /I and /LIBPATH options for the resulting DSP file + std::vector& includes = m_Makefile->GetIncludeDirectories(); + std::vector::iterator i; + for(i = includes.begin(); i != includes.end(); ++i) + { + m_IncludeOptions += " /I "; + std::string tmp = cmSystemTools::ConvertToOutputPath(i->c_str()); + + // quote if not already quoted + if (tmp[0] != '"') + { + m_IncludeOptions += "\""; + m_IncludeOptions += tmp; + m_IncludeOptions += "\""; + } + else + { + m_IncludeOptions += tmp; + } + } + + // Create the DSP or set of DSP's for libraries and executables + + // clear project names + m_CreatedProjectNames.clear(); + + // build any targets + cmTargets &tgts = m_Makefile->GetTargets(); + for(cmTargets::iterator l = tgts.begin(); + l != tgts.end(); l++) + { + switch(l->second.GetType()) + { + case cmTarget::STATIC_LIBRARY: + this->SetBuildType(STATIC_LIBRARY, l->first.c_str()); + break; + case cmTarget::SHARED_LIBRARY: + this->SetBuildType(DLL, l->first.c_str()); + break; + case cmTarget::EXECUTABLE: + this->SetBuildType(EXECUTABLE,l->first.c_str()); + break; + case cmTarget::WIN32_EXECUTABLE: + this->SetBuildType(WIN32_EXECUTABLE,l->first.c_str()); + break; + case cmTarget::UTILITY: + this->SetBuildType(UTILITY, l->first.c_str()); + break; + case cmTarget::INSTALL_FILES: + break; + case cmTarget::INSTALL_PROGRAMS: + break; + default: + cmSystemTools::Error("Bad target type", l->first.c_str()); + break; + } + // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace + // so don't build a projectfile for it + if ((l->second.GetType() != cmTarget::INSTALL_FILES) + && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS) + && (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0)) + { + // check to see if the dsp is going into a sub-directory + std::string::size_type pos = l->first.rfind('/'); + if(pos != std::string::npos) + { + std::string dir = m_Makefile->GetStartOutputDirectory(); + dir += "/"; + dir += l->first.substr(0, pos); + if(!cmSystemTools::MakeDirectory(dir.c_str())) + { + cmSystemTools::Error("Error creating directory ", dir.c_str()); + } + } + this->CreateSingleDSP(l->first.c_str(),l->second); + } + } +} + +void cmLocalVisualStudio6Generator::CreateSingleDSP(const char *lname, cmTarget &target) +{ + // add to the list of projects + std::string pname = lname; + m_CreatedProjectNames.push_back(pname); + // create the dsp.cmake file + std::string fname; + fname = m_Makefile->GetStartOutputDirectory(); + fname += "/"; + fname += lname; + fname += ".dsp"; + // save the name of the real dsp file + std::string realDSP = fname; + fname += ".cmake"; + std::ofstream fout(fname.c_str()); + if(!fout) + { + cmSystemTools::Error("Error Writing ", fname.c_str()); + } + this->WriteDSPFile(fout,lname,target); + fout.close(); + // if the dsp file has changed, then write it. + cmSystemTools::CopyFileIfDifferent(fname.c_str(), realDSP.c_str()); +} + + +void cmLocalVisualStudio6Generator::AddDSPBuildRule(cmSourceGroup& sourceGroup) +{ + std::string dspname = *(m_CreatedProjectNames.end()-1); + if(dspname == "ALL_BUILD") + { + return; + } + dspname += ".dsp.cmake"; + std::string makefileIn = m_Makefile->GetStartDirectory(); + makefileIn += "/"; + makefileIn += "CMakeLists.txt"; + makefileIn = cmSystemTools::ConvertToOutputPath(makefileIn.c_str()); + std::string dsprule = "${CMAKE_COMMAND}"; + m_Makefile->ExpandVariablesInString(dsprule); + dsprule = cmSystemTools::ConvertToOutputPath(dsprule.c_str()); + std::string args = makefileIn; + args += " -H"; + args += + cmSystemTools::ConvertToOutputPath(m_Makefile->GetHomeDirectory()); + args += " -S"; + args += + cmSystemTools::ConvertToOutputPath(m_Makefile->GetStartDirectory()); + args += " -O"; + args += + cmSystemTools::ConvertToOutputPath(m_Makefile->GetStartOutputDirectory()); + args += " -B"; + args += + cmSystemTools::ConvertToOutputPath(m_Makefile->GetHomeOutputDirectory()); + m_Makefile->ExpandVariablesInString(args); + + std::string configFile = + m_Makefile->GetDefinition("CMAKE_ROOT"); + configFile += "/Templates/CMakeWindowsSystemConfig.cmake"; + std::vector listFiles = m_Makefile->GetListFiles(); + bool found = false; + for(std::vector::iterator i = listFiles.begin(); + i != listFiles.end(); ++i) + { + if(*i == configFile) + { + found = true; + } + } + if(!found) + { + listFiles.push_back(configFile); + } + + std::vector outputs; + outputs.push_back(dspname); + cmCustomCommand cc(makefileIn.c_str(), dsprule.c_str(), + args.c_str(), + listFiles, + outputs); + sourceGroup.AddCustomCommand(cc); +} + + +void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout, + const char *libName, + cmTarget &target) +{ + // We may be modifying the source groups temporarily, so make a copy. + std::vector sourceGroups = m_Makefile->GetSourceGroups(); + + // get the classes from the source lists then add them to the groups + std::vector classes = target.GetSourceFiles(); + for(std::vector::iterator i = classes.begin(); + i != classes.end(); i++) + { + // Add the file to the list of sources. + std::string source = (*i)->GetFullPath(); + cmSourceGroup& sourceGroup = m_Makefile->FindSourceGroup(source.c_str(), + sourceGroups); + sourceGroup.AddSource(source.c_str(), *i); + } + + // add any custom rules to the source groups + for (std::vector::const_iterator cr = + target.GetCustomCommands().begin(); + cr != target.GetCustomCommands().end(); ++cr) + { + cmSourceGroup& sourceGroup = + m_Makefile->FindSourceGroup(cr->GetSourceName().c_str(), + sourceGroups); + cmCustomCommand cc(*cr); + cc.ExpandVariables(*m_Makefile); + sourceGroup.AddCustomCommand(cc); + } + + // Write the DSP file's header. + this->WriteDSPHeader(fout, libName, target, sourceGroups); + + // Find the group in which the CMakeLists.txt source belongs, and add + // the rule to generate this DSP file. + for(std::vector::reverse_iterator sg = sourceGroups.rbegin(); + sg != sourceGroups.rend(); ++sg) + { + if(sg->Matches("CMakeLists.txt")) + { + this->AddDSPBuildRule(*sg); + break; + } + } + + // Loop through every source group. + for(std::vector::const_iterator sg = sourceGroups.begin(); + sg != sourceGroups.end(); ++sg) + { + const cmSourceGroup::BuildRules& buildRules = sg->GetBuildRules(); + // If the group is empty, don't write it at all. + if(buildRules.empty()) + { continue; } + + // If the group has a name, write the header. + std::string name = sg->GetName(); + if(name != "") + { + this->WriteDSPBeginGroup(fout, name.c_str(), ""); + } + + // Loop through each build rule in the source group. + for(cmSourceGroup::BuildRules::const_iterator cc = + buildRules.begin(); cc != buildRules.end(); ++ cc) + { + std::string source = cc->first; + const cmSourceGroup::Commands& commands = cc->second.m_Commands; + const char* compileFlags = 0; + if(cc->second.m_SourceFile) + { + compileFlags = cc->second.m_SourceFile->GetProperty("COMPILE_FLAGS"); + } + if (source != libName || target.GetType() == cmTarget::UTILITY) + { + fout << "# Begin Source File\n\n"; + + // Tell MS-Dev what the source is. If the compiler knows how to + // build it, then it will. + fout << "SOURCE=" << + cmSystemTools::ConvertToOutputPath(source.c_str()) << "\n\n"; + if (!commands.empty()) + { + cmSourceGroup::CommandFiles totalCommand; + std::string totalCommandStr; + totalCommandStr = this->CombineCommands(commands, totalCommand, + source.c_str()); + this->WriteCustomRule(fout, source.c_str(), totalCommandStr.c_str(), + totalCommand.m_Depends, + totalCommand.m_Outputs, compileFlags); + } + else if(compileFlags) + { + for(std::vector::iterator i + = m_Configurations.begin(); i != m_Configurations.end(); ++i) + { + if (i == m_Configurations.begin()) + { + fout << "!IF \"$(CFG)\" == " << i->c_str() << std::endl; + } + else + { + fout << "!ELSEIF \"$(CFG)\" == " << i->c_str() << std::endl; + } + fout << "\n# ADD CPP " << compileFlags << "\n\n"; + } + fout << "!ENDIF\n\n"; + } + fout << "# End Source File\n"; + } + } + + // If the group has a name, write the footer. + if(name != "") + { + this->WriteDSPEndGroup(fout); + } + } + + // Write the DSP file's footer. + this->WriteDSPFooter(fout); +} + + +void cmLocalVisualStudio6Generator::WriteCustomRule(std::ostream& fout, + const char* source, + const char* command, + const std::set& depends, + const std::set& outputs, + const char* flags + ) +{ + std::vector::iterator i; + for(i = m_Configurations.begin(); i != m_Configurations.end(); ++i) + { + if (i == m_Configurations.begin()) + { + fout << "!IF \"$(CFG)\" == " << i->c_str() << std::endl; + } + else + { + fout << "!ELSEIF \"$(CFG)\" == " << i->c_str() << std::endl; + } + if(flags) + { + fout << "\n# ADD CPP " << flags << "\n\n"; + } + // Write out the dependencies for the rule. + fout << "USERDEP__HACK="; + for(std::set::const_iterator d = depends.begin(); + d != depends.end(); ++d) + { + fout << "\\\n\t" << + cmSystemTools::ConvertToOutputPath(d->c_str()); + } + fout << "\n"; + + fout << "# PROP Ignore_Default_Tool 1\n"; + fout << "# Begin Custom Build\n\n"; + if(outputs.size() == 0) + { + fout << source << "_force : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\""; + fout << command << "\n\n"; + } + + // Write a rule for every output generated by this command. + for(std::set::const_iterator output = outputs.begin(); + output != outputs.end(); ++output) + { + fout << "\"" << output->c_str() + << "\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\""; + fout << command << "\n\n"; + } + + fout << "# End Custom Build\n\n"; + } + + fout << "!ENDIF\n\n"; +} + + +void cmLocalVisualStudio6Generator::WriteDSPBeginGroup(std::ostream& fout, + const char* group, + const char* filter) +{ + fout << "# Begin Group \"" << group << "\"\n" + "# PROP Default_Filter \"" << filter << "\"\n"; +} + + +void cmLocalVisualStudio6Generator::WriteDSPEndGroup(std::ostream& fout) +{ + fout << "# End Group\n"; +} + + + + +void cmLocalVisualStudio6Generator::SetBuildType(BuildType b, const char *libName) +{ + std::string root= m_Makefile->GetDefinition("CMAKE_ROOT"); + const char *def= m_Makefile->GetDefinition( "MSPROJECT_TEMPLATE_DIRECTORY"); + + if( def) + { + root = def; + } + else + { + root += "/Templates"; + } + + switch(b) + { + case STATIC_LIBRARY: + m_DSPHeaderTemplate = root; + m_DSPHeaderTemplate += "/staticLibHeader.dsptemplate"; + m_DSPFooterTemplate = root; + m_DSPFooterTemplate += "/staticLibFooter.dsptemplate"; + break; + case DLL: + m_DSPHeaderTemplate = root; + m_DSPHeaderTemplate += "/DLLHeader.dsptemplate"; + m_DSPFooterTemplate = root; + m_DSPFooterTemplate += "/DLLFooter.dsptemplate"; + break; + case EXECUTABLE: + m_DSPHeaderTemplate = root; + m_DSPHeaderTemplate += "/EXEHeader.dsptemplate"; + m_DSPFooterTemplate = root; + m_DSPFooterTemplate += "/EXEFooter.dsptemplate"; + break; + case WIN32_EXECUTABLE: + m_DSPHeaderTemplate = root; + m_DSPHeaderTemplate += "/EXEWinHeader.dsptemplate"; + m_DSPFooterTemplate = root; + m_DSPFooterTemplate += "/EXEFooter.dsptemplate"; + break; + case UTILITY: + m_DSPHeaderTemplate = root; + m_DSPHeaderTemplate += "/UtilityHeader.dsptemplate"; + m_DSPFooterTemplate = root; + m_DSPFooterTemplate += "/UtilityFooter.dsptemplate"; + break; + } + + // once the build type is set, determine what configurations are + // possible + std::ifstream fin(m_DSPHeaderTemplate.c_str()); + + cmRegularExpression reg("# Name "); + if(!fin) + { + cmSystemTools::Error("Error Reading ", m_DSPHeaderTemplate.c_str()); + } + + // reset m_Configurations + m_Configurations.erase(m_Configurations.begin(), m_Configurations.end()); + // now add all the configurations possible + char buffer[2048]; + while(fin) + { + fin.getline(buffer, 2048); + std::string line = buffer; + cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME",libName); + if (reg.find(line)) + { + m_Configurations.push_back(line.substr(reg.end())); + } + } +} + +std::string +cmLocalVisualStudio6Generator::CombineCommands(const cmSourceGroup::Commands &commands, + cmSourceGroup::CommandFiles &totalCommand, + const char *source) + +{ + // Loop through every custom command generating code from the + // current source. + // build up the depends and outputs and commands + std::string totalCommandStr = ""; + std::string temp; + for(cmSourceGroup::Commands::const_iterator c = commands.begin(); + c != commands.end(); ++c) + { + totalCommandStr += "\n\t"; + temp= c->second.m_Command; + temp = cmSystemTools::ConvertToOutputPath(temp.c_str()); + totalCommandStr += temp; + totalCommandStr += " "; + totalCommandStr += c->second.m_Arguments; + totalCommand.Merge(c->second); + } + // Create a dummy file with the name of the source if it does + // not exist + if(totalCommand.m_Outputs.empty()) + { + std::string dummyFile = m_Makefile->GetStartOutputDirectory(); + dummyFile += "/"; + dummyFile += source; + if(!cmSystemTools::FileExists(dummyFile.c_str())) + { + std::ofstream fout(dummyFile.c_str()); + fout << "Dummy file created by cmake as unused source for utility command.\n"; + } + } + return totalCommandStr; +} + + +// look for custom rules on a target and collect them together +std::string +cmLocalVisualStudio6Generator::CreateTargetRules(const cmTarget &target, + const char *libName) +{ + std::string customRuleCode = ""; + + if (target.GetType() >= cmTarget::UTILITY) + { + return customRuleCode; + } + + // Find the group in which the lix exe custom rules belong + bool init = false; + for (std::vector::const_iterator cr = + target.GetCustomCommands().begin(); + cr != target.GetCustomCommands().end(); ++cr) + { + cmCustomCommand cc(*cr); + cc.ExpandVariables(*m_Makefile); + if (cc.GetSourceName() == libName) + { + if (!init) + { + // header stuff + customRuleCode = "# Begin Special Build Tool\nPostBuild_Cmds="; + init = true; + } + else + { + customRuleCode += "\t"; + } + customRuleCode += cc.GetCommand() + " " + cc.GetArguments(); + } + } + + if (init) + { + customRuleCode += "\n# End Special Build Tool\n"; + } + return customRuleCode; +} + + +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 cmLocalVisualStudio6Generator::WriteDSPHeader(std::ostream& fout, const char *libName, + const cmTarget &target, + std::vector &) +{ + std::set pathEmitted; + + // determine the link directories + std::string libOptions; + std::string libDebugOptions; + std::string libOptimizedOptions; + + std::string libMultiLineOptions; + std::string libMultiLineDebugOptions; + std::string libMultiLineOptimizedOptions; + + // suppoirt override in output directory + std::string libPath = ""; + if (m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH")) + { + libPath = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"); + } + std::string exePath = ""; + if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH")) + { + exePath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"); + } + + if(libPath.size()) + { + // make sure there is a trailing slash + if(libPath[libPath.size()-1] != '/') + { + libPath += "/"; + } + std::string lpath = + cmSystemTools::ConvertToOutputPath(libPath.c_str()); + std::string lpathIntDir = libPath + "$(INTDIR)"; + lpathIntDir = cmSystemTools::ConvertToOutputPath(lpathIntDir.c_str()); + if(pathEmitted.insert(lpath).second) + { + libOptions += " /LIBPATH:"; + libOptions += lpathIntDir; + libOptions += " "; + libOptions += " /LIBPATH:"; + libOptions += lpath; + libOptions += " "; + libMultiLineOptions += "# ADD LINK32 /LIBPATH:"; + libMultiLineOptions += lpathIntDir; + libMultiLineOptions += " "; + libMultiLineOptions += " /LIBPATH:"; + libMultiLineOptions += lpath; + libMultiLineOptions += " \n"; + } + } + if(exePath.size()) + { + // make sure there is a trailing slash + if(exePath[exePath.size()-1] != '/') + { + exePath += "/"; + } + std::string lpath = + cmSystemTools::ConvertToOutputPath(exePath.c_str()); + std::string lpathIntDir = exePath + "$(INTDIR)"; + lpathIntDir = cmSystemTools::ConvertToOutputPath(lpathIntDir.c_str()); + + if(pathEmitted.insert(lpath).second) + { + libOptions += " /LIBPATH:"; + libOptions += lpathIntDir; + libOptions += " "; + libOptions += " /LIBPATH:"; + libOptions += lpath; + libOptions += " "; + libMultiLineOptions += "# ADD LINK32 /LIBPATH:"; + libMultiLineOptions += lpathIntDir; + libMultiLineOptions += " "; + libMultiLineOptions += " /LIBPATH:"; + libMultiLineOptions += lpath; + libMultiLineOptions += " \n"; + } + } + std::vector::const_iterator i; + const std::vector& libdirs = target.GetLinkDirectories(); + for(i = libdirs.begin(); i != libdirs.end(); ++i) + { + std::string path = *i; + if(path[path.size()-1] != '/') + { + path += "/"; + } + std::string lpath = + cmSystemTools::ConvertToOutputPath(path.c_str()); + std::string lpathIntDir = path + "$(INTDIR)"; + lpathIntDir = cmSystemTools::ConvertToOutputPath(lpathIntDir.c_str()); + if(pathEmitted.insert(lpath).second) + { + libOptions += " /LIBPATH:"; + libOptions += lpathIntDir; + libOptions += " "; + libOptions += " /LIBPATH:"; + libOptions += lpath; + libOptions += " "; + + libMultiLineOptions += "# ADD LINK32 /LIBPATH:"; + libMultiLineOptions += lpathIntDir; + libMultiLineOptions += " "; + libMultiLineOptions += " /LIBPATH:"; + libMultiLineOptions += lpath; + libMultiLineOptions += " \n"; + } + } + + // find link libraries + const cmTarget::LinkLibraries& libs = target.GetLinkLibraries(); + cmTarget::LinkLibraries::const_iterator j; + for(j = libs.begin(); j != libs.end(); ++j) + { + // add libraries to executables and dlls (but never include + // a library in a library, bad recursion) + if ((target.GetType() != cmTarget::SHARED_LIBRARY + && target.GetType() != cmTarget::STATIC_LIBRARY) || + (target.GetType() == cmTarget::SHARED_LIBRARY && libName != j->first)) + { + std::string lib = j->first; + if(j->first.find(".lib") == std::string::npos) + { + lib += ".lib"; + } + lib = cmSystemTools::ConvertToOutputPath(lib.c_str()); + + if (j->second == cmTarget::GENERAL) + { + libOptions += " "; + libOptions += lib; + + libMultiLineOptions += "# ADD LINK32 "; + libMultiLineOptions += lib; + libMultiLineOptions += "\n"; + } + if (j->second == cmTarget::DEBUG) + { + libDebugOptions += " "; + libDebugOptions += lib; + + libMultiLineDebugOptions += "# ADD LINK32 "; + libMultiLineDebugOptions += lib; + libMultiLineDebugOptions += "\n"; + } + if (j->second == cmTarget::OPTIMIZED) + { + libOptimizedOptions += " "; + libOptimizedOptions += lib; + + libMultiLineOptimizedOptions += "# ADD LINK32 "; + libMultiLineOptimizedOptions += lib; + libMultiLineOptimizedOptions += "\n"; + } + } + } + std::string extraLinkOptions = + m_Makefile->GetDefinition("CMAKE_EXTRA_LINK_FLAGS"); + if(extraLinkOptions.size()) + { + libOptions += " "; + libOptions += extraLinkOptions; + libOptions += " "; + libMultiLineOptions += "# ADD LINK32 "; + libMultiLineOptions += extraLinkOptions; + libMultiLineOptions += " \n"; + } + + // are there any custom rules on the target itself + // only if the target is a lib or exe + std::string customRuleCode = this->CreateTargetRules(target, libName); + + std::ifstream fin(m_DSPHeaderTemplate.c_str()); + if(!fin) + { + cmSystemTools::Error("Error Reading ", m_DSPHeaderTemplate.c_str()); + } + char buffer[2048]; + + while(fin) + { + fin.getline(buffer, 2048); + std::string line = buffer; + const char* mfcFlag = m_Makefile->GetDefinition("CMAKE_MFC_FLAG"); + if(!mfcFlag) + { + mfcFlag = "0"; + } + cmSystemTools::ReplaceString(line, "CMAKE_CUSTOM_RULE_CODE", + customRuleCode.c_str()); + cmSystemTools::ReplaceString(line, "CMAKE_MFC_FLAG", + mfcFlag); + cmSystemTools::ReplaceString(line, "CM_LIBRARIES", + libOptions.c_str()); + cmSystemTools::ReplaceString(line, "CM_DEBUG_LIBRARIES", + libDebugOptions.c_str()); + cmSystemTools::ReplaceString(line, "CM_OPTIMIZED_LIBRARIES", + libOptimizedOptions.c_str()); + + cmSystemTools::ReplaceString(line, "CM_MULTILINE_LIBRARIES", + libMultiLineOptions.c_str()); + cmSystemTools::ReplaceString(line, "CM_MULTILINE_DEBUG_LIBRARIES", + libMultiLineDebugOptions.c_str()); + cmSystemTools::ReplaceString(line, "CM_MULTILINE_OPTIMIZED_LIBRARIES", + libMultiLineOptimizedOptions.c_str()); + + cmSystemTools::ReplaceString(line, "BUILD_INCLUDES", + m_IncludeOptions.c_str()); + cmSystemTools::ReplaceString(line, "OUTPUT_LIBNAME",libName); + // because LIBRARY_OUTPUT_PATH and EXECUTABLE_OUTPUT_PATH + // are already quoted in the template file, + // we need to remove the quotes here, we still need + // to convert to output path for unix to win32 conversion + cmSystemTools::ReplaceString(line, "LIBRARY_OUTPUT_PATH", + removeQuotes( + cmSystemTools::ConvertToOutputPath(libPath.c_str())).c_str()); + cmSystemTools::ReplaceString(line, "EXECUTABLE_OUTPUT_PATH", + removeQuotes( + cmSystemTools::ConvertToOutputPath(exePath.c_str())).c_str()); + cmSystemTools::ReplaceString(line, + "EXTRA_DEFINES", + m_Makefile->GetDefineFlags()); + std::string flags = m_Makefile->GetDefinition("CMAKE_CXX_FLAGS_RELEASE"); + flags += " -DCMAKE_INTDIR=\\\"Release\\\""; + cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_RELEASE", flags.c_str()); + flags = m_Makefile->GetDefinition("CMAKE_CXX_FLAGS_MINSIZEREL"); + flags += " -DCMAKE_INTDIR=\\\"MinSizeRel\\\""; + cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_MINSIZEREL", flags.c_str()); + flags = m_Makefile->GetDefinition("CMAKE_CXX_FLAGS_DEBUG"); + flags += " -DCMAKE_INTDIR=\\\"Debug\\\""; + cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS_DEBUG", flags.c_str()); + flags = m_Makefile->GetDefinition("CMAKE_CXX_FLAGS_RELWITHDEBINFO"); + flags += " -DCMAKE_INTDIR=\\\"RelWithDebInfo\\\""; + cmSystemTools::ReplaceString(line,"CMAKE_CXX_FLAGS_RELWITHDEBINFO", flags.c_str()); + cmSystemTools::ReplaceString(line, "CMAKE_CXX_FLAGS", + m_Makefile-> + GetDefinition("CMAKE_CXX_FLAGS")); + + fout << line.c_str() << std::endl; + } +} + + +void cmLocalVisualStudio6Generator::WriteDSPFooter(std::ostream& fout) +{ + std::ifstream fin(m_DSPFooterTemplate.c_str()); + if(!fin) + { + cmSystemTools::Error("Error Reading ", + m_DSPFooterTemplate.c_str()); + } + char buffer[2048]; + while(fin) + { + fin.getline(buffer, 2048); + fout << buffer << std::endl; + } +} diff --git a/Source/cmLocalVisualStudio6Generator.h b/Source/cmLocalVisualStudio6Generator.h new file mode 100644 index 000000000..871e3ea7d --- /dev/null +++ b/Source/cmLocalVisualStudio6Generator.h @@ -0,0 +1,106 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef cmLocalVisualStudio6Generator_h +#define cmLocalVisualStudio6Generator_h + +#include "cmLocalGenerator.h" + +class cmMakeDepend; +class cmTarget; +class cmSourceFile; + +// please remove me.... Yuck +#include "cmSourceGroup.h" + +/** \class cmLocalVisualStudio6Generator + * \brief Write a LocalUnix makefiles. + * + * cmLocalVisualStudio6Generator produces a LocalUnix makefile from its + * member m_Makefile. + */ +class cmLocalVisualStudio6Generator : public cmLocalGenerator +{ +public: + ///! Set cache only and recurse to false by default. + cmLocalVisualStudio6Generator(); + + virtual ~cmLocalVisualStudio6Generator(); + + /** + * Generate the makefile for this directory. fromTheTop indicates if this + * is being invoked as part of a global Generate or specific to this + * directory. The difference is that when done from the Top we might skip + * some steps to save time, such as dependency generation for the + * makefiles. This is done by a direct invocation from make. + */ + virtual void Generate(bool fromTheTop); + + void OutputDSPFile(); + + enum BuildType {STATIC_LIBRARY, DLL, EXECUTABLE, WIN32_EXECUTABLE, UTILITY}; + + /** + * Specify the type of the build: static, dll, or executable. + */ + void SetBuildType(BuildType,const char *name); + + /** + * Return array of created DSP names in a STL vector. + * Each executable must have its own dsp. + */ + std::vector GetCreatedProjectNames() + { + return m_CreatedProjectNames; + } + +private: + std::string m_DSPHeaderTemplate; + std::string m_DSPFooterTemplate; + std::vector m_CreatedProjectNames; + + void CreateSingleDSP(const char *lname, cmTarget &tgt); + void WriteDSPFile(std::ostream& fout, const char *libName, + cmTarget &tgt); + void WriteDSPBeginGroup(std::ostream& fout, + const char* group, + const char* filter); + void WriteDSPEndGroup(std::ostream& fout); + + void WriteDSPHeader(std::ostream& fout, const char *libName, + const cmTarget &tgt, std::vector &sgs); + + void WriteDSPFooter(std::ostream& fout); + void AddDSPBuildRule(cmSourceGroup&); + void WriteCustomRule(std::ostream& fout, + const char* source, + const char* command, + const std::set& depends, + const std::set& outputs, + const char* flags); + + std::string CreateTargetRules(const cmTarget &target, + const char *libName); + std::string CombineCommands(const cmSourceGroup::Commands &commands, + cmSourceGroup::CommandFiles &totalCommand, + const char *source); + + std::string m_IncludeOptions; + std::vector m_Configurations; +}; + +#endif + diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx new file mode 100644 index 000000000..95e223427 --- /dev/null +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -0,0 +1,906 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "cmGlobalVisualStudio7Generator.h" +#include "cmLocalVisualStudio7Generator.h" +#include "cmMakefile.h" +#include "cmSystemTools.h" +#include "cmSourceFile.h" +#include "cmCacheManager.h" + +cmLocalVisualStudio7Generator::cmLocalVisualStudio7Generator() +{ +} + +cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator() +{ +} + + +void cmLocalVisualStudio7Generator::Generate(bool fromTheTop) +{ + // this is misnammed right now, it doesn't really generate the makefile but + // instead sets up the Makefile for generation + this->m_Makefile->GenerateMakefile(); + this->OutputVCProjFile(); +} + +// TODO +// for CommandLine= need to repleace quotes with " +// write out configurations +void cmLocalVisualStudio7Generator::OutputVCProjFile() +{ + // If not an in source build, then create the output directory + if(strcmp(m_Makefile->GetStartOutputDirectory(), + m_Makefile->GetHomeDirectory()) != 0) + { + if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory())) + { + cmSystemTools::Error("Error creating directory ", + m_Makefile->GetStartOutputDirectory()); + } + } + + m_LibraryOutputPath = ""; + if (m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH")) + { + m_LibraryOutputPath = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"); + } + if(m_LibraryOutputPath.size()) + { + // make sure there is a trailing slash + if(m_LibraryOutputPath[m_LibraryOutputPath.size()-1] != '/') + { + m_LibraryOutputPath += "/"; + } + } + m_ExecutableOutputPath = ""; + if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH")) + { + m_ExecutableOutputPath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"); + } + if(m_ExecutableOutputPath.size()) + { + // make sure there is a trailing slash + if(m_ExecutableOutputPath[m_ExecutableOutputPath.size()-1] != '/') + { + m_ExecutableOutputPath += "/"; + } + } + + // Create the VCProj or set of VCProj's for libraries and executables + + // clear project names + m_CreatedProjectNames.clear(); + + // build any targets + cmTargets &tgts = m_Makefile->GetTargets(); + for(cmTargets::iterator l = tgts.begin(); + l != tgts.end(); l++) + { + // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace + // so don't build a projectfile for it + if ((l->second.GetType() != cmTarget::INSTALL_FILES) + && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS) + && (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0)) + { + this->CreateSingleVCProj(l->first.c_str(),l->second); + } + } +} + +void cmLocalVisualStudio7Generator::CreateSingleVCProj(const char *lname, cmTarget &target) +{ + // add to the list of projects + std::string pname = lname; + m_CreatedProjectNames.push_back(pname); + // create the dsp.cmake file + std::string fname; + fname = m_Makefile->GetStartOutputDirectory(); + fname += "/"; + fname += lname; + fname += ".vcproj"; + // save the name of the real dsp file + std::string realVCProj = fname; + fname += ".cmake"; + std::ofstream fout(fname.c_str()); + if(!fout) + { + cmSystemTools::Error("Error Writing ", fname.c_str()); + } + this->WriteVCProjFile(fout,lname,target); + fout.close(); + // if the dsp file has changed, then write it. + cmSystemTools::CopyFileIfDifferent(fname.c_str(), realVCProj.c_str()); +} + + +void cmLocalVisualStudio7Generator::AddVCProjBuildRule(cmSourceGroup& sourceGroup) +{ + std::string dspname = *(m_CreatedProjectNames.end()-1); + if(dspname == "ALL_BUILD") + { + return; + } + dspname += ".vcproj.cmake"; + std::string makefileIn = m_Makefile->GetStartDirectory(); + makefileIn += "/"; + makefileIn += "CMakeLists.txt"; + makefileIn = cmSystemTools::ConvertToOutputPath(makefileIn.c_str()); + std::string dsprule = "${CMAKE_COMMAND}"; + m_Makefile->ExpandVariablesInString(dsprule); + dsprule = cmSystemTools::ConvertToOutputPath(dsprule.c_str()); + std::string args = makefileIn; + args += " -H"; + args += + cmSystemTools::ConvertToOutputPath(m_Makefile->GetHomeDirectory()); + args += " -S"; + args += + cmSystemTools::ConvertToOutputPath(m_Makefile->GetStartDirectory()); + args += " -O"; + args += + cmSystemTools::ConvertToOutputPath(m_Makefile->GetStartOutputDirectory()); + args += " -B"; + args += + cmSystemTools::ConvertToOutputPath(m_Makefile->GetHomeOutputDirectory()); + args += ""; + m_Makefile->ExpandVariablesInString(args); + + std::string configFile = + m_Makefile->GetDefinition("CMAKE_ROOT"); + configFile += "/Templates/CMakeWindowsSystemConfig.cmake"; + std::vector listFiles = m_Makefile->GetListFiles(); + bool found = false; + for(std::vector::iterator i = listFiles.begin(); + i != listFiles.end(); ++i) + { + if(*i == configFile) + { + found = true; + } + } + if(!found) + { + listFiles.push_back(configFile); + } + + std::vector outputs; + outputs.push_back(dspname); + cmCustomCommand cc(makefileIn.c_str(), dsprule.c_str(), + args.c_str(), + listFiles, + outputs); + sourceGroup.AddCustomCommand(cc); +} + + +void cmLocalVisualStudio7Generator::WriteConfigurations(std::ostream& fout, + const char *libName, + const cmTarget &target) +{ + std::vector *configs = + static_cast(m_GlobalGenerator)->GetConfigurations(); + fout << "\t\n"; + for( std::vector::iterator i = configs->begin(); + i != configs->end(); ++i) + { + this->WriteConfiguration(fout, i->c_str(), libName, target); + } + fout << "\t\n"; +} + +void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout, + const char* configName, + const char *libName, + const cmTarget &target) +{ + const char* mfcFlag = m_Makefile->GetDefinition("CMAKE_MFC_FLAG"); + if(!mfcFlag) + { + mfcFlag = "0"; + } + fout << "\t\t\n"; + fout << "\t\t\tGetDefinition("CMAKE_CXX_FLAGS") + << " -DCMAKE_INTDIR=\\"" << configName << "\\"" + << "\"\n"; + + fout << "\t\t\t\tAdditionalIncludeDirectories=\""; + std::vector& includes = m_Makefile->GetIncludeDirectories(); + std::vector::iterator i = includes.begin(); + for(;i != includes.end(); ++i) + { + std::string ipath = this->ConvertToXMLOutputPath(i->c_str()); + fout << ipath << ";"; + } + fout << "\"\n"; + +// Optimization = 0 None Debug /O0 +// Optimization = 1 MinSize /O1 +// Optimization = 2 MaxSpeed /O2 +// Optimization = 3 Max Optimization /O3 +// RuntimeLibrary = 0 /MT multithread +// RuntimeLibrary = 1 /MTd multithread debug +// RuntimeLibrary = 2 /MD multithread dll +// RuntimeLibrary = 3 /MDd multithread dll debug +// RuntimeLibrary = 4 /ML single thread +// RuntimeLibrary = 5 /MLd single thread debug +// InlineFunctionExpansion = 0 none +// InlineFunctionExpansion = 1 when inline keyword +// InlineFunctionExpansion = 2 any time you can + + + if(strcmp(configName, "Debug") == 0) + { + fout << "\t\t\t\tOptimization=\"0\"\n" + << "\t\t\t\tRuntimeLibrary=\"3\"\n" + << "\t\t\t\tInlineFunctionExpansion=\"0\"\n" + << "\t\t\t\tPreprocessorDefinitions=\"WIN32,_DEBUG,_WINDOWS"; + } + else if(strcmp(configName, "Release") == 0) + { + fout << "\t\t\t\tOptimization=\"2\"\n" + << "\t\t\t\tRuntimeLibrary=\"2\"\n" + << "\t\t\t\tInlineFunctionExpansion=\"1\"\n" + << "\t\t\t\tPreprocessorDefinitions=\"WIN32,NDEBUG,_WINDOWS"; + } + else if(strcmp(configName, "MinSizeRel") == 0) + { + fout << "\t\t\t\tOptimization=\"1\"\n" + << "\t\t\t\tRuntimeLibrary=\"2\"\n" + << "\t\t\t\tInlineFunctionExpansion=\"1\"\n" + << "\t\t\t\tPreprocessorDefinitions=\"WIN32,NDEBUG,_WINDOWS"; + } + else if(strcmp(configName, "RelWithDebInfo") == 0) + { + fout << "\t\t\t\tOptimization=\"2\"\n" + << "\t\t\t\tRuntimeLibrary=\"2\"\n" + << "\t\t\t\tInlineFunctionExpansion=\"1\"\n" + << "\t\t\t\tPreprocessorDefinitions=\"WIN32,NDEBUG,_WINDOWS"; + } + if(target.GetType() == cmTarget::SHARED_LIBRARY + || target.GetType() == cmTarget::MODULE_LIBRARY) + { + fout << "," << libName << "_EXPORTS"; + } + this->OutputDefineFlags(fout); + fout << "\"\n"; + if(m_Makefile->IsOn("CMAKE_CXX_USE_RTTI")) + { + fout << "\t\t\t\tRuntimeTypeInfo=\"TRUE\"\n"; + } + fout << "\t\t\t\tAssemblerListingLocation=\"" << configName << "\"\n"; + fout << "\t\t\t\tObjectFile=\"" << configName << "\\\"\n"; + fout << "\t\t\t\tWarningLevel=\"" << m_Makefile->GetDefinition("CMAKE_CXX_WARNING_LEVEL") << "\"\n"; + fout << "\t\t\t\tDetect64BitPortabilityProblems=\"TRUE\"\n" + << "\t\t\t\tDebugInformationFormat=\"3\""; + fout << "/>\n"; // end of \n"; + fout << "\t\t\tConvertToXMLOutputPath(i->c_str()); + fout << ipath << ";"; + } + fout << "\"\n/>\n"; + fout << "\t\t\t\n"; + fout << "\t\t\tOutputTargetRules(fout, target, libName); + fout << "/>\n"; + fout << "\t\t\t\n"; + this->OutputBuildTool(fout, configName, libName, target); + fout << "\t\t\n"; +} + +void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, + const char* configName, + const char *libName, + const cmTarget &target) +{ + std::string temp; + switch(target.GetType()) + { + case cmTarget::STATIC_LIBRARY: + { + std::string libpath = m_LibraryOutputPath + + "$(OutDir)/" + libName + ".lib"; + fout << "\t\t\tConvertToXMLOutputPathSingle(libpath.c_str()) << ".\"/>\n"; + break; + } + case cmTarget::SHARED_LIBRARY: + case cmTarget::MODULE_LIBRARY: + fout << "\t\t\tOutputLibraries(fout, configName, libName, target); + fout << "\"\n"; + temp = m_LibraryOutputPath; + temp += configName; + temp += "/"; + temp += libName; + temp += ".dll"; + fout << "\t\t\t\tOutputFile=\"" + << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n"; + fout << "\t\t\t\tLinkIncremental=\"1\"\n"; + fout << "\t\t\t\tSuppressStartupBanner=\"TRUE\"\n"; + fout << "\t\t\t\tAdditionalLibraryDirectories=\""; + this->OutputLibraryDirectories(fout, configName, libName, target); + fout << "\"\n"; + this->OutputModuleDefinitionFile(fout, target); + temp = m_LibraryOutputPath; + temp += "$(OutDir)"; + temp += "/"; + temp += libName; + temp += ".pdb"; + fout << "\t\t\t\tProgramDatabaseFile=\"" << + this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n"; + if(strcmp(configName, "Debug") == 0 + || strcmp(configName, "RelWithDebInfo") == 0) + { + fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n"; + } + fout << "\t\t\t\tStackReserveSize=\"" + << m_Makefile->GetDefinition("CMAKE_CXX_STACK_SIZE") << "\"\n"; + temp = m_ExecutableOutputPath; + temp += configName; + temp += "/"; + temp += libName; + temp += ".lib"; + fout << "\t\t\t\tImportLibrary=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n"; + break; + case cmTarget::EXECUTABLE: + case cmTarget::WIN32_EXECUTABLE: + + fout << "\t\t\tOutputLibraries(fout, configName, libName, target); + fout << "\"\n"; + temp = m_ExecutableOutputPath; + temp += configName; + temp += "/"; + temp += libName; + temp += ".exe"; + fout << "\t\t\t\tOutputFile=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n"; + fout << "\t\t\t\tLinkIncremental=\"1\"\n"; + fout << "\t\t\t\tSuppressStartupBanner=\"TRUE\"\n"; + fout << "\t\t\t\tAdditionalLibraryDirectories=\""; + this->OutputLibraryDirectories(fout, configName, libName, target); + fout << "\"\n"; + fout << "\t\t\t\tProgramDatabaseFile=\"" << m_LibraryOutputPath + << "$(OutDir)\\" << libName << ".pdb\"\n"; + if(strcmp(configName, "Debug") == 0 + || strcmp(configName, "RelWithDebInfo") == 0) + { + fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n"; + } + if( target.GetType() == cmTarget::EXECUTABLE) + { + fout << "\t\t\t\tSubSystem=\"1\"\n"; + } + else + { + fout << "\t\t\t\tSubSystem=\"2\"\n"; + } + fout << "\t\t\t\tStackReserveSize=\"" + << m_Makefile->GetDefinition("CMAKE_CXX_STACK_SIZE") << "\"/>\n"; + break; + case cmTarget::UTILITY: + break; + } +} + +void cmLocalVisualStudio7Generator::OutputModuleDefinitionFile(std::ostream& fout, + const cmTarget &target) +{ + std::vector const& classes = target.GetSourceFiles(); + for(std::vector::const_iterator i = classes.begin(); + i != classes.end(); i++) + { + if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF") + { + fout << "\t\t\t\tModuleDefinitionFile=\"" + << this->ConvertToXMLOutputPath((*i)->GetFullPath().c_str()) + << "\"\n"; + return; + } + } + +} + +void cmLocalVisualStudio7Generator::OutputLibraryDirectories(std::ostream& fout, + const char*, + const char*, + const cmTarget &tgt) +{ + bool hasone = false; + if(m_LibraryOutputPath.size()) + { + hasone = true; + std::string temp = m_LibraryOutputPath; + temp += "$(INTDIR)"; + + fout << this->ConvertToXMLOutputPath(temp.c_str()) << "," << + this->ConvertToXMLOutputPath(m_LibraryOutputPath.c_str()); + } + if(m_ExecutableOutputPath.size()) + { + hasone = true; + std::string temp = m_ExecutableOutputPath; + temp += "$(INTDIR)"; + fout << this->ConvertToXMLOutputPath(temp.c_str()) << "," << + this->ConvertToXMLOutputPath(m_ExecutableOutputPath.c_str()); + } + + std::set pathEmitted; + std::vector::const_iterator i; + const std::vector& libdirs = tgt.GetLinkDirectories(); + for(i = libdirs.begin(); i != libdirs.end(); ++i) + { + std::string lpath = *i; + if(lpath[lpath.size()-1] != '/') + { + lpath += "/"; + } + if(pathEmitted.insert(lpath).second) + { + if(hasone) + { + fout << ","; + } + std::string lpathi = lpath + "$(INTDIR)"; + fout << this->ConvertToXMLOutputPath(lpathi.c_str()) << "," << lpath; + hasone = true; + } + } +} + +void cmLocalVisualStudio7Generator::OutputLibraries(std::ostream& fout, + const char* configName, + const char* libName, + const cmTarget &target) +{ + const cmTarget::LinkLibraries& libs = target.GetLinkLibraries(); + cmTarget::LinkLibraries::const_iterator j; + for(j = libs.begin(); j != libs.end(); ++j) + { + if(j->first != libName) + { + std::string lib = j->first; + if(j->first.find(".lib") == std::string::npos) + { + lib += ".lib"; + } + lib = this->ConvertToXMLOutputPath(lib.c_str()); + if (j->second == cmTarget::GENERAL + || (j->second == cmTarget::DEBUG && strcmp(configName, "DEBUG") == 0) + || (j->second == cmTarget::OPTIMIZED && strcmp(configName, "DEBUG") != 0)) + { + fout << lib << " "; + } + } + } +} + +void cmLocalVisualStudio7Generator::OutputDefineFlags(std::ostream& fout) +{ + std::string defs = m_Makefile->GetDefineFlags(); + std::string::size_type pos = defs.find("-D"); + bool done = pos == std::string::npos; + if(!done) + { + fout << ","; + } + while(!done) + { + std::string::size_type nextpos = defs.find("-D", pos+2); + std::string define; + if(nextpos != std::string::npos) + { + define = defs.substr(pos+2, nextpos - pos -3); + } + else + { + define = defs.substr(pos+2); + done = true; + } + fout << define << ","; + if(!done) + { + pos = defs.find("-D", nextpos); + } + } +} + +void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, + const char *libName, + cmTarget &target) +{ + // get the configurations + std::vector *configs = + static_cast(m_GlobalGenerator)->GetConfigurations(); + + // We may be modifying the source groups temporarily, so make a copy. + std::vector sourceGroups = m_Makefile->GetSourceGroups(); + + // get the classes from the source lists then add them to the groups + std::vector const& classes = target.GetSourceFiles(); + for(std::vector::const_iterator i = classes.begin(); + i != classes.end(); i++) + { + // Add the file to the list of sources. + std::string source = (*i)->GetFullPath(); + if(cmSystemTools::UpperCase((*i)->GetSourceExtension()) == "DEF") + { + m_ModuleDefinitionFile = (*i)->GetFullPath(); + } + + cmSourceGroup& sourceGroup = m_Makefile->FindSourceGroup(source.c_str(), + sourceGroups); + sourceGroup.AddSource(source.c_str(), *i); + } + + // add any custom rules to the source groups + for (std::vector::const_iterator cr = + target.GetCustomCommands().begin(); + cr != target.GetCustomCommands().end(); ++cr) + { + cmSourceGroup& sourceGroup = + m_Makefile->FindSourceGroup(cr->GetSourceName().c_str(), + sourceGroups); + cmCustomCommand cc(*cr); + cc.ExpandVariables(*m_Makefile); + sourceGroup.AddCustomCommand(cc); + } + + // open the project + this->WriteProjectStart(fout, libName, target, sourceGroups); + // write the configuration information + this->WriteConfigurations(fout, libName, target); + + fout << "\t\n"; + // Find the group in which the CMakeLists.txt source belongs, and add + // the rule to generate this VCProj file. + for(std::vector::reverse_iterator sg = sourceGroups.rbegin(); + sg != sourceGroups.rend(); ++sg) + { + if(sg->Matches("CMakeLists.txt")) + { + this->AddVCProjBuildRule(*sg); + break; + } + } + + + // Loop through every source group. + for(std::vector::const_iterator sg = sourceGroups.begin(); + sg != sourceGroups.end(); ++sg) + { + const cmSourceGroup::BuildRules& buildRules = sg->GetBuildRules(); + // If the group is empty, don't write it at all. + if(buildRules.empty()) + { continue; } + + // If the group has a name, write the header. + std::string name = sg->GetName(); + if(name != "") + { + this->WriteVCProjBeginGroup(fout, name.c_str(), ""); + } + + // Loop through each build rule in the source group. + for(cmSourceGroup::BuildRules::const_iterator cc = + buildRules.begin(); cc != buildRules.end(); ++ cc) + { + std::string source = cc->first; + const cmSourceGroup::Commands& commands = cc->second.m_Commands; + const char* compileFlags = 0; + if(cc->second.m_SourceFile) + { + compileFlags = cc->second.m_SourceFile->GetProperty("COMPILE_FLAGS"); + } + if (source != libName || target.GetType() == cmTarget::UTILITY) + { + fout << "\t\t\t\n"; + if (!commands.empty()) + { + cmSourceGroup::CommandFiles totalCommand; + std::string totalCommandStr; + totalCommandStr = this->CombineCommands(commands, totalCommand, + source.c_str()); + this->WriteCustomRule(fout, source.c_str(), totalCommandStr.c_str(), + totalCommand.m_Depends, + totalCommand.m_Outputs, compileFlags); + } + else if(compileFlags) + { + for(std::vector::iterator i = configs->begin(); + i != configs->end(); ++i) + { + fout << "\t\t\t\t\n" + << "\t\t\t\t\t\n" + << "\t\t\t\t\n"; + } + } + fout << "\t\t\t\n"; + } + } + + // If the group has a name, write the footer. + if(name != "") + { + this->WriteVCProjEndGroup(fout); + } + } + fout << "\t\n"; + + // Write the VCProj file's footer. + this->WriteVCProjFooter(fout); +} + + +void cmLocalVisualStudio7Generator::WriteCustomRule(std::ostream& fout, + const char* source, + const char* command, + const std::set& depends, + const std::set& outputs, + const char* compileFlags) +{ + std::string cmd = command; + cmSystemTools::ReplaceString(cmd, "\"", """); + std::vector::iterator i; + std::vector *configs = + static_cast(m_GlobalGenerator)->GetConfigurations(); + for(i = configs->begin(); i != configs->end(); ++i) + { + fout << "\t\t\t\t\n"; + if(compileFlags) + { + fout << "\t\t\t\t\t\n"; + } + fout << "\t\t\t\t\t::const_iterator d = depends.begin(); + d != depends.end(); ++d) + { + fout << this->ConvertToXMLOutputPath(d->c_str()) + << ";"; + } + fout << "\"\n"; + fout << "\t\t\t\t\tOutputs=\""; + if(outputs.size() == 0) + { + fout << source << "_force"; + } + + bool first = true; + // Write a rule for every output generated by this command. + for(std::set::const_iterator output = outputs.begin(); + output != outputs.end(); ++output) + { + if(!first) + { + fout << ";"; + } + else + { + first = false; + } + fout << output->c_str(); + } + fout << "\"/>\n"; + fout << "\t\t\t\t\n"; + } +} + + +void cmLocalVisualStudio7Generator::WriteVCProjBeginGroup(std::ostream& fout, + const char* group, + const char* ) +{ + fout << "\t\t\n"; +} + + +void cmLocalVisualStudio7Generator::WriteVCProjEndGroup(std::ostream& fout) +{ + fout << "\t\t\n"; +} + + + + + +std::string +cmLocalVisualStudio7Generator::CombineCommands(const cmSourceGroup::Commands &commands, + cmSourceGroup::CommandFiles &totalCommand, + const char *source) + +{ + // Loop through every custom command generating code from the + // current source. + // build up the depends and outputs and commands + std::string totalCommandStr = ""; + std::string temp; + for(cmSourceGroup::Commands::const_iterator c = commands.begin(); + c != commands.end(); ++c) + { + temp= + cmSystemTools::ConvertToOutputPath(c->second.m_Command.c_str()); + totalCommandStr += temp; + totalCommandStr += " "; + totalCommandStr += c->second.m_Arguments; + totalCommandStr += "\n"; + totalCommand.Merge(c->second); + } + // Create a dummy file with the name of the source if it does + // not exist + if(totalCommand.m_Outputs.empty()) + { + std::string dummyFile = m_Makefile->GetStartOutputDirectory(); + dummyFile += "/"; + dummyFile += source; + if(!cmSystemTools::FileExists(dummyFile.c_str())) + { + std::ofstream fout(dummyFile.c_str()); + fout << "Dummy file created by cmake as unused source for utility command.\n"; + } + } + return totalCommandStr; +} + + +// look for custom rules on a target and collect them together + +void cmLocalVisualStudio7Generator::OutputTargetRules(std::ostream& fout, + const cmTarget &target, + const char *libName) +{ + if (target.GetType() >= cmTarget::UTILITY) + { + return; + } + + // Find the group in which the lix exe custom rules belong + bool init = false; + for (std::vector::const_iterator cr = + target.GetCustomCommands().begin(); + cr != target.GetCustomCommands().end(); ++cr) + { + cmCustomCommand cc(*cr); + cc.ExpandVariables(*m_Makefile); + if (cc.GetSourceName() == libName) + { + if(!init) + { + fout << "\nCommandLine=\""; + init = true; + } + std::string args = cc.GetArguments(); + cmSystemTools::ReplaceString(args, "\"", """); + fout << this->ConvertToXMLOutputPath(cc.GetCommand().c_str()) << " " << args << "\n"; + } + } + if (init) + { + fout << "\""; + } +} + +void +cmLocalVisualStudio7Generator::WriteProjectStart(std::ostream& fout, + const char *libName, + const cmTarget &, + std::vector &) +{ + fout << "\n" + << "\n" + << "\t\n" + << "\t\t\n" + << "\t\n"; +} + + +void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout) +{ + fout << "\t\n" + << "\t\n" + << "\n"; +} + + +std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPath(const char* path) +{ + std::string ret = cmSystemTools::ConvertToOutputPath(path); + cmSystemTools::ReplaceString(ret, "\"", """); + return ret; +} + +std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPathSingle(const char* path) +{ + std::string ret = cmSystemTools::ConvertToOutputPath(path); + cmSystemTools::ReplaceString(ret, "\"", ""); + return ret; +} + + diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h new file mode 100644 index 000000000..8c79ffe5e --- /dev/null +++ b/Source/cmLocalVisualStudio7Generator.h @@ -0,0 +1,151 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef cmLocalVisualStudio7Generator_h +#define cmLocalVisualStudio7Generator_h + +#include "cmLocalGenerator.h" + +class cmMakeDepend; +class cmTarget; +class cmSourceFile; + +// please remove me.... Yuck +#include "cmSourceGroup.h" + +/** \class cmLocalVisualStudio7Generator + * \brief Write a LocalUnix makefiles. + * + * cmLocalVisualStudio7Generator produces a LocalUnix makefile from its + * member m_Makefile. + */ +class cmLocalVisualStudio7Generator : public cmLocalGenerator +{ +public: + ///! Set cache only and recurse to false by default. + cmLocalVisualStudio7Generator(); + + virtual ~cmLocalVisualStudio7Generator(); + + /** + * Generate the makefile for this directory. fromTheTop indicates if this + * is being invoked as part of a global Generate or specific to this + * directory. The difference is that when done from the Top we might skip + * some steps to save time, such as dependency generation for the + * makefiles. This is done by a direct invocation from make. + */ + virtual void Generate(bool fromTheTop); + + enum BuildType {STATIC_LIBRARY, DLL, EXECUTABLE, WIN32_EXECUTABLE, UTILITY}; + + /** + * Specify the type of the build: static, dll, or executable. + */ + void SetBuildType(BuildType,const char *name); + + /** + * Return array of created DSP names in a STL vector. + * Each executable must have its own dsp. + */ + std::vector GetCreatedProjectNames() + { + return m_CreatedProjectNames; + } + +private: + void OutputVCProjFile(); + void WriteVCProjHeader(std::ostream& fout, const char *libName, + const cmTarget &tgt, std::vector &sgs); + void WriteVCProjFooter(std::ostream& fout); + void CreateSingleVCProj(const char *lname, cmTarget &tgt); + void WriteVCProjFile(std::ostream& fout, const char *libName, + cmTarget &tgt); + void AddVCProjBuildRule(cmSourceGroup&); + void WriteConfigurations(std::ostream& fout, + const char *libName, + const cmTarget &tgt); + void WriteConfiguration(std::ostream& fout, + const char* configName, + const char* libName, + const cmTarget &tgt); + std::string ConvertToXMLOutputPath(const char* path); + std::string ConvertToXMLOutputPathSingle(const char* path); + void OutputDefineFlags(std::ostream& fout); + void OutputTargetRules(std::ostream& fout, + const cmTarget &target, + const char *libName); + void OutputBuildTool(std::ostream& fout, const char* configName, + const char* libname, const cmTarget& t); + void OutputLibraries(std::ostream& fout, + const char* configName, + const char* libName, + const cmTarget &target); + void OutputLibraryDirectories(std::ostream& fout, + const char* configName, + const char* libName, + const cmTarget &target); + void OutputModuleDefinitionFile(std::ostream& fout, + const cmTarget &target); + void WriteProjectStart(std::ostream& fout, const char *libName, + const cmTarget &tgt, std::vector &sgs); + void WriteVCProjBeginGroup(std::ostream& fout, + const char* group, + const char* filter); + void WriteVCProjEndGroup(std::ostream& fout); + std::string CombineCommands(const cmSourceGroup::Commands &commands, + cmSourceGroup::CommandFiles &totalCommand, + const char *source); + void WriteCustomRule(std::ostream& fout, + const char* source, + const char* command, + const std::set& depends, + const std::set& outputs, + const char* extraFlags); + + std::vector m_CreatedProjectNames; + std::string m_LibraryOutputPath; + std::string m_ExecutableOutputPath; + std::string m_ModuleDefinitionFile; + + /* + std::string m_DSPHeaderTemplate; + std::string m_DSPFooterTemplate; + void WriteDSPBeginGroup(std::ostream& fout, + const char* group, + const char* filter); + void WriteDSPEndGroup(std::ostream& fout); + + + void WriteCustomRule(std::ostream& fout, + const char* source, + const char* command, + const std::set& depends, + const std::set& outputs, + const char* flags); + + std::string CreateTargetRules(const cmTarget &target, + const char *libName); + std::string CombineCommands(const cmSourceGroup::Commands &commands, + cmSourceGroup::CommandFiles &totalCommand, + const char *source); + + std::string m_IncludeOptions; + std::vector m_Configurations; + */ +}; + +#endif +