cmDSWMakefile.cxx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #ifdef _MSC_VER
  2. #pragma warning ( disable : 4786 )
  3. #endif
  4. #include "cmDSWMakefile.h"
  5. #include "cmDSPBuilder.h"
  6. #include "cmSystemTools.h"
  7. #include <iostream>
  8. #include <fstream>
  9. #include <windows.h>
  10. // virtual override, ouput the makefile
  11. void cmDSWMakefile::OutputDSWFile()
  12. {
  13. if(m_OutputDirectory == "")
  14. {
  15. // default to build in place
  16. m_OutputDirectory = m_cmHomeDirectory;
  17. }
  18. // If the output directory is not the m_cmHomeDirectory
  19. // then create it.
  20. if(m_OutputDirectory != m_cmHomeDirectory)
  21. {
  22. if(!cmSystemTools::MakeDirectory(m_OutputDirectory.c_str()))
  23. {
  24. MessageBox(0, "Error creating directory ", 0, MB_OK);
  25. MessageBox(0, m_OutputDirectory.c_str(), 0, MB_OK);
  26. }
  27. }
  28. std::string fname;
  29. fname = m_OutputDirectory;
  30. fname += "/";
  31. fname += this->m_LibraryName;
  32. fname += ".dsw";
  33. std::cerr << "writting dsw file " << fname.c_str() << std::endl;
  34. std::ofstream fout(fname.c_str());
  35. if(!fout)
  36. {
  37. std::cerr << "Error can not open " << fname.c_str() << " for write" << std::endl;
  38. return;
  39. }
  40. this->WriteDSWFile(fout);
  41. }
  42. void cmDSWMakefile::WriteDSWFile(std::ostream& fout)
  43. {
  44. this->WriteDSWHeader(fout);
  45. for(std::vector<std::string>::iterator i = m_SubDirectories.begin();
  46. i != m_SubDirectories.end(); ++i)
  47. {
  48. const char* dir = (*i).c_str();
  49. std::vector<std::string> dspnames = this->CreateDSPFile(dir);
  50. std::cerr << "Create dsp for " << dspnames.size() << " number of dsp files in " << dir << std::endl;
  51. for(std::vector<std::string>::iterator si = dspnames.begin();
  52. si != dspnames.end(); ++si)
  53. {
  54. std::string dspname = *si;
  55. std::cerr << "Create dsp for " << (*si).c_str() << std::endl;
  56. if(dspname == "")
  57. {
  58. std::cerr << "Project name not found in " << dir << "/CMakeLists.txt" << std::endl;
  59. std::cerr << "Skipping Project " << std::endl;
  60. }
  61. else
  62. {
  63. std::string subdir = "./";
  64. subdir += dir;
  65. this->WriteProject(fout, dspname.c_str(), subdir.c_str());
  66. }
  67. }
  68. }
  69. this->WriteDSWFooter(fout);
  70. }
  71. std::vector<std::string> cmDSWMakefile::CreateDSPFile(const char* subdir)
  72. {
  73. #undef GetCurrentDirectory
  74. std::string currentDir = this->GetCurrentDirectory();
  75. currentDir += "/";
  76. currentDir += subdir;
  77. cmDSPBuilder dsp;
  78. dsp.SetOutputHomeDirectory(this->GetOutputDirectory());
  79. dsp.SetHomeDirectory(this->GetHomeDirectory());
  80. dsp.SetMakefileDirectory(currentDir.c_str());
  81. std::string outdir = m_OutputDirectory;
  82. outdir += "/";
  83. outdir += subdir;
  84. dsp.SetOutputDirectory(outdir.c_str());
  85. currentDir += "/";
  86. currentDir += "CMakeLists.txt";
  87. dsp.SetInputMakefilePath(currentDir.c_str());
  88. dsp.CreateDSPFile();
  89. return dsp.GetCreatedProjectNames();
  90. }
  91. void cmDSWMakefile::WriteProject(std::ostream& fout,
  92. const char* dspname,
  93. const char* dir)
  94. {
  95. fout << "###############################################################################\n\n";
  96. fout << "Project: \"" << dspname << "\"="
  97. << dir << "\\" << dspname << ".dsp - Package Owner=<4>\n\n";
  98. fout << "Package=<5>\n{{{\n}}}\n\n";
  99. fout << "Package=<4>\n";
  100. fout << "{{{\n";
  101. // insert Begin Project Dependency Project_Dep_Name project stuff here
  102. fout << "}}}\n\n";
  103. }
  104. void cmDSWMakefile::WriteDSWFooter(std::ostream& fout)
  105. {
  106. fout << "###############################################################################\n\n";
  107. fout << "Global:\n\n";
  108. fout << "Package=<5>\n{{{\n}}}\n\n";
  109. fout << "Package=<3>\n{{{\n}}}\n\n";
  110. fout << "###############################################################################\n\n";
  111. }
  112. void cmDSWMakefile::WriteDSWHeader(std::ostream& fout)
  113. {
  114. fout << "Microsoft Developer Studio Workspace File, Format Version 6.00\n";
  115. fout << "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\n\n";
  116. }