cmGlobalVisualStudio10Generator.cxx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. std::string vc10Express;
  19. this->ExpressEdition = cmSystemTools::ReadRegistryValue(
  20. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\10.0\\Setup\\VC;"
  21. "ProductDir", vc10Express, cmSystemTools::KeyWOW64_32);
  22. }
  23. //----------------------------------------------------------------------------
  24. void cmGlobalVisualStudio10Generator::AddPlatformDefinitions(cmMakefile* mf)
  25. {
  26. mf->AddDefinition("MSVC10", "1");
  27. mf->AddDefinition("MSVC_C_ARCHITECTURE_ID", "X86");
  28. mf->AddDefinition("MSVC_CXX_ARCHITECTURE_ID", "X86");
  29. }
  30. //----------------------------------------------------------------------------
  31. void cmGlobalVisualStudio10Generator::WriteSLNHeader(std::ostream& fout)
  32. {
  33. fout << "Microsoft Visual Studio Solution File, Format Version 11.00\n";
  34. fout << "# Visual Studio 2010\n";
  35. }
  36. ///! Create a local generator appropriate to this Global Generator
  37. cmLocalGenerator *cmGlobalVisualStudio10Generator::CreateLocalGenerator()
  38. {
  39. cmLocalVisualStudio10Generator* lg = new cmLocalVisualStudio10Generator;
  40. lg->SetPlatformName(this->GetPlatformName());
  41. lg->SetGlobalGenerator(this);
  42. return lg;
  43. }
  44. //----------------------------------------------------------------------------
  45. void cmGlobalVisualStudio10Generator
  46. ::GetDocumentation(cmDocumentationEntry& entry) const
  47. {
  48. entry.Name = this->GetName();
  49. entry.Brief = "Generates Visual Studio 10 project files.";
  50. entry.Full = "";
  51. }
  52. //----------------------------------------------------------------------------
  53. void cmGlobalVisualStudio10Generator
  54. ::EnableLanguage(std::vector<std::string>const & lang,
  55. cmMakefile *mf, bool optional)
  56. {
  57. cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf, optional);
  58. }
  59. //----------------------------------------------------------------------------
  60. const char* cmGlobalVisualStudio10Generator::GetPlatformToolset()
  61. {
  62. if(!this->PlatformToolset.empty())
  63. {
  64. return this->PlatformToolset.c_str();
  65. }
  66. return 0;
  67. }
  68. //----------------------------------------------------------------------------
  69. std::string cmGlobalVisualStudio10Generator::GetUserMacrosDirectory()
  70. {
  71. std::string base;
  72. std::string path;
  73. // base begins with the VisualStudioProjectsLocation reg value...
  74. if (cmSystemTools::ReadRegistryValue(
  75. "HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\10.0;"
  76. "VisualStudioProjectsLocation",
  77. base))
  78. {
  79. cmSystemTools::ConvertToUnixSlashes(base);
  80. // 9.0 macros folder:
  81. path = base + "/VSMacros80";
  82. // *NOT* a typo; right now in Visual Studio 2008 beta the macros
  83. // folder is VSMacros80... They may change it to 90 before final
  84. // release of 2008 or they may not... we'll have to keep our eyes
  85. // on it
  86. }
  87. // path is (correctly) still empty if we did not read the base value from
  88. // the Registry value
  89. return path;
  90. }
  91. //----------------------------------------------------------------------------
  92. std::string cmGlobalVisualStudio10Generator::GetUserMacrosRegKeyBase()
  93. {
  94. return "Software\\Microsoft\\VisualStudio\\10.0\\vsmacros";
  95. }
  96. std::string cmGlobalVisualStudio10Generator
  97. ::GenerateBuildCommand(const char* makeProgram,
  98. const char *projectName,
  99. const char* additionalOptions, const char *targetName,
  100. const char* config, bool ignoreErrors, bool)
  101. {
  102. // Ingoring errors is not implemented in visual studio 6
  103. (void) ignoreErrors;
  104. // now build the test
  105. std::string makeCommand
  106. = cmSystemTools::ConvertToOutputPath(makeProgram);
  107. std::string lowerCaseCommand = makeCommand;
  108. cmSystemTools::LowerCase(lowerCaseCommand);
  109. // if there are spaces in the makeCommand, assume a full path
  110. // and convert it to a path with no spaces in it as the
  111. // RunSingleCommand does not like spaces
  112. if(makeCommand.find(' ') != std::string::npos)
  113. {
  114. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  115. }
  116. // msbuild.exe CxxOnly.sln /t:Build /p:Configuration=Debug /target:ALL_BUILD
  117. if(!targetName || strlen(targetName) == 0)
  118. {
  119. targetName = "ALL_BUILD";
  120. }
  121. bool clean = false;
  122. if ( targetName && strcmp(targetName, "clean") == 0 )
  123. {
  124. clean = true;
  125. makeCommand += " ";
  126. makeCommand += projectName;
  127. makeCommand += ".sln ";
  128. makeCommand += "/t:Clean ";
  129. }
  130. else
  131. {
  132. makeCommand += " ";
  133. makeCommand += targetName;
  134. makeCommand += ".vcxproj ";
  135. }
  136. makeCommand += "/p:Configuration=";
  137. if(config && strlen(config))
  138. {
  139. makeCommand += config;
  140. }
  141. else
  142. {
  143. makeCommand += "Debug";
  144. }
  145. if ( additionalOptions )
  146. {
  147. makeCommand += " ";
  148. makeCommand += additionalOptions;
  149. }
  150. return makeCommand;
  151. }