cmGlobalVisualStudio10Generator.cxx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. cmLocalGenerator*lg = new cmLocalVisualStudio10Generator;
  34. lg->SetGlobalGenerator(this);
  35. return lg;
  36. }
  37. //----------------------------------------------------------------------------
  38. void cmGlobalVisualStudio10Generator
  39. ::GetDocumentation(cmDocumentationEntry& entry) const
  40. {
  41. entry.Name = this->GetName();
  42. entry.Brief = "Generates Visual Studio 10 project files.";
  43. entry.Full = "";
  44. }
  45. //----------------------------------------------------------------------------
  46. void cmGlobalVisualStudio10Generator
  47. ::EnableLanguage(std::vector<std::string>const & lang,
  48. cmMakefile *mf, bool optional)
  49. {
  50. cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf, optional);
  51. }
  52. //----------------------------------------------------------------------------
  53. std::string cmGlobalVisualStudio10Generator::GetUserMacrosDirectory()
  54. {
  55. std::string base;
  56. std::string path;
  57. // base begins with the VisualStudioProjectsLocation reg value...
  58. if (cmSystemTools::ReadRegistryValue(
  59. "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\10.0;"
  60. "VisualStudioProjectsLocation",
  61. base))
  62. {
  63. cmSystemTools::ConvertToUnixSlashes(base);
  64. // 9.0 macros folder:
  65. path = base + "/VSMacros80";
  66. // *NOT* a typo; right now in Visual Studio 2008 beta the macros
  67. // folder is VSMacros80... They may change it to 90 before final
  68. // release of 2008 or they may not... we'll have to keep our eyes
  69. // on it
  70. }
  71. // path is (correctly) still empty if we did not read the base value from
  72. // the Registry value
  73. return path;
  74. }
  75. //----------------------------------------------------------------------------
  76. std::string cmGlobalVisualStudio10Generator::GetUserMacrosRegKeyBase()
  77. {
  78. return "Software\\Microsoft\\VisualStudio\\10.0\\vsmacros";
  79. }
  80. std::string cmGlobalVisualStudio10Generator
  81. ::GenerateBuildCommand(const char* makeProgram,
  82. const char *projectName,
  83. const char* additionalOptions, const char *targetName,
  84. const char* config, bool ignoreErrors, bool)
  85. {
  86. // Ingoring errors is not implemented in visual studio 6
  87. (void) ignoreErrors;
  88. // now build the test
  89. std::string makeCommand
  90. = cmSystemTools::ConvertToOutputPath(makeProgram);
  91. std::string lowerCaseCommand = makeCommand;
  92. cmSystemTools::LowerCase(lowerCaseCommand);
  93. // if there are spaces in the makeCommand, assume a full path
  94. // and convert it to a path with no spaces in it as the
  95. // RunSingleCommand does not like spaces
  96. if(makeCommand.find(' ') != std::string::npos)
  97. {
  98. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  99. }
  100. // msbuild.exe CxxOnly.sln /t:Build /p:Configuration=Debug /target:ALL_BUILD
  101. if(!targetName || strlen(targetName) == 0)
  102. {
  103. targetName = "ALL_BUILD";
  104. }
  105. bool clean = false;
  106. if ( targetName && strcmp(targetName, "clean") == 0 )
  107. {
  108. clean = true;
  109. makeCommand += " ";
  110. makeCommand += projectName;
  111. makeCommand += ".sln ";
  112. makeCommand += "/t:Clean ";
  113. }
  114. else
  115. {
  116. makeCommand += " ";
  117. makeCommand += targetName;
  118. makeCommand += ".vcxproj ";
  119. }
  120. makeCommand += "/p:Configuration=";
  121. if(config && strlen(config))
  122. {
  123. makeCommand += config;
  124. }
  125. else
  126. {
  127. makeCommand += "Debug";
  128. }
  129. if ( additionalOptions )
  130. {
  131. makeCommand += " ";
  132. makeCommand += additionalOptions;
  133. }
  134. return makeCommand;
  135. }