cmDSWWriter.cxx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2000 National Library of Medicine
  8. All rights reserved.
  9. See COPYRIGHT.txt for copyright details.
  10. =========================================================================*/
  11. #include "cmDSWMakefile.h"
  12. #include "cmStandardIncludes.h"
  13. #include "cmSystemTools.h"
  14. #include "cmDSPMakefile.h"
  15. #include "cmMSProjectGenerator.h"
  16. cmDSWMakefile::cmDSWMakefile(cmMakefile* m)
  17. {
  18. m_Makefile = m;
  19. }
  20. // output the DSW file
  21. void cmDSWMakefile::OutputDSWFile()
  22. {
  23. // if this is an out of source build, create the output directory
  24. if(strcmp(m_Makefile->GetStartOutputDirectory(),
  25. m_Makefile->GetHomeDirectory()) != 0)
  26. {
  27. if(!cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory()))
  28. {
  29. cmSystemTools::Error("Error creating output directory for DSW file",
  30. m_Makefile->GetStartOutputDirectory());
  31. }
  32. }
  33. // create the dsw file name
  34. std::string fname;
  35. fname = m_Makefile->GetStartOutputDirectory();
  36. fname += "/";
  37. fname += m_Makefile->GetProjectName();
  38. fname += ".dsw";
  39. std::ofstream fout(fname.c_str());
  40. if(!fout)
  41. {
  42. cmSystemTools::Error("Error can not open DSW file for write: "
  43. ,fname.c_str());
  44. return;
  45. }
  46. this->WriteDSWFile(fout);
  47. }
  48. // Write a DSW file to the stream
  49. void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
  50. {
  51. // Write out the header for a DSW file
  52. this->WriteDSWHeader(fout);
  53. // Create a list of cmMakefile created from all the
  54. // CMakeLists.txt files that are in sub directories of
  55. // this one.
  56. std::vector<cmMakefile*> allListFiles;
  57. m_Makefile->FindSubDirectoryCMakeListsFiles(allListFiles);
  58. // For each cmMakefile, create a DSP for it, and
  59. // add it to this DSW file
  60. for(std::vector<cmMakefile*>::iterator k = allListFiles.begin();
  61. k != allListFiles.end(); ++k)
  62. {
  63. cmMakefile* mf = *k;
  64. // Create an MS generator with DSW off, so it only creates dsp files
  65. cmMSProjectGenerator* pg = new cmMSProjectGenerator;
  66. pg->BuildDSWOff();
  67. mf->SetMakefileGenerator(pg);
  68. mf->GenerateMakefile();
  69. // Get the source directory from the makefile
  70. std::string dir = mf->GetStartDirectory();
  71. // Get the home directory with the trailing slash
  72. std::string homedir = m_Makefile->GetHomeDirectory();
  73. homedir += "/";
  74. // remove the home directory and / from the source directory
  75. // this gives a relative path
  76. cmSystemTools::ReplaceString(dir, homedir.c_str(), "");
  77. // Get the list of create dsp files names from the cmDSPMakefile, more
  78. // than one dsp could have been created per input CMakeLists.txt file
  79. // for each target
  80. std::vector<std::string> dspnames = pg->GetDSPMakefile()->GetCreatedProjectNames();
  81. const cmTargets &tgts = pg->GetDSPMakefile()->GetMakefile()->GetTargets();
  82. cmTargets::const_iterator l = tgts.begin();
  83. for(std::vector<std::string>::iterator si = dspnames.begin();
  84. l != tgts.end(); ++l, ++si)
  85. {
  86. // Write the project into the DSW file
  87. this->WriteProject(fout, si->c_str(), dir.c_str(),
  88. pg->GetDSPMakefile(),l->second);
  89. }
  90. // delete the cmMakefile which also deletes the cmMSProjectGenerator
  91. delete mf;
  92. }
  93. // Write the footer for the DSW file
  94. this->WriteDSWFooter(fout);
  95. }
  96. // Write a dsp file into the DSW file,
  97. // Note, that dependencies from executables to
  98. // the libraries it uses are also done here
  99. void cmDSWMakefile::WriteProject(std::ostream& fout,
  100. const char* dspname,
  101. const char* dir,
  102. cmDSPMakefile* project,
  103. const cmTarget &l)
  104. {
  105. fout << "#########################################################"
  106. "######################\n\n";
  107. fout << "Project: \"" << dspname << "\"="
  108. << dir << "\\" << dspname << ".dsp - Package Owner=<4>\n\n";
  109. fout << "Package=<5>\n{{{\n}}}\n\n";
  110. fout << "Package=<4>\n";
  111. fout << "{{{\n";
  112. // insert Begin Project Dependency Project_Dep_Name project stuff here
  113. cmMakefile::LinkLibraries::const_iterator j, jend;
  114. j = project->GetMakefile()->GetLinkLibraries().begin();
  115. jend = project->GetMakefile()->GetLinkLibraries().end();
  116. for(;j!= jend; ++j)
  117. {
  118. if(j->first != dspname)
  119. {
  120. if (!l.IsALibrary() ||
  121. project->GetLibraryBuildType() == cmDSPMakefile::DLL)
  122. {
  123. fout << "Begin Project Dependency\n";
  124. fout << "Project_Dep_Name " << j->first << "\n";
  125. fout << "End Project Dependency\n";
  126. }
  127. }
  128. }
  129. std::vector<std::string>::iterator i, end;
  130. // write utility dependencies.
  131. i = project->GetMakefile()->GetUtilities().begin();
  132. end = project->GetMakefile()->GetUtilities().end();
  133. for(;i!= end; ++i)
  134. {
  135. if(*i != dspname)
  136. {
  137. fout << "Begin Project Dependency\n";
  138. fout << "Project_Dep_Name " << *i << "\n";
  139. fout << "End Project Dependency\n";
  140. }
  141. }
  142. fout << "}}}\n\n";
  143. }
  144. // Standard end of dsw file
  145. void cmDSWMakefile::WriteDSWFooter(std::ostream& fout)
  146. {
  147. fout << "######################################################"
  148. "#########################\n\n";
  149. fout << "Global:\n\n";
  150. fout << "Package=<5>\n{{{\n}}}\n\n";
  151. fout << "Package=<3>\n{{{\n}}}\n\n";
  152. fout << "#####################################################"
  153. "##########################\n\n";
  154. }
  155. // ouput standard header for dsw file
  156. void cmDSWMakefile::WriteDSWHeader(std::ostream& fout)
  157. {
  158. fout << "Microsoft Developer Studio Workspace File, Format Version 6.00\n";
  159. fout << "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\n\n";
  160. }