cmGlobalVisualStudio10Generator.cxx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "windows.h" // this must be first to define GetCurrentDirectory
  11. #include "cmGlobalVisualStudio10Generator.h"
  12. #include "cmLocalVisualStudio10Generator.h"
  13. #include "cmMakefile.h"
  14. #include "cmake.h"
  15. cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator()
  16. {
  17. this->FindMakeProgramFile = "CMakeVS10FindMake.cmake";
  18. }
  19. //----------------------------------------------------------------------------
  20. void cmGlobalVisualStudio10Generator::AddPlatformDefinitions(cmMakefile* mf)
  21. {
  22. mf->AddDefinition("MSVC10", "1");
  23. }
  24. //----------------------------------------------------------------------------
  25. void cmGlobalVisualStudio10Generator::WriteSLNHeader(std::ostream& fout)
  26. {
  27. fout << "Microsoft Visual Studio Solution File, Format Version 11.00\n";
  28. fout << "# Visual Studio 10\n";
  29. }
  30. ///! Create a local generator appropriate to this Global Generator
  31. cmLocalGenerator *cmGlobalVisualStudio10Generator::CreateLocalGenerator()
  32. {
  33. cmLocalVisualStudio10Generator* lg = new cmLocalVisualStudio10Generator;
  34. lg->SetPlatformName(this->PlatformName.c_str());
  35. lg->SetGlobalGenerator(this);
  36. return lg;
  37. }
  38. //----------------------------------------------------------------------------
  39. void cmGlobalVisualStudio10Generator
  40. ::GetDocumentation(cmDocumentationEntry& entry) const
  41. {
  42. entry.Name = this->GetName();
  43. entry.Brief = "Generates Visual Studio 10 project files.";
  44. entry.Full = "";
  45. }
  46. //----------------------------------------------------------------------------
  47. void cmGlobalVisualStudio10Generator
  48. ::EnableLanguage(std::vector<std::string>const & lang,
  49. cmMakefile *mf, bool optional)
  50. {
  51. cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf, optional);
  52. }
  53. //----------------------------------------------------------------------------
  54. std::string cmGlobalVisualStudio10Generator::GetUserMacrosDirectory()
  55. {
  56. std::string base;
  57. std::string path;
  58. // base begins with the VisualStudioProjectsLocation reg value...
  59. if (cmSystemTools::ReadRegistryValue(
  60. "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\10.0;"
  61. "VisualStudioProjectsLocation",
  62. base))
  63. {
  64. cmSystemTools::ConvertToUnixSlashes(base);
  65. // 9.0 macros folder:
  66. path = base + "/VSMacros80";
  67. // *NOT* a typo; right now in Visual Studio 2008 beta the macros
  68. // folder is VSMacros80... They may change it to 90 before final
  69. // release of 2008 or they may not... we'll have to keep our eyes
  70. // on it
  71. }
  72. // path is (correctly) still empty if we did not read the base value from
  73. // the Registry value
  74. return path;
  75. }
  76. //----------------------------------------------------------------------------
  77. std::string cmGlobalVisualStudio10Generator::GetUserMacrosRegKeyBase()
  78. {
  79. return "Software\\Microsoft\\VisualStudio\\10.0\\vsmacros";
  80. }
  81. std::string cmGlobalVisualStudio10Generator
  82. ::GenerateBuildCommand(const char* makeProgram,
  83. const char *projectName,
  84. const char* additionalOptions, const char *targetName,
  85. const char* config, bool ignoreErrors, bool)
  86. {
  87. // Ingoring errors is not implemented in visual studio 6
  88. (void) ignoreErrors;
  89. // now build the test
  90. std::string makeCommand
  91. = cmSystemTools::ConvertToOutputPath(makeProgram);
  92. std::string lowerCaseCommand = makeCommand;
  93. cmSystemTools::LowerCase(lowerCaseCommand);
  94. // if there are spaces in the makeCommand, assume a full path
  95. // and convert it to a path with no spaces in it as the
  96. // RunSingleCommand does not like spaces
  97. if(makeCommand.find(' ') != std::string::npos)
  98. {
  99. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  100. }
  101. // msbuild.exe CxxOnly.sln /t:Build /p:Configuration=Debug /target:ALL_BUILD
  102. if(!targetName || strlen(targetName) == 0)
  103. {
  104. targetName = "ALL_BUILD";
  105. }
  106. bool clean = false;
  107. if ( targetName && strcmp(targetName, "clean") == 0 )
  108. {
  109. clean = true;
  110. makeCommand += " ";
  111. makeCommand += projectName;
  112. makeCommand += ".sln ";
  113. makeCommand += "/t:Clean ";
  114. }
  115. else
  116. {
  117. makeCommand += " ";
  118. makeCommand += targetName;
  119. makeCommand += ".vcxproj ";
  120. }
  121. makeCommand += "/p:Configuration=";
  122. if(config && strlen(config))
  123. {
  124. makeCommand += config;
  125. }
  126. else
  127. {
  128. makeCommand += "Debug";
  129. }
  130. if ( additionalOptions )
  131. {
  132. makeCommand += " ";
  133. makeCommand += additionalOptions;
  134. }
  135. return makeCommand;
  136. }