cmDSWWriter.cxx 5.4 KB

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